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

Add a stored procedure to handle entity deletions #1618

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Nov 10, 2023

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

BEGIN;

-- Define the trigger function (if it doesn't already exist)
CREATE OR REPLACE FUNCTION update_profile_status_on_delete() RETURNS TRIGGER AS $$
Copy link
Contributor

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 $$
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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

@jhrozek
Copy link
Contributor Author

jhrozek commented Nov 13, 2023

let me rebase atop the recent migration (I'll bump the file number)

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
@jhrozek jhrozek merged commit 464b622 into mindersec:main Nov 13, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

profile status is not updated on entity deletion
2 participants