From 490d7d8d397b9021d2488742e4bc1f1405d98dc5 Mon Sep 17 00:00:00 2001 From: poveyd <32199157+poveyd@users.noreply.github.com> Date: Mon, 4 May 2020 15:20:10 +0100 Subject: [PATCH 1/3] Update cycle_notification_history_in_batches.sql --- .../cycle_notification_history_in_batches.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database_maintenance/cycle_notification_history_in_batches.sql b/database_maintenance/cycle_notification_history_in_batches.sql index 4dbd3fb9b..f85e3542a 100644 --- a/database_maintenance/cycle_notification_history_in_batches.sql +++ b/database_maintenance/cycle_notification_history_in_batches.sql @@ -4,13 +4,13 @@ CREATE TABLE notification_history_pivot AS SELECT * from notification_history WH CREATE TEMPORARY TABLE nh_temp AS SELECT id FROM notification_history; -SELECT COUNT(*) AS 'Total number of rows in nh' FROM nh_temp; +SELECT COUNT(*) AS "Total number of rows in nh" FROM nh_temp; DELETE FROM nh_temp t USING notification_history_pivot p WHERE t.id = p.id; -SELECT COUNT(*) AS 'Number of rows remaining that need moving across from nh to nh_pivot' FROM nh_temp; +SELECT COUNT(*) AS "Number of rows remaining that need moving across from nh to nh_pivot" FROM nh_temp; -- In each function call, using same database connection as used for the above SQL (needs to be in a transaction; this can be inside a stored function or in a transaction from the code) From 557bf7aa7ec23dd114c67d0caa34c68885e6772f Mon Sep 17 00:00:00 2001 From: poveyd <32199157+poveyd@users.noreply.github.com> Date: Mon, 4 May 2020 15:55:24 +0100 Subject: [PATCH 2/3] Update cycle_notification_history_in_batches.sql --- database_maintenance/cycle_notification_history_in_batches.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database_maintenance/cycle_notification_history_in_batches.sql b/database_maintenance/cycle_notification_history_in_batches.sql index f85e3542a..dc0651dc2 100644 --- a/database_maintenance/cycle_notification_history_in_batches.sql +++ b/database_maintenance/cycle_notification_history_in_batches.sql @@ -12,6 +12,8 @@ WHERE t.id = p.id; SELECT COUNT(*) AS "Number of rows remaining that need moving across from nh to nh_pivot" FROM nh_temp; +CREATE INDEX nh_temp_idx ON nh_temp (id); + -- In each function call, using same database connection as used for the above SQL (needs to be in a transaction; this can be inside a stored function or in a transaction from the code) INSERT INTO notification_history_pivot From 7e4adee84bbeb4cbe35cb8f13dceb349ead61405 Mon Sep 17 00:00:00 2001 From: poveyd <32199157+poveyd@users.noreply.github.com> Date: Mon, 4 May 2020 16:18:06 +0100 Subject: [PATCH 3/3] Update cycle_notification_history.sql --- database_maintenance/cycle_notification_history.sql | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/database_maintenance/cycle_notification_history.sql b/database_maintenance/cycle_notification_history.sql index 463b2853b..63561a53a 100644 --- a/database_maintenance/cycle_notification_history.sql +++ b/database_maintenance/cycle_notification_history.sql @@ -24,7 +24,7 @@ CREATE TRIGGER update_pivot AFTER UPDATE OF notification_status, billable_units, FOR EACH ROW EXECUTE PROCEDURE update_pivot_table(); -Create foreign key constraints in notification_history_pivot with dummy names - prefix with "nh_" +Create foreign key constraints in notification_history_pivot using same names as used in notification_history insert data into notification_history_pivot in batches @@ -33,10 +33,7 @@ create remaining indices on notification_history_pivot -- Run basic sanity checks on data in notification_history_pivot, ensuring same number of entries present in notification_history and notification_history_pivot ALTER TABLE notification_history RENAME TO notification_history_old; -Drop constraints on notification_history_old ALTER TABLE notification_history_pivot RENAME TO notification_history; -Create foreign key constraints in notification_history using correct names. Names of constraints will now be available after step above ("Drop constraints on notification_history_old"). -Drop constraints in notification_history that are prefixed with "nh_". -- Run sanity checks on data in notification_history_pivot -- 1. Ensure same number of entries in notification_history and notification_history_pivot