Skip to content

Commit

Permalink
Add required schema changes
Browse files Browse the repository at this point in the history
Co-Authored-By: Sukhwinder Dhillon <[email protected]>
  • Loading branch information
yhabteab and sukhwinder33445 committed Apr 25, 2024
1 parent 6d6bb0f commit c18842d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions schema/pgsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
);
39 changes: 39 additions & 0 deletions schema/pgsql/upgrades/some-unique-file-name.sql
Original file line number Diff line number Diff line change
@@ -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
);

0 comments on commit c18842d

Please sign in to comment.