-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add a stored procedure to handle entity deletions #1618
Conversation
BEGIN; | ||
|
||
-- Define the trigger function (if it doesn't already exist) | ||
CREATE OR REPLACE FUNCTION update_profile_status_on_delete() RETURNS TRIGGER AS $$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function makes sense.
|
||
-- Update overall profile status if a rule evaluation status is updated | ||
-- error takes precedence over failure, failure takes precedence over success | ||
CREATE OR REPLACE FUNCTION update_profile_status() RETURNS TRIGGER AS $$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the comment to mention what actually changed? It's tricky to figure out since we don't have a diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. I just realised I should have included the old function in the down migration for completeness, too
FROM rule_evaluations | ||
WHERE id = NEW.rule_eval_id; | ||
|
||
raise warning 'profile_id: %', v_profile_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to keep this raise warning
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, no, sorry, this is a debug leftover
let me rebase atop the recent migration (I'll bump the file number) |
57dd281
to
86d130a
Compare
In case an entity was deleted (typically a PR but a repo delete is also a valid use-case), we would not update the profile status until the next profile run. For that, we need to add a new database trigger in a migration. Sort-of-related is a bug in the original procedure that we had where if all the current rules were skipped and we added a failure the overall status would still be a failure. I added a new version of the old procedure to cover that plus some tests. Fixes: mindersec#1610
86d130a
to
50350c5
Compare
In case an entity was deleted (typically a PR but a repo delete is also
a valid use-case), we would not update the profile status until the next
profile run.
For that, we need to add a new database trigger in a migration.
Sort-of-related is a bug in the original procedure that we had where if
all the current rules were skipped and we added a failure the overall
status would still be a failure. I added a new version of the old
procedure to cover that plus some tests.
Fixes: #1610