Skip to content

Commit 27d7fca

Browse files
adityathebemoshloop
authored andcommitted
feat: add trigger | when done definition is added, log it to incident
history
1 parent 4649a11 commit 27d7fca

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

views/008_incident_history_triggers.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ OR REPLACE TRIGGER evidence_to_incident_history
5858
AFTER INSERT ON evidences FOR EACH ROW
5959
EXECUTE PROCEDURE insert_evidence_created_in_incident_history ();
6060

61+
-- Insert incident done definition added in incident_histories
62+
CREATE
63+
OR REPLACE FUNCTION insert_config_done_definition_added_in_incident_history () RETURNS TRIGGER AS $$
64+
DECLARE incident_id UUID;
65+
BEGIN
66+
SELECT hypotheses.incident_id INTO STRICT incident_id FROM evidences LEFT JOIN hypotheses ON hypotheses.id = evidences.hypothesis_id WHERE evidences.id = NEW.id;
67+
INSERT INTO incident_histories(incident_id, evidence_id, created_by, type) VALUES (incident_id, NEW.id, NEW.created_by, 'evidence.done_definition_added');
68+
RETURN NEW;
69+
END
70+
$$ LANGUAGE plpgsql;
71+
72+
CREATE
73+
OR REPLACE TRIGGER evidence_done_definition_to_incident_history
74+
AFTER UPDATE ON evidences FOR EACH ROW WHEN (OLD.definition_of_done IS DISTINCT FROM NEW.definition_of_done AND NEW.definition_of_done = true)
75+
EXECUTE PROCEDURE insert_config_done_definition_added_in_incident_history ();
76+
6177
-- Insert responder responses updates in incident_histories
6278
CREATE
6379
OR REPLACE FUNCTION insert_responder_comment_in_incident_history () RETURNS TRIGGER AS $$

0 commit comments

Comments
 (0)