From c18842d37c4f596694697045ff79cd9974d3ebe7 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Thu, 25 Apr 2024 11:43:59 +0200 Subject: [PATCH] Add required schema changes Co-Authored-By: Sukhwinder Dhillon --- schema/pgsql/schema.sql | 39 +++++++++++++++++++ .../pgsql/upgrades/some-unique-file-name.sql | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index a544e8d2d..8b84e5272 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -244,6 +244,31 @@ CREATE TABLE rule_escalation_recipient ( CHECK (num_nonnulls(contact_id, contactgroup_id, schedule_id) = 1) ); +CREATE TABLE rule_routing ( + id bigserial, + rule_id bigint NOT NULL REFERENCES rule(id), + position integer NOT NULL, + condition text, + name text, -- if not set, recipients are used as a fallback for display purposes + + CONSTRAINT pk_rule_routing PRIMARY KEY (id), + + UNIQUE (rule_id, position) +); + +CREATE TABLE rule_routing_recipient ( + id bigserial, + rule_routing_id bigint NOT NULL REFERENCES rule_routing(id), + contact_id bigint REFERENCES contact(id), + contactgroup_id bigint REFERENCES contactgroup(id), + schedule_id bigint REFERENCES schedule(id), + channel_id bigint REFERENCES channel(id), + + CONSTRAINT pk_rule_routing_recipient PRIMARY KEY (id), + + CHECK (num_nonnulls(contact_id, contactgroup_id, schedule_id) = 1) +); + CREATE TABLE incident ( id bigserial, object_id bytea NOT NULL REFERENCES object(id), @@ -310,3 +335,17 @@ CREATE TABLE incident_history ( CREATE INDEX idx_incident_history_time_type ON incident_history(time, type); COMMENT ON INDEX idx_incident_history_time_type IS 'Incident History ordered by time/type'; + +CREATE TABLE notification_history ( + id bigserial, + incident_id bigint REFERENCES incident(id), + rule_routing_id bigint REFERENCES rule_routing(id), + contact_id bigint REFERENCES contact(id), + contactgroup_id bigint REFERENCES contactgroup(id), + schedule_id bigint REFERENCES schedule(id), + channel_id bigint REFERENCES channel(id), + time bigint NOT NULL, + notification_state notification_state_type, + sent_at bigint, + message text +); diff --git a/schema/pgsql/upgrades/some-unique-file-name.sql b/schema/pgsql/upgrades/some-unique-file-name.sql index 79c19f8f3..2a0f8e8fd 100644 --- a/schema/pgsql/upgrades/some-unique-file-name.sql +++ b/schema/pgsql/upgrades/some-unique-file-name.sql @@ -1 +1,40 @@ DROP TABLE incident_event; + +CREATE TABLE rule_routing ( + id bigserial, + rule_id bigint NOT NULL REFERENCES rule(id), + position integer NOT NULL, + condition text, + name text, -- if not set, recipients are used as a fallback for display purposes + + CONSTRAINT pk_rule_routing PRIMARY KEY (id), + + UNIQUE (rule_id, position) +); + +CREATE TABLE rule_routing_recipient ( + id bigserial, + rule_routing_id bigint NOT NULL REFERENCES rule_routing(id), + contact_id bigint REFERENCES contact(id), + contactgroup_id bigint REFERENCES contactgroup(id), + schedule_id bigint REFERENCES schedule(id), + channel_id bigint REFERENCES channel(id), + + CONSTRAINT pk_rule_routing_recipient PRIMARY KEY (id), + + CHECK (num_nonnulls(contact_id, contactgroup_id, schedule_id) = 1) +); + +CREATE TABLE notification_history ( + id bigserial, + incident_id bigint REFERENCES incident(id), + rule_routing_id bigint REFERENCES rule_routing(id), + contact_id bigint REFERENCES contact(id), + contactgroup_id bigint REFERENCES contactgroup(id), + schedule_id bigint REFERENCES schedule(id), + channel_id bigint REFERENCES channel(id), + time bigint NOT NULL, + notification_state notification_state_type, + sent_at bigint, + message text +);