Remove extra scripts

This commit is contained in:
Rebecca Law
2020-05-05 12:01:52 +01:00
parent 1197c4a50a
commit 2e7ae5618c
2 changed files with 0 additions and 32 deletions

View File

@@ -1,6 +0,0 @@
ALTER TABLE notification_history_pivot ADD CONSTRAINT fk_notification_history_notification_status FOREIGN KEY (notification_status) REFERENCES notification_status_types(name)
ALTER TABLE notification_history_pivot ADD CONSTRAINT notification_history_api_key_id_fkey FOREIGN KEY (api_key_id) REFERENCES api_keys(id)
ALTER TABLE notification_history_pivot ADD CONSTRAINT notification_history_job_id_fkey FOREIGN KEY (job_id) REFERENCES jobs(id)
ALTER TABLE notification_history_pivot ADD CONSTRAINT notification_history_key_type_fkey FOREIGN KEY (key_type) REFERENCES key_types(name)
ALTER TABLE notification_history_pivot ADD CONSTRAINT notification_history_service_id_fkey FOREIGN KEY (service_id) REFERENCES services(id)
ALTER TABLE notification_history_pivot ADD CONSTRAINT notification_history_templates_history_fkey FOREIGN KEY (template_id, template_version) REFERENCES templates_history(id, version)

View File

@@ -1,26 +0,0 @@
CREATE TABLE notification_history_pivot AS SELECT * FROM notification_history WHERE 1=2;
ALTER TABLE notification_history_pivot ADD PRIMARY KEY (id);
-- Update values of notification_status, billable_units, updated_at, sent_by, sent_at based on new updates coming into the notification_history table.
CREATE OR REPLACE FUNCTION update_pivot_table()
RETURNS TRIGGER
LANGUAGE plpgsql AS
$$
BEGIN
UPDATE notification_history_pivot SET notification_status = NEW.notification_status,
billable_units = NEW.billable_units,
updated_at = NEW.updated_at,
sent_by = NEW.sent_by,
sent_at = NEW.sent_at
WHERE notification_history_pivot.id = NEW.id;
RETURN NEW;
END
$$;
DROP TRIGGER IF EXISTS update_pivot on notification_history;
CREATE TRIGGER update_pivot AFTER UPDATE OF notification_status, billable_units, updated_at, sent_by, sent_at ON notification_history
FOR EACH ROW
EXECUTE PROCEDURE update_pivot_table();
create index concurrently created_id_nh on notification_history (created_at, id);