Fix new serial constraint upgrades collab/senator/serials-avoid-materialize-error
authorDan Wells <dbw2@calvin.edu>
Mon, 9 Apr 2012 21:59:55 +0000 (17:59 -0400)
committerDan Wells <dbw2@calvin.edu>
Mon, 9 Apr 2012 22:04:31 +0000 (18:04 -0400)
1. None of the upgrades so far have moved is_json() from the public
to the evergreen schema.  That's probably a separate issue, but it
should be safe to call it unqualified, and that's what the rest of
the upgrade file does, so we will too.

2. Add a specific SET CONSTRAINT to avoid deferred trigger problems
when ALTERing the table.

3. Make sure that the unwanted columns on materialized_holding_code
do not exist regardless of your upgrade path.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.serial-holding-code-constraint.sql
Open-ILS/src/sql/Pg/version-upgrade/2.1-2.2-upgrade-db.sql

index 3ac6453..b0519e1 100644 (file)
@@ -3,9 +3,17 @@ BEGIN;
 SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 
 -- This throws away data, but only data that causes breakage anyway.
-UPDATE serial.issuance SET holding_code = NULL WHERE NOT evergreen.is_json(holding_code);
+UPDATE serial.issuance SET holding_code = NULL WHERE NOT is_json(holding_code);
 
-ALTER TABLE serial.issuance ADD CHECK (holding_code IS NULL OR evergreen.is_json(holding_code));
+-- If we don't do this, we have unprocessed triggers and we can't alter the table
+SET CONSTRAINTS serial.issuance_caption_and_pattern_fkey IMMEDIATE;
+
+ALTER TABLE serial.issuance ADD CHECK (holding_code IS NULL OR is_json(holding_code));
+
+-- For the sake of completeness if these sneaked through
+ALTER TABLE serial.materialized_holding_code DROP COLUMN IF EXISTS holding_type;
+ALTER TABLE serial.materialized_holding_code DROP COLUMN IF EXISTS ind1;
+ALTER TABLE serial.materialized_holding_code DROP COLUMN IF EXISTS ind2;
 
 CREATE OR REPLACE FUNCTION serial.materialize_holding_code() RETURNS TRIGGER
 AS $func$ 
index 21d82ee..e8b12f7 100644 (file)
@@ -15379,9 +15379,12 @@ SELECT evergreen.upgrade_deps_block_check('0700', :eg_version);
 SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 
 -- This throws away data, but only data that causes breakage anyway.
-UPDATE serial.issuance SET holding_code = NULL WHERE NOT evergreen.is_json(holding_code);
+UPDATE serial.issuance SET holding_code = NULL WHERE NOT is_json(holding_code);
 
-ALTER TABLE serial.issuance ADD CHECK (holding_code IS NULL OR evergreen.is_json(holding_code));
+-- If we don't do this, we have unprocessed triggers and we can't alter the table
+SET CONSTRAINTS serial.issuance_caption_and_pattern_fkey IMMEDIATE;
+
+ALTER TABLE serial.issuance ADD CHECK (holding_code IS NULL OR is_json(holding_code));
 
 INSERT INTO config.internal_flag (name, value, enabled) VALUES (
     'serial.rematerialize_on_same_holding_code', NULL, FALSE