Stamping upgrade scripts for MARC import tag stripping
authorMike Rylander <mrylander@gmail.com>
Wed, 13 Mar 2013 20:39:15 +0000 (16:39 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 13 Mar 2013 20:39:15 +0000 (16:39 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/0779.schema.strip-marc-tags.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql [deleted file]

index 649d665..3d83609 100644 (file)
@@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0778', :eg_version); -- berick/senator
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0779', :eg_version); -- berick/miker
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0779.schema.strip-marc-tags.sql b/Open-ILS/src/sql/Pg/upgrade/0779.schema.strip-marc-tags.sql
new file mode 100644 (file)
index 0000000..3650d3d
--- /dev/null
@@ -0,0 +1,43 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('0779', :eg_version);
+
+CREATE TABLE vandelay.import_bib_trash_group(
+    id SERIAL PRIMARY KEY,
+    owner INT NOT NULL REFERENCES actor.org_unit(id),
+    label TEXT NOT NULL, --i18n
+    always_apply BOOLEAN NOT NULL DEFAULT FALSE,
+       CONSTRAINT vand_import_bib_trash_grp_owner_label UNIQUE (owner, label)
+);
+
+-- otherwise, the ALTER TABLE statement below
+-- will fail with pending trigger events.
+SET CONSTRAINTS ALL IMMEDIATE;
+
+ALTER TABLE vandelay.import_bib_trash_fields
+    -- allow null-able for now..
+    ADD COLUMN grp INTEGER REFERENCES vandelay.import_bib_trash_group;
+
+-- add any existing trash_fields to "Legacy" groups (one per unique field
+-- owner) as part of the upgrade, since grp is now required.
+-- note that vandelay.import_bib_trash_fields was never used before,
+-- so in most cases this should be a no-op.
+
+INSERT INTO vandelay.import_bib_trash_group (owner, label)
+    SELECT DISTINCT(owner), 'Legacy' FROM vandelay.import_bib_trash_fields;
+
+UPDATE vandelay.import_bib_trash_fields field SET grp = tgroup.id
+    FROM vandelay.import_bib_trash_group tgroup
+    WHERE tgroup.owner = field.owner;
+    
+ALTER TABLE vandelay.import_bib_trash_fields
+    -- now that have values, we can make this non-null
+    ALTER COLUMN grp SET NOT NULL,
+    -- drop outdated constraint
+    DROP CONSTRAINT vand_import_bib_trash_fields_idx,
+    -- owner is implied by the grp
+    DROP COLUMN owner, 
+    -- make grp+field unique
+    ADD CONSTRAINT vand_import_bib_trash_fields_once_per UNIQUE (grp, field);
+
+COMMIT;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql
deleted file mode 100644 (file)
index 3bf2835..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-BEGIN;
-
-CREATE TABLE vandelay.import_bib_trash_group(
-    id SERIAL PRIMARY KEY,
-    owner INT NOT NULL REFERENCES actor.org_unit(id),
-    label TEXT NOT NULL, --i18n
-    always_apply BOOLEAN NOT NULL DEFAULT FALSE,
-       CONSTRAINT vand_import_bib_trash_grp_owner_label UNIQUE (owner, label)
-);
-
--- otherwise, the ALTER TABLE statement below
--- will fail with pending trigger events.
-SET CONSTRAINTS ALL IMMEDIATE;
-
-ALTER TABLE vandelay.import_bib_trash_fields
-    -- allow null-able for now..
-    ADD COLUMN grp INTEGER REFERENCES vandelay.import_bib_trash_group;
-
--- add any existing trash_fields to "Legacy" groups (one per unique field
--- owner) as part of the upgrade, since grp is now required.
--- note that vandelay.import_bib_trash_fields was never used before,
--- so in most cases this should be a no-op.
-
-INSERT INTO vandelay.import_bib_trash_group (owner, label)
-    SELECT DISTINCT(owner), 'Legacy' FROM vandelay.import_bib_trash_fields;
-
-UPDATE vandelay.import_bib_trash_fields field SET grp = tgroup.id
-    FROM vandelay.import_bib_trash_group tgroup
-    WHERE tgroup.owner = field.owner;
-    
-ALTER TABLE vandelay.import_bib_trash_fields
-    -- now that have values, we can make this non-null
-    ALTER COLUMN grp SET NOT NULL,
-    -- drop outdated constraint
-    DROP CONSTRAINT vand_import_bib_trash_fields_idx,
-    -- owner is implied by the grp
-    DROP COLUMN owner, 
-    -- make grp+field unique
-    ADD CONSTRAINT vand_import_bib_trash_fields_once_per UNIQUE (grp, field);
-
-COMMIT;