From 269cd54c75387c7f3065425928c12de330164bde Mon Sep 17 00:00:00 2001 From: gmc Date: Mon, 20 Sep 2010 20:58:02 +0000 Subject: [PATCH] add missing upgrade script for maintain_901() stored function Signed-off-by: Galen Charlton git-svn-id: svn://svn.open-ils.org/ILS/trunk@17850 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- .../Pg/upgrade/0408.schema.update_maintain_901.sql | 57 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0408.schema.update_maintain_901.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 023556dd2..e90f171d5 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0407'); -- senator +INSERT INTO config.upgrade_log (version) VALUES ('0408'); -- gmc CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0408.schema.update_maintain_901.sql b/Open-ILS/src/sql/Pg/upgrade/0408.schema.update_maintain_901.sql new file mode 100644 index 000000000..256bcf07a --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0408.schema.update_maintain_901.sql @@ -0,0 +1,57 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0408'); -- gmc + +CREATE OR REPLACE FUNCTION maintain_901 () RETURNS TRIGGER AS $func$ +BEGIN + -- Remove any existing 901 fields before we insert the authoritative one + NEW.marc := REGEXP_REPLACE(NEW.marc, E']*?\s*tag="901".+?', '', 'g'); + IF TG_TABLE_SCHEMA = 'biblio' THEN + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.tcn_value || E'' || + '' || NEW.tcn_source || E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + CASE WHEN NEW.owner IS NOT NULL THEN '' || NEW.owner || E'' ELSE '' END || + CASE WHEN NEW.share_depth IS NOT NULL THEN '' || NEW.share_depth || E'' ELSE '' END || + E'\\1' + ); + ELSIF TG_TABLE_SCHEMA = 'authority' THEN + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + E'\\1' + ); + ELSIF TG_TABLE_SCHEMA = 'serial' THEN + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + '' || NEW.owning_lib || E'' || + CASE WHEN NEW.record IS NOT NULL THEN '' || NEW.record || E'' ELSE '' END || + E'\\1' + ); + ELSE + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + E'\\1' + ); + END IF; + + RETURN NEW; +END; +$func$ LANGUAGE PLPGSQL; + +COMMIT; -- 2.11.0