+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
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;
+