From 5176666fcd2818f75484afac1da324e785a6252c Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 13 Oct 2010 02:33:59 +0000 Subject: [PATCH] thinko supporting multiple rules of the same type in in-line merge rulesets git-svn-id: svn://svn.open-ils.org/ILS/trunk@18303 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/012.schema.vandelay.sql | 8 ++-- Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql | 8 ++-- .../sql/Pg/upgrade/0436.schema.multiple-rules.sql | 50 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0436.schema.multiple-rules.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 7fb85d227..0294e8a5e 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -70,7 +70,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0435'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0436'); -- miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 5ec966ad5..95ff5eb3b 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -475,10 +475,10 @@ BEGIN END IF; END IF; - add_rule := add_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="a"]/text()',incoming_xml),''),''); - strip_rule := strip_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="d"]/text()',incoming_xml),''),''); - replace_rule := replace_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="r"]/text()',incoming_xml),''),''); - preserve_rule := preserve_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="p"]/text()',incoming_xml),''),''); + add_rule := add_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="a"]/text()',incoming_xml),','),''); + strip_rule := strip_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="d"]/text()',incoming_xml),','),''); + replace_rule := replace_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="r"]/text()',incoming_xml),','),''); + preserve_rule := preserve_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="p"]/text()',incoming_xml),','),''); output.add_rule := BTRIM(add_rule,','); output.replace_rule := BTRIM(replace_rule,','); diff --git a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql index 04bdab6d7..77d2dc4a2 100644 --- a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql @@ -14146,10 +14146,10 @@ BEGIN END IF; END IF; - add_rule := add_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="a"]/text()',incoming_xml),''),''); - strip_rule := strip_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="d"]/text()',incoming_xml),''),''); - replace_rule := replace_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="r"]/text()',incoming_xml),''),''); - preserve_rule := preserve_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="p"]/text()',incoming_xml),''),''); + add_rule := add_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="a"]/text()',incoming_xml),','),''); + strip_rule := strip_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="d"]/text()',incoming_xml),','),''); + replace_rule := replace_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="r"]/text()',incoming_xml),','),''); + preserve_rule := preserve_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="p"]/text()',incoming_xml),','),''); output.add_rule := BTRIM(add_rule,','); output.replace_rule := BTRIM(replace_rule,','); diff --git a/Open-ILS/src/sql/Pg/upgrade/0436.schema.multiple-rules.sql b/Open-ILS/src/sql/Pg/upgrade/0436.schema.multiple-rules.sql new file mode 100644 index 000000000..6d02c4046 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0436.schema.multiple-rules.sql @@ -0,0 +1,50 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0436'); -- miker + +CREATE OR REPLACE FUNCTION vandelay.compile_profile ( incoming_xml TEXT ) RETURNS vandelay.compile_profile AS $_$ +DECLARE + output vandelay.compile_profile%ROWTYPE; + profile vandelay.merge_profile%ROWTYPE; + profile_tmpl TEXT; + profile_tmpl_owner TEXT; + add_rule TEXT := ''; + strip_rule TEXT := ''; + replace_rule TEXT := ''; + preserve_rule TEXT := ''; + +BEGIN + + profile_tmpl := (oils_xpath('//*[@tag="905"]/*[@code="t"]/text()',incoming_xml))[1]; + profile_tmpl_owner := (oils_xpath('//*[@tag="905"]/*[@code="o"]/text()',incoming_xml))[1]; + + IF profile_tmpl IS NOT NULL AND profile_tmpl <> '' AND profile_tmpl_owner IS NOT NULL AND profile_tmpl_owner <> '' THEN + SELECT p.* INTO profile + FROM vandelay.merge_profile p + JOIN actor.org_unit u ON (u.id = p.owner) + WHERE p.name = profile_tmpl + AND u.shortname = profile_tmpl_owner; + + IF profile.id IS NOT NULL THEN + add_rule := COALESCE(profile.add_spec,''); + strip_rule := COALESCE(profile.strip_spec,''); + replace_rule := COALESCE(profile.replace_spec,''); + preserve_rule := COALESCE(profile.preserve_spec,''); + END IF; + END IF; + + add_rule := add_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="a"]/text()',incoming_xml),','),''); + strip_rule := strip_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="d"]/text()',incoming_xml),','),''); + replace_rule := replace_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="r"]/text()',incoming_xml),','),''); + preserve_rule := preserve_rule || ',' || COALESCE(ARRAY_TO_STRING(oils_xpath('//*[@tag="905"]/*[@code="p"]/text()',incoming_xml),','),''); + + output.add_rule := BTRIM(add_rule,','); + output.replace_rule := BTRIM(replace_rule,','); + output.strip_rule := BTRIM(strip_rule,','); + output.preserve_rule := BTRIM(preserve_rule,','); + + RETURN output; +END; +$_$ LANGUAGE PLPGSQL; + +COMMIT; -- 2.11.0