JBAS-944 Move auth updates to 2ndry transaction
authorBill Erickson <berickxx@gmail.com>
Wed, 30 Dec 2015 16:46:27 +0000 (11:46 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/sql/schema/deploy/2.5-to-2.7-upgrade.sql
KCLS/sql/schema/deploy/2.7-auth-reingest.sql [new file with mode: 0644]
KCLS/sql/schema/revert/2.7-auth-reingest.sql [new file with mode: 0644]
KCLS/sql/schema/sqitch.plan
KCLS/sql/schema/verify/2.7-auth-reingest.sql [new file with mode: 0644]

index f3c23d3..ed9f1c2 100644 (file)
@@ -3,11 +3,13 @@
 
 \set ON_ERROR_STOP on
 
+/*
 ALTER TABLE authority.record_entry DISABLE TRIGGER a_marcxml_is_well_formed;
 ALTER TABLE authority.record_entry DISABLE TRIGGER aaa_auth_ingest_or_delete;
 ALTER TABLE authority.record_entry DISABLE TRIGGER b_maintain_901;
 ALTER TABLE authority.record_entry DISABLE TRIGGER c_maintain_control_numbers;
 ALTER TABLE authority.record_entry DISABLE TRIGGER map_thesaurus_to_control_set;
+*/
 
 BEGIN;
 
@@ -5502,6 +5504,9 @@ SELECT evergreen.upgrade_deps_block_check('0875', :eg_version);
 ALTER TABLE authority.record_entry ADD COLUMN heading TEXT, ADD COLUMN simple_heading TEXT;
 
 DROP INDEX IF EXISTS authority.unique_by_heading_and_thesaurus;
+
+-- auth updates and indexes recreated in secondary transaction.
+/*
 DROP INDEX IF EXISTS authority.by_heading_and_thesaurus;
 DROP INDEX IF EXISTS authority.by_heading;
 
@@ -5513,6 +5518,8 @@ UPDATE  authority.record_entry
 CREATE INDEX by_heading_and_thesaurus ON authority.record_entry (heading) WHERE deleted IS FALSE or deleted = FALSE;
 CREATE INDEX by_heading ON authority.record_entry (simple_heading) WHERE deleted IS FALSE or deleted = FALSE;
 
+*/
+
 -- Add the trigger
 CREATE OR REPLACE FUNCTION authority.normalize_heading_for_upsert () RETURNS TRIGGER AS $f$
 BEGIN
@@ -5836,11 +5843,13 @@ END;
 $$ LANGUAGE PLPGSQL;
 
 -- re-enable the triggers we disabled before starting the transaction
+/*
 ALTER TABLE authority.record_entry ENABLE TRIGGER a_marcxml_is_well_formed;
 ALTER TABLE authority.record_entry ENABLE TRIGGER aaa_auth_ingest_or_delete;
 ALTER TABLE authority.record_entry ENABLE TRIGGER b_maintain_901;
 ALTER TABLE authority.record_entry ENABLE TRIGGER c_maintain_control_numbers;
 ALTER TABLE authority.record_entry ENABLE TRIGGER map_thesaurus_to_control_set;
+*/
 
 -- TODO RECREATE reporter.classic_current_circ;
 
@@ -7858,14 +7867,17 @@ $func$ LANGUAGE PLPGSQL STABLE STRICT;
 
 -- fix heading and simple_headings columns without
 -- causing a full authority reingest
+/*
 ALTER TABLE authority.record_entry DISABLE TRIGGER a_marcxml_is_well_formed;
 ALTER TABLE authority.record_entry DISABLE TRIGGER aaa_auth_ingest_or_delete;
 ALTER TABLE authority.record_entry DISABLE TRIGGER b_maintain_901;
 ALTER TABLE authority.record_entry DISABLE TRIGGER c_maintain_control_numbers;
 ALTER TABLE authority.record_entry DISABLE TRIGGER map_thesaurus_to_control_set;
 
+SELECT COUNT(*) FROM authority.record_entry WHERE heading LIKE 'NOHEADING%';
 UPDATE authority.record_entry SET id = id WHERE heading LIKE 'NOHEADING%';
-
+SELECT COUNT(*) FROM authority.record_entry WHERE heading LIKE 'NOHEADING%';
+*/
 
 -- check whether patch can be applied
 SELECT evergreen.upgrade_deps_block_check('0906', :eg_version);
@@ -8880,13 +8892,4 @@ UPDATE authority.control_set_authority_field SET sf_list = REGEXP_REPLACE( sf_li
 
 COMMIT;
 
--- These need to happen outside of the transaction to avoid this:
--- ERROR: cannot ALTER TABLE "record_entry" because it has pending trigger
--- events
-ALTER TABLE authority.record_entry ENABLE TRIGGER a_marcxml_is_well_formed;
-ALTER TABLE authority.record_entry ENABLE TRIGGER aaa_auth_ingest_or_delete;
-ALTER TABLE authority.record_entry ENABLE TRIGGER b_maintain_901;
-ALTER TABLE authority.record_entry ENABLE TRIGGER c_maintain_control_numbers;
-ALTER TABLE authority.record_entry ENABLE TRIGGER map_thesaurus_to_control_set;
-
 
diff --git a/KCLS/sql/schema/deploy/2.7-auth-reingest.sql b/KCLS/sql/schema/deploy/2.7-auth-reingest.sql
new file mode 100644 (file)
index 0000000..3e90efe
--- /dev/null
@@ -0,0 +1,29 @@
+-- Deploy kcls-evergreen:2.7-auth-reingest to pg
+-- requires: 2.5-to-2.7-upgrade
+
+BEGIN;
+
+ALTER TABLE authority.record_entry DISABLE TRIGGER a_marcxml_is_well_formed;
+ALTER TABLE authority.record_entry DISABLE TRIGGER aaa_auth_ingest_or_delete;
+ALTER TABLE authority.record_entry DISABLE TRIGGER b_maintain_901;
+ALTER TABLE authority.record_entry DISABLE TRIGGER c_maintain_control_numbers;
+ALTER TABLE authority.record_entry DISABLE TRIGGER map_thesaurus_to_control_set;
+
+DROP INDEX IF EXISTS authority.by_heading_and_thesaurus;
+DROP INDEX IF EXISTS authority.by_heading;
+
+-- build the new heading and simple_heading values
+UPDATE authority.record_entry SET id = id;
+
+CREATE INDEX by_heading_and_thesaurus ON authority.record_entry (heading) 
+    WHERE deleted IS FALSE or deleted = FALSE;
+CREATE INDEX by_heading ON authority.record_entry (simple_heading) 
+    WHERE deleted IS FALSE or deleted = FALSE;
+
+ALTER TABLE authority.record_entry ENABLE TRIGGER a_marcxml_is_well_formed;
+ALTER TABLE authority.record_entry ENABLE TRIGGER aaa_auth_ingest_or_delete;
+ALTER TABLE authority.record_entry ENABLE TRIGGER b_maintain_901;
+ALTER TABLE authority.record_entry ENABLE TRIGGER c_maintain_control_numbers;
+ALTER TABLE authority.record_entry ENABLE TRIGGER map_thesaurus_to_control_set;
+
+COMMIT;
diff --git a/KCLS/sql/schema/revert/2.7-auth-reingest.sql b/KCLS/sql/schema/revert/2.7-auth-reingest.sql
new file mode 100644 (file)
index 0000000..e412424
--- /dev/null
@@ -0,0 +1,7 @@
+-- Revert kcls-evergreen:2.7-auth-reingest from pg
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
index fdd6aac..5b4533c 100644 (file)
@@ -17,3 +17,4 @@ blanket-po-print-template [student-groups] 2015-10-12T15:38:31Z Bill Erickson <b
 po-print-li-count-and-date [blanket-po-print-template] 2015-11-20T18:56:33Z Bill Erickson <berickxx@gmail.com> # Minor PO print template repairs
 dob-as-date [student-groups] 2015-10-05T14:17:54Z Bill Erickson <berickxx@gmail.com> # Store DoB as date
 2.5-to-2.7-upgrade [student-groups] 2015-10-15T20:40:14Z Bill Erickson <berickxx@gmail.com> # 2.5 to 2.7 Upgrade
+2.7-auth-reingest [2.5-to-2.7-upgrade] 2015-12-30T16:25:38Z Bill Erickson <berickxx@gmail.com> # Reingest authority records after 2.7 update
diff --git a/KCLS/sql/schema/verify/2.7-auth-reingest.sql b/KCLS/sql/schema/verify/2.7-auth-reingest.sql
new file mode 100644 (file)
index 0000000..ee75136
--- /dev/null
@@ -0,0 +1,7 @@
+-- Verify kcls-evergreen:2.7-auth-reingest on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;