DASSL / ClassDB

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

Test for existence of all ClassDB roles succeeds even if just one of the roles is defined (W) #93

Closed smurthys closed 7 years ago

smurthys commented 7 years ago

In prepareClassDB.sql, the test for existence of all ClassDB roles succeeds even if just one of the roles is defined.

This issue should be addressed after PRs #90 and #92 are merged. Here is the required code:

--Make sure the expected app-specific roles are already defined:
-- four roles expected: ClassDB, Instructor, DBManager, Student
DO
$$
DECLARE
   classDBRoleCount NUMERIC(1);
BEGIN
   SELECT COUNT(*) 
   FROM pg_catalog.pg_roles
   WHERE rolname IN ('classdb', 'classdb_instructor',
                     'classdb_dbmanager', 'classdb_student'
                    )
   INTO classDBRoleCount;

   IF classDBRoleCount <> 4 THEN
      RAISE EXCEPTION
         'Missing roles: one or more expected of the expected ClassDB roles are undefined';
   END IF;
END
$$;
smurthys commented 7 years ago

This code is implemented in initializeDB.sql in #94.

I believe it is helpful to make the code segment shown a helper function such as assertClassDBRolesDefined and then call it (PERFORM?) wherever that assertion is required.

Of course, the assertion function cannot be used in initializeDB.sql, because helper functions won't yet be created.

smurthys commented 7 years ago

I do not believe the original code this issue is about is now only in initializeDB.sql in its correct form. Am I correct? If you happen to verify this is true, please also close this issue.

wildtayne commented 7 years ago

Yes, I believe you are correct.