LP#1846354: Adjust upgrade script for speed user/miker/consolidate_patron_notes_rebased-upgrade_speed-signoff
authorMike Rylander <mrylander@gmail.com>
Tue, 8 Sep 2020 19:12:06 +0000 (15:12 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 8 Sep 2020 19:21:35 +0000 (15:21 -0400)
This commit makes minor adjustments to the upgrade script to speed it up
in the face of larger data sets.

NOTE: The DO blocks that provided assertion tests during the the upgrade
have been commented out, as they primarily test that the preceding
insert did not break in some way that would have inserted data from the
wrong table into the intermediate staging tables.  They take a very long
time to run in some cases, but are left here for testers to enable in
order to confirm that they would pass in production.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.note_and_message_consolidation
docs/RELEASE_NOTES_NEXT/Client/lp1846354_consolidate_patron_notes.adoc

index 5da0cac..28c5c89 100644 (file)
@@ -27,7 +27,7 @@ CREATE TABLE actor.XXXX_penalty_notes AS
 -- here is our staging table which will be shaped exactly like
 -- actor.usr_message and use the same id sequence
 CREATE TABLE actor.XXXX_usr_message_for_penalty_notes (
-    LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS
+    LIKE actor.usr_message INCLUDING DEFAULTS 
 );
 
 INSERT INTO actor.XXXX_usr_message_for_penalty_notes (
@@ -71,7 +71,7 @@ WHERE
 
 -- probably redundant here, but the spec calls for an assertion before removing
 -- the note column from actor.usr_standing_penalty, so being extra cautious:
-
+/*
 do $$ begin
     assert (
         select count(*)
@@ -81,6 +81,7 @@ do $$ begin
         )
     ) = 0, 'failed migrating to actor.usr_message';
 end; $$;
+*/
 
 ALTER TABLE actor.usr_standing_penalty DROP COLUMN note;
 
@@ -135,7 +136,7 @@ CREATE TABLE actor.XXXX_note_and_message_consolidation AS
 -- here is our staging table which will be shaped exactly like
 -- actor.usr_message and use the same id sequence
 CREATE TABLE actor.XXXX_usr_message (
-    LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS
+    LIKE actor.usr_message INCLUDING DEFAULTS 
 );
 
 INSERT INTO actor.XXXX_usr_message (
@@ -158,7 +159,7 @@ FROM
 
 -- another staging table, but for actor.usr_standing_penalty
 CREATE TABLE actor.XXXX_usr_standing_penalty (
-    LIKE actor.usr_standing_penalty INCLUDING DEFAULTS EXCLUDING CONSTRAINTS
+    LIKE actor.usr_standing_penalty INCLUDING DEFAULTS 
 );
 
 INSERT INTO actor.XXXX_usr_standing_penalty (
@@ -188,7 +189,7 @@ INSERT INTO actor.usr_standing_penalty
 
 -- probably redundant here, but the spec calls for an assertion before removing
 -- the alert message column from actor.usr, so being extra cautious:
-
+/*
 do $$ begin
     assert (
         select count(*)
@@ -208,6 +209,7 @@ do $$ begin
         )
     ) = 0, 'failed migrating to actor.usr_standing_penalty';
 end; $$;
+*/
 
 -- WARNING: we're going to lose the history of alert_message
 ALTER TABLE actor.usr DROP COLUMN alert_message CASCADE;
@@ -220,7 +222,7 @@ SELECT auditor.update_auditors();
 -- for the note contents.
 
 CREATE TABLE actor.XXXX_usr_message_for_private_notes (
-    LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS
+    LIKE actor.usr_message INCLUDING DEFAULTS 
 );
 
 INSERT INTO actor.XXXX_usr_message_for_private_notes (
@@ -244,7 +246,7 @@ WHERE
 ;
 
 CREATE TABLE actor.XXXX_usr_message_for_unmatched_public_notes (
-    LIKE actor.usr_message INCLUDING DEFAULTS EXCLUDING CONSTRAINTS
+    LIKE actor.usr_message INCLUDING DEFAULTS 
 );
 
 INSERT INTO actor.XXXX_usr_message_for_unmatched_public_notes (
@@ -275,7 +277,7 @@ WHERE
 --  3) usr_note and usr_message entries that can be matched
 
 CREATE TABLE actor.XXXX_usr_standing_penalties_for_notes (
-    LIKE actor.usr_standing_penalty INCLUDING DEFAULTS EXCLUDING CONSTRAINTS
+    LIKE actor.usr_standing_penalty INCLUDING DEFAULTS 
 );
 
 --  1) actor.XXXX_usr_message_for_private_notes and associated usr_note entries
@@ -344,14 +346,11 @@ INSERT INTO actor.XXXX_usr_standing_penalties_for_notes (
     m.stop_date,
     m.id
 FROM
-    actor.usr_note n,
-    actor.usr_message m
+    actor.usr_note n
+    JOIN actor.usr_message m ON (n.usr = m.usr AND n.create_date = m.create_date)
 WHERE
-    n.usr = m.usr AND n.create_date = m.create_date AND m.id NOT IN (
-        SELECT id FROM actor.XXXX_usr_message_for_private_notes
-        UNION
-        SELECT id FROM actor.XXXX_usr_message_for_unmatched_public_notes
-    )
+    NOT EXISTS ( SELECT 1 FROM actor.XXXX_usr_message_for_private_notes WHERE id = m.id )
+    AND NOT EXISTS ( SELECT 1 FROM actor.XXXX_usr_message_for_unmatched_public_notes WHERE id = m.id )
 ;
 
 -- so far so good, let's push these into production
@@ -364,7 +363,7 @@ INSERT INTO actor.usr_standing_penalty
 
 -- probably redundant here, but the spec calls for an assertion before dropping
 -- the actor.usr_note table, so being extra cautious:
-
+/*
 do $$ begin
     assert (
         select count(*)
@@ -374,8 +373,9 @@ do $$ begin
         )
     ) = 0, 'failed migrating to actor.usr_message';
 end; $$;
+*/
 
-DROP TABLE actor.usr_note;
+DROP TABLE actor.usr_note CASCADE;
 
 -- preserve would-be collisions for migrating
 -- ui.staff.require_initials.patron_info_notes
index 0d2f9ca..9c54ec4 100644 (file)
@@ -12,7 +12,7 @@ And for actor.usr_message, there is now both a pub column and a deleted column.
 
 Depending on privacy policies, system adminstrators may wish to set up a recurring process to truly delete older entries in actor.usr_message that have been flagged as deleted.
 
-WARNING: The upgrade script will remote the alert_message field from the auditor table, so if you care about preserving those you should run a query to create a backup.
+WARNING: The upgrade script will remove the alert_message field from the auditor table, so if you care about preserving those you should run a query to create a backup.
 
 For example: