From: Ben Shum Date: Wed, 19 Mar 2014 02:44:56 +0000 (-0400) Subject: LP#1253163: stamping upgrade for authority.in-line-headings X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4ffa6220773038b7c8956612479b074e3803b56d;p=evergreen%2Fpines.git LP#1253163: stamping upgrade for authority.in-line-headings Signed-off-by: Ben Shum --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 7c30be7285..be95f68f1d 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -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 ('0874', :eg_version); -- dbwells/bshum +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0875', :eg_version); -- miker/dbwells/bshum CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0875.schema.authority.in-line-headings.sql b/Open-ILS/src/sql/Pg/upgrade/0875.schema.authority.in-line-headings.sql new file mode 100644 index 0000000000..6fd43d02cc --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0875.schema.authority.in-line-headings.sql @@ -0,0 +1,56 @@ + +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; + +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; +DROP INDEX IF EXISTS authority.by_heading_and_thesaurus; +DROP INDEX IF EXISTS authority.by_heading; + +-- Update without indexes for HOT update +UPDATE authority.record_entry + SET heading = authority.normalize_heading( marc ), + simple_heading = authority.simple_normalize_heading( marc ); + +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 + NEW.heading := authority.normalize_heading( NEW.marc ); + NEW.simple_heading := authority.simple_normalize_heading( NEW.marc ); + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL; + +CREATE TRIGGER update_headings_tgr BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE authority.normalize_heading_for_upsert(); + +ALTER FUNCTION authority.normalize_heading(TEXT, BOOL) STABLE STRICT; +ALTER FUNCTION authority.normalize_heading(TEXT) STABLE STRICT; +ALTER FUNCTION authority.simple_normalize_heading(TEXT) STABLE STRICT; +ALTER FUNCTION authority.simple_heading_set(TEXT) STABLE STRICT; + +COMMIT; + +\qecho . +\qecho This index might fail, and is outside the transaction for that reason. +\qecho If it fails, you probably did not have it in the first place. +\qecho . +CREATE UNIQUE INDEX unique_by_heading_and_thesaurus ON authority.record_entry (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; + + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority.in-line-headings.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority.in-line-headings.sql deleted file mode 100644 index 3b68093f05..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority.in-line-headings.sql +++ /dev/null @@ -1,56 +0,0 @@ - -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; - ---SELECT evergreen.upgrade_deps_block_check('XXXX', :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; -DROP INDEX IF EXISTS authority.by_heading_and_thesaurus; -DROP INDEX IF EXISTS authority.by_heading; - --- Update without indexes for HOT update -UPDATE authority.record_entry - SET heading = authority.normalize_heading( marc ), - simple_heading = authority.simple_normalize_heading( marc ); - -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 - NEW.heading := authority.normalize_heading( NEW.marc ); - NEW.simple_heading := authority.simple_normalize_heading( NEW.marc ); - RETURN NEW; -END; -$f$ LANGUAGE PLPGSQL; - -CREATE TRIGGER update_headings_tgr BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE authority.normalize_heading_for_upsert(); - -ALTER FUNCTION authority.normalize_heading(TEXT, BOOL) STABLE STRICT; -ALTER FUNCTION authority.normalize_heading(TEXT) STABLE STRICT; -ALTER FUNCTION authority.simple_normalize_heading(TEXT) STABLE STRICT; -ALTER FUNCTION authority.simple_heading_set(TEXT) STABLE STRICT; - -COMMIT; - -\qecho . -\qecho This index might fail, and is outside the transaction for that reason. -\qecho If it fails, you probably did not have it in the first place. -\qecho . -CREATE UNIQUE INDEX unique_by_heading_and_thesaurus ON authority.record_entry (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; - -