DASSL / ClassDB

An open-source system to let students experiment with relational data
https://dassl.github.io/ClassDB/
Other
7 stars 2 forks source link

classdb.listOrphans() and uninstaller orphan object check #116

Closed wildtayne closed 7 years ago

wildtayne commented 7 years ago

This branch implements the fix outlined in #107 for orphan objects:

(Fixes #107)

afig commented 7 years ago

Changes look good, This page seems to list the available database objects (although it does not promise to be comprehensive).

Could you also include a fix to the Issue that I recently opened, #117, since the same file is being modified?A potential fix is outlined in a Gist linked to in a comment. The exact function cannot be copy and pasted since other changed were introduced in this branch. Thanks

smurthys commented 7 years ago

In listOrphans, the last column's name is misspelled in the table type returned: has an extra 'u'

In dropInstructor and dropDBManager, it will be helpful if a notice is raised on reassignment (requires a test for existence of objects that need to be reassigned).

In removeFromDB.sql

wildtayne commented 7 years ago

Andrew - no problem, I can also add that fix

wildtayne commented 7 years ago

Thanks for the review, I just pushed a commit to address these issues.

smurthys commented 7 years ago

listOwnedObjects. 👍

Rename listOrphans() to listOrphanObjects(): retain the owner column

removeFromDB.sql: Cannot assume classdb.isSuperuser is created. Please revert to the earlier code.

wildtayne commented 7 years ago
afig commented 7 years ago

Changes and behavior look good.

Oddly enough, other objects (that I did not create) ended up as orphan objects. Namely "toast" objects. This may have been due to the use of the VARCHAR datatype without a number (equivalent to TEXT).

sql0708=# SELECT classdb.createInstructor('testinss', 'noname');
 createinstructor
------------------

(1 row)

sql0708=# \q
---------------------------------------------------------------------------Switch to testinss
sql0708=> CREATE TABLE public.testtab(col1 VARCHAR);
CREATE TABLE
sql0708=> \q
---------------------------------------------------------------------------Switch back to superuser
sql0708=# SELECT classdb.dropInstructor('testinss');
NOTICE:  Objects belonging to this user exist outside their schema. They have been reassigned to ClassDB_Instructor, and can be viewed by executing classdb.listOrphanObjects('Instructor').
 dropinstructor
----------------

(1 row)

sql0708=# SELECT classdb.listOrphanObjects('Instructor');
                    listorphanobjects
----------------------------------------------------------
 (ClassDB_Instructor,testtab,public,Table)
 (ClassDB_Instructor,pg_toast_22576,pg_toast,TOAST)
 (ClassDB_Instructor,pg_toast_22576_index,pg_toast,Index)
(3 rows)

Information on TOAST:

To overcome this limitation, large field values are compressed and/or broken up into multiple physical rows. This happens transparently to the user, with only small impact on most of the backend code. The technique is affectionately known as TOAST (or "the best thing since sliced bread"). The TOAST infrastructure is also used to improve handling of large data values in-memory. ... If any of the columns of a table are TOAST-able, the table will have an associated TOAST table, whose OID is stored in the table's pg_class.reltoastrelid entry. On-disk TOASTed values are kept in the TOAST table, as described in more detail below.

We may choose to ignore this quirk, not include toast in the values listed by listOrphanObjects, or something else.

An while we're on the topic of silly names, loo as a shorthand for listOwnedObjects might not be the best choice, but I suppose it'll do for now.

wildtayne commented 7 years ago

I think it would be good to display all the objects returned in case some of them were manually created, although I guess that kind of contradicts my reason for excluding triggers. It looks like TOAST is pretty much always an automatic thing, so it would probably be OK to exclude it in a future version. We might want to think about which object types can be excluded for the same/similar reason.

smurthys commented 7 years ago

I see @afig and I had an observation in common. :)

The TOAST business is interesting. I have a feeling it might make a return as an issue. :(

Good work with this commit @srrollo.