Skip to content

Commit

Permalink
auto clear notification error
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 22, 2023
1 parent 13418ed commit 323aa24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions views/020_teams_triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ BEGIN
DELETE FROM team_components WHERE team_id = OLD.id;
END IF;

IF OLD.spec != NEW.spec THEN
UPDATE notifications SET error = NULL WHERE team_id = NEW.id;
END IF;

PERFORM pg_notify('table_activity', TG_TABLE_NAME || ' ' || NEW.id);

RETURN NULL;
Expand Down
19 changes: 18 additions & 1 deletion views/021_notification.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER notification_update_enqueue
AFTER UPDATE OR DELETE ON notifications
FOR EACH ROW
EXECUTE PROCEDURE handle_notifications_updates_deletes();
EXECUTE PROCEDURE handle_notifications_updates_deletes();

-- Handle before updates for notifications
CREATE OR REPLACE FUNCTION reset_notification_error_before_update()
RETURNS TRIGGER AS $$
BEGIN
IF OLD.filter != NEW.filter OR OLD.custom_services != NEW.custom_services OR OLD.team_id != NEW.team_id THEN
NEW.error = NULL;
END IF;

RETURN NEW;
END
$$ LANGUAGE plpgsql;

CREATE OR REPLACE TRIGGER notification_update_enqueue
BEFORE UPDATE ON notifications
FOR EACH ROW
EXECUTE PROCEDURE reset_notification_error_before_update();

0 comments on commit 323aa24

Please sign in to comment.