From: Bill Erickson Date: Mon, 20 Jun 2016 20:58:44 +0000 (-0400) Subject: JBAS-1437 Remove deprecated Backstage export functions X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=90f0a9be6d8b0c7c2508aa15b4798bcc256567ee;p=working%2FEvergreen.git JBAS-1437 Remove deprecated Backstage export functions Signed-off-by: Bill Erickson --- diff --git a/KCLS/sql/schema/deploy/backstage-exports-continued.sql b/KCLS/sql/schema/deploy/backstage-exports-continued.sql new file mode 100644 index 0000000000..e302317756 --- /dev/null +++ b/KCLS/sql/schema/deploy/backstage-exports-continued.sql @@ -0,0 +1,12 @@ +-- Deploy kcls-evergreen:backstage-exports-continued to pg +-- requires: ingram-edi-mods + +BEGIN; + +DROP FUNCTION IF EXISTS public.export_ids_cat_date(bigint, date, date); +DROP FUNCTION IF EXISTS public.export_ids_001(bigint); +DROP FUNCTION IF EXISTS public.export_ids_086_092_099(bigint); +DROP FUNCTION IF EXISTS public.export_ids_998(bigint); +DROP FUNCTION IF EXISTS public.export_generate_ids(date, date); + +COMMIT; diff --git a/KCLS/sql/schema/revert/backstage-exports-continued.sql b/KCLS/sql/schema/revert/backstage-exports-continued.sql new file mode 100644 index 0000000000..9cd3026976 --- /dev/null +++ b/KCLS/sql/schema/revert/backstage-exports-continued.sql @@ -0,0 +1,133 @@ +-- Revert kcls-evergreen:backstage-exports-continued from pg + +BEGIN; + +-- XXX Add DDLs here. + +CREATE FUNCTION public.export_ids_cat_date(record_to_check bigint, start_date date, end_date date) RETURNS boolean + LANGUAGE plpgsql STABLE + AS $$ + +-- Returns true if a record has a Cat Date that falls between start_date and end_date inclusive. +DECLARE + v_cat_date TIMESTAMP WITH TIME ZONE; +BEGIN + + IF start_date IS NULL OR end_date IS NULL THEN + RETURN TRUE; + ELSE + SELECT cataloging_date INTO v_cat_date + FROM biblio.record_entry + WHERE id = record_to_check; + + IF v_cat_date >= start_date AND v_cat_date <= end_date THEN + RETURN TRUE; + ELSE + RETURN FALSE; + END IF; + END IF; +END $$; + +CREATE FUNCTION public.export_ids_001(record_to_check bigint) RETURNS boolean + LANGUAGE plpgsql STABLE + AS $$ + +-- Returns true if the record has at least one 001 field and at least one of those fields should contain “oc” +-- OR has at least one 035 field with "WaOLN" in subfield "a" +DECLARE + v_row_count BIGINT; +BEGIN + + SELECT count(*) INTO v_row_count + FROM metabib.real_full_rec + WHERE ((tag = '001' AND (value ILIKE 'oc%' OR value ILIKE 'on%' OR value ILIKE 'wln%')) + OR (tag = '035' AND subfield ILIKE 'a' AND value ILIKE '%WaOLN%')) + AND record = record_to_check; + + IF v_row_count > 0 THEN + RETURN TRUE; + ELSE + RETURN FALSE; + END IF; + +END $$; + +CREATE FUNCTION public.export_ids_086_092_099(record_to_check bigint) RETURNS boolean + LANGUAGE plpgsql STABLE + AS $$ + +-- Returns true if a record has at least one of the following fields 086 or 092 or 099 and every instance +-- of each of these fields must not contain “ON ORDER” +DECLARE + v_row_count BIGINT; +BEGIN + + SELECT count(*) INTO v_row_count + FROM metabib.real_full_rec + WHERE (tag = '086' OR tag = '092' OR tag = '099') AND value ILIKE '%on order%' AND record = record_to_check; + + IF v_row_count > 0 THEN + RETURN FALSE; + END IF; + + SELECT count(*) INTO v_row_count + FROM metabib.real_full_rec + WHERE (tag = '086' OR tag = '092' OR tag = '099') AND value NOT ILIKE '%on order%' AND record = record_to_check; + + IF v_row_count > 0 THEN + RETURN TRUE; + ELSE + RETURN FALSE; + END IF; + +END $$; + +CREATE FUNCTION public.export_ids_998(record_to_check bigint) RETURNS boolean + LANGUAGE plpgsql STABLE + AS $$ + +-- Returns true if a record has items attached OR the record must have at least one 998 field with subfield d that has +-- one of the following values ‘d’ or ‘t’ or ‘v’ or ‘w’ or ‘x’ or ‘y’ or ‘1’ +DECLARE + v_row_count BIGINT; +BEGIN + + SELECT count(*) INTO v_row_count + FROM metabib.real_full_rec + WHERE tag = '998' + AND subfield = 'd' + AND value IN ('d','t','v','w','x','y','1') + AND record = record_to_check; + + IF v_row_count > 0 OR public.export_ids_has_copy(record_to_check) THEN + RETURN TRUE; + ELSE + RETURN FALSE; + END IF; +END $$; + +CREATE FUNCTION public.export_generate_ids(start_date date, end_date date) RETURNS SETOF bigint + LANGUAGE sql STABLE + AS $$ +-- Generates a list of ids for exporting based on the following criteria +-- For a record to be exported it MUST MEET ALL of the following conditions +-- 1.The record must have at least one LDR field and byte 05 of every instance of that field must not be ‘d’. +-- AND +-- 2. The record must have at least one 001 field and at least one of those fields should contain “oc” +-- OR has at least one 035 field with "WaOLN" in subfield "a" +-- AND +-- 3. The record must have at least one of the following fields 086 or 092 or 099 and every instance of each of these fields must not contain “ON ORDER” +-- AND +-- 4. The record must have items attached OR the record must have at least one 998 field with subfield d that has one of the following values ‘d’ or ‘t’ or ‘v’ or ‘w’ or ‘x’ or ‘y’ or ‘1’ +-- AND +-- 5. The records Cat Date must fall between two dates supplied by the user. + + + SELECT id + FROM biblio.record_entry + WHERE public.export_ids_cat_date(id, start_date, end_date) AND public.export_ids_LDR(id) AND public.export_ids_001(id) + AND public.export_ids_086_092_099(id) AND public.export_ids_998(id); +$$; + + +COMMIT; diff --git a/KCLS/sql/schema/sqitch.plan b/KCLS/sql/schema/sqitch.plan index a371feac10..4fa1ee9534 100644 --- a/KCLS/sql/schema/sqitch.plan +++ b/KCLS/sql/schema/sqitch.plan @@ -37,3 +37,4 @@ copy-status-alerts [purge-user-activity] 2016-05-25T14:10:24Z Bill Erickson # Staged users get net_access_level vand-delete-speed-indexes [self-reg-net-access-level] 2016-09-30T14:52:21Z Bill Erickson # Indexes to speed up vandelay queue deleting auth-prop-mods-bib-meta [ingram-edi-mods] 2016-06-13T16:07:28Z Bill Erickson # Authority propagation udpates bib editor/edit_date +backstage-exports-continued [ingram-edi-mods] 2016-06-20T20:28:38Z Bill Erickson # Updating in-db export utilities diff --git a/KCLS/sql/schema/verify/backstage-exports-continued.sql b/KCLS/sql/schema/verify/backstage-exports-continued.sql new file mode 100644 index 0000000000..50058dae78 --- /dev/null +++ b/KCLS/sql/schema/verify/backstage-exports-continued.sql @@ -0,0 +1,7 @@ +-- Verify kcls-evergreen:backstage-exports-continued on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK;