LP#1284864: Forcibly update deleted MR masters
authorMike Rylander <mrylander@gmail.com>
Mon, 10 Mar 2014 16:43:24 +0000 (12:43 -0400)
committerBen Shum <bshum@biblio.org>
Mon, 10 Mar 2014 16:54:01 +0000 (12:54 -0400)
Query derived from one by Ben Shum, altered to take deleted-record retention
configuration into account.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/sql/Pg/upgrade/XXXX.functions.metarecord-deleted-constituents.sql

index 7b98009..ab23ff5 100644 (file)
@@ -1,3 +1,6 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 
 CREATE OR REPLACE FUNCTION metabib.remap_metarecord_for_bib( bib_id BIGINT, fp TEXT, bib_is_deleted BOOL DEFAULT FALSE, retain_deleted BOOL DEFAULT FALSE ) RETURNS BIGINT AS $func$
 DECLARE
@@ -341,3 +344,12 @@ BEGIN
 END;
 $F$ LANGUAGE PLPGSQL STABLE;
 
+-- Forcibly remap deleted master records, retaining the linkage if so configured.
+SELECT  metabib.remap_metarecord_for_bib( bre.id, bre.fingerprint, TRUE, COALESCE(flag.enabled,FALSE))
+  FROM  metabib.metarecord metar
+        JOIN biblio.record_entry bre ON bre.id = metar.master_record,
+        config.internal_flag flag
+  WHERE bre.deleted = TRUE AND flag.name = 'ingest.metarecord_mapping.preserve_on_delete';
+
+COMMIT;
+