From: Chris Sharp Date: Tue, 11 Apr 2017 14:20:30 +0000 (-0400) Subject: LP#1170514 - Upgrade script for vandelay.auto_overlay_bib_record X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f9ee99cd9077d4f469a8465e3260a0f0ff8708e6;p=evergreen%2Fpines.git LP#1170514 - Upgrade script for vandelay.auto_overlay_bib_record This script got missed in the 2.1-2.2 era and finally makes it in nearly six years later. Not necessary for sites that began using Evergreen since then, but harmless to run. Signed-off-by: Chris Sharp Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay_auto_overlay_bib_record.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay_auto_overlay_bib_record.sql new file mode 100644 index 0000000000..ef1da1983d --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay_auto_overlay_bib_record.sql @@ -0,0 +1,44 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +-- This function was replaced back in 2011, but never made it +-- into an upgrade script. Here it is, nearly 6 years later. + +CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_record ( import_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$ +DECLARE + eg_id BIGINT; + match_count INT; +BEGIN + + PERFORM * FROM vandelay.queued_bib_record WHERE import_time IS NOT NULL AND id = import_id; + + IF FOUND THEN + -- RAISE NOTICE 'already imported, cannot auto-overlay' + RETURN FALSE; + END IF; + + SELECT COUNT(*) INTO match_count FROM vandelay.bib_match WHERE queued_record = import_id; + + IF match_count <> 1 THEN + -- RAISE NOTICE 'not an exact match'; + RETURN FALSE; + END IF; + + -- Check that the one match is on the first 901c + SELECT m.eg_record INTO eg_id + FROM vandelay.queued_bib_record q + JOIN vandelay.bib_match m ON (m.queued_record = q.id) + WHERE q.id = import_id + AND m.eg_record = oils_xpath_string('//*[@tag="901"]/*[@code="c"][1]',marc)::BIGINT; + + IF NOT FOUND THEN + -- RAISE NOTICE 'not a 901c match'; + RETURN FALSE; + END IF; + + RETURN vandelay.overlay_bib_record( import_id, eg_id, merge_profile_id ); +END; +$$ LANGUAGE PLPGSQL; + +COMMIT;