From: Galen Charlton Date: Tue, 20 May 2014 23:48:57 +0000 (-0700) Subject: LP#1312945: pin schema update X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4df12a913c2b9ca16e734dc965e58fffdb512d0f;p=evergreen%2Fmasslnc.git LP#1312945: pin schema update Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 9b0256002f..ba3ac96246 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 ('0879', :eg_version); -- dbwells/bshum +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0880', :eg_version); -- miker/sreyseng/gmcharlt CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0880.function.authority.calculate_authority_linking.sql b/Open-ILS/src/sql/Pg/upgrade/0880.function.authority.calculate_authority_linking.sql new file mode 100644 index 0000000000..507ceaf6b4 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0880.function.authority.calculate_authority_linking.sql @@ -0,0 +1,68 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('0880', :eg_version); + +CREATE OR REPLACE FUNCTION authority.calculate_authority_linking( + rec_id BIGINT, rec_control_set INT, rec_marc_xml XML +) RETURNS SETOF authority.authority_linking AS $func$ +DECLARE + acsaf authority.control_set_authority_field%ROWTYPE; + link TEXT; + aal authority.authority_linking%ROWTYPE; +BEGIN + IF rec_control_set IS NULL THEN + -- No control_set on record? Guess at one + SELECT control_set INTO rec_control_set + FROM authority.control_set_authority_field + WHERE tag IN ( + SELECT UNNEST( + XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc_xml)::TEXT[] + ) + ) LIMIT 1; + + IF NOT FOUND THEN + RAISE WARNING 'Could not even guess at control set for authority record %', rec_id; + RETURN; + END IF; + END IF; + + aal.source := rec_id; + + FOR acsaf IN + SELECT * FROM authority.control_set_authority_field + WHERE control_set = rec_control_set + AND linking_subfield IS NOT NULL + AND main_entry IS NOT NULL + LOOP + -- Loop over the trailing-number contents of all linking subfields + FOR link IN + SELECT SUBSTRING( x::TEXT, '\d+$' ) + FROM UNNEST( + XPATH( + '//*[@tag="' + || acsaf.tag + || '"]/*[@code="' + || acsaf.linking_subfield + || '"]/text()', + rec_marc_xml + ) + ) x + LOOP + + -- Ignore links that are null, malformed, circular, or point to + -- non-existent authority records. + IF link IS NOT NULL AND link::BIGINT <> rec_id THEN + PERFORM * FROM authority.record_entry WHERE id = link::BIGINT; + IF FOUND THEN + aal.target := link::BIGINT; + aal.field := acsaf.id; + RETURN NEXT aal; + END IF; + END IF; + END LOOP; + END LOOP; +END; +$func$ LANGUAGE PLPGSQL; + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.authority.calculate_authority_linking.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.authority.calculate_authority_linking.sql deleted file mode 100644 index 4347aaa71b..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.authority.calculate_authority_linking.sql +++ /dev/null @@ -1,68 +0,0 @@ -BEGIN; - -SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - -CREATE OR REPLACE FUNCTION authority.calculate_authority_linking( - rec_id BIGINT, rec_control_set INT, rec_marc_xml XML -) RETURNS SETOF authority.authority_linking AS $func$ -DECLARE - acsaf authority.control_set_authority_field%ROWTYPE; - link TEXT; - aal authority.authority_linking%ROWTYPE; -BEGIN - IF rec_control_set IS NULL THEN - -- No control_set on record? Guess at one - SELECT control_set INTO rec_control_set - FROM authority.control_set_authority_field - WHERE tag IN ( - SELECT UNNEST( - XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc_xml)::TEXT[] - ) - ) LIMIT 1; - - IF NOT FOUND THEN - RAISE WARNING 'Could not even guess at control set for authority record %', rec_id; - RETURN; - END IF; - END IF; - - aal.source := rec_id; - - FOR acsaf IN - SELECT * FROM authority.control_set_authority_field - WHERE control_set = rec_control_set - AND linking_subfield IS NOT NULL - AND main_entry IS NOT NULL - LOOP - -- Loop over the trailing-number contents of all linking subfields - FOR link IN - SELECT SUBSTRING( x::TEXT, '\d+$' ) - FROM UNNEST( - XPATH( - '//*[@tag="' - || acsaf.tag - || '"]/*[@code="' - || acsaf.linking_subfield - || '"]/text()', - rec_marc_xml - ) - ) x - LOOP - - -- Ignore links that are null, malformed, circular, or point to - -- non-existent authority records. - IF link IS NOT NULL AND link::BIGINT <> rec_id THEN - PERFORM * FROM authority.record_entry WHERE id = link::BIGINT; - IF FOUND THEN - aal.target := link::BIGINT; - aal.field := acsaf.id; - RETURN NEXT aal; - END IF; - END IF; - END LOOP; - END LOOP; -END; -$func$ LANGUAGE PLPGSQL; - -COMMIT; -