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

Assertion code is repeated across DB-level scripts (E) #95

Open smurthys opened 7 years ago

smurthys commented 7 years ago

Assertions on privilege, etc. repeat across db-level scripts. The repetition can be eliminated by adding assertion functions to addHelpers.sql and calling the assertion functions from all DB-level scripts except initializeDB.sql from PR #94

smurthys commented 7 years ago

I have in mind functions such as the following to be added to addHelpers.sql because there are a few instances of such code in various files. I assume the exception propagates from a function to the calling transaction.

The code below is an example of an assertion function. And, it is quite possible the code needs some tweaks. Still showing it here to share the idea.

At this point, I will put this issue on backlog. We can reconsider before M1's release if an opportunity presents to add assertions.

CREATE OR REPLACE FUNCTION
   classdb.assertSuperUser(message VARCHAR DEFAULT NULL, 
                           roleName VARCHAR(63) DEFAULT current_user
                          )
   RETURNS BOOLEAN AS
$$
BEGIN
   IF NOT (SELECT classdb.isSuperUser(roleName)) THEN
      RAISE EXCEPTION 
         COALESCE(message, format('Role %s is not a superuser', roleName));
   END IF;
END;
$$ LANGUAGE plpgsql;
smurthys commented 6 years ago

Removing from M2 due to time constraint.