Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smurthys opened this issue Jul 7, 2017 · 2 comments
Open

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

smurthys opened this issue Jul 7, 2017 · 2 comments

Comments

@smurthys
Copy link
Member

smurthys commented Jul 7, 2017

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
Copy link
Member Author

smurthys commented Jul 8, 2017

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 smurthys added this to the M2 (V 1.1.0) milestone Dec 21, 2017
@smurthys smurthys removed this from the M2 (V 2.0.0) milestone Jan 11, 2018
@smurthys
Copy link
Member Author

Removing from M2 due to time constraint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant