From 2e7ae5618c92a05e092bca9461c797ce287ad638 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 5 May 2020 12:01:52 +0100 Subject: [PATCH] Remove extra scripts --- database_maintenance/foreign_keys.sql | 6 ------ database_maintenance/script_1.sql | 26 -------------------------- 2 files changed, 32 deletions(-) delete mode 100644 database_maintenance/foreign_keys.sql delete mode 100644 database_maintenance/script_1.sql diff --git a/database_maintenance/foreign_keys.sql b/database_maintenance/foreign_keys.sql deleted file mode 100644 index 871e59b1c..000000000 --- a/database_maintenance/foreign_keys.sql +++ /dev/null @@ -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) diff --git a/database_maintenance/script_1.sql b/database_maintenance/script_1.sql deleted file mode 100644 index 9b3003d80..000000000 --- a/database_maintenance/script_1.sql +++ /dev/null @@ -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); \ No newline at end of file