[open-ils-commits] r18568 - branches/rel_2_0/Open-ILS/src/sql/Pg (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 1 22:47:49 EDT 2010
Author: dbs
Date: 2010-11-01 22:47:47 -0400 (Mon, 01 Nov 2010)
New Revision: 18568
Added:
branches/rel_2_0/Open-ILS/src/sql/Pg/0454.function.authority_merge_records.sql
Modified:
branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql
Log:
Enable merge of authority records to do the right thing
The target and source authority record was flipped, causing
the update to fail. In reconsidering this function, it is not
necessary to change the contents of the source authority record
just to propagate the content of the target authority record
to any linked bibliographic records.
Instead, take the approach of updating the ID of the controlled
field in the bib record, then temporarily set "reingest on same
MARC" to TRUE and update the target authority record by setting
deleted = FALSE (which propagates the "changes" to the linked
bib records), then set "reingest on same MARC" flag back to its
original value.
This has the bonus of actually working.
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-11-02 02:46:51 UTC (rev 18567)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-11-02 02:47:47 UTC (rev 18568)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0453'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0454'); -- dbs
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-11-02 02:46:51 UTC (rev 18567)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-11-02 02:47:47 UTC (rev 18568)
@@ -196,21 +196,13 @@
bib_id INT := 0;
bib_rec biblio.record_entry%ROWTYPE;
auth_link authority.bib_linking%ROWTYPE;
+ ingest_same boolean;
BEGIN
- -- 1. Make source_record MARC a copy of the target_record to get auto-sync in linked bib records
- UPDATE authority.record_entry
- SET marc = (
- SELECT marc
- FROM authority.record_entry
- WHERE id = target_record
- )
- WHERE id = source_record;
-
- -- 2. Update all bib records with the ID from target_record in their $0
+ -- 1. Update all bib records with the ID from target_record in their $0
FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre
INNER JOIN authority.bib_linking abl ON abl.bib = bre.id
- WHERE abl.authority = target_record LOOP
+ WHERE abl.authority = source_record LOOP
UPDATE biblio.record_entry
SET marc = REGEXP_REPLACE(marc,
@@ -221,10 +213,34 @@
moved_objects := moved_objects + 1;
END LOOP;
- -- 3. "Delete" source_record
+ -- 2. Grab the current value of reingest on same MARC flag
+ SELECT enabled INTO ingest_same
+ FROM config.internal_flag
+ WHERE name = 'ingest.reingest.force_on_same_marc'
+ ;
+
+ -- 3. Temporarily set reingest on same to TRUE
+ UPDATE config.internal_flag
+ SET enabled = TRUE
+ WHERE name = 'ingest.reingest.force_on_same_marc'
+ ;
+
+ -- 4. Make a harmless update to target_record to trigger auto-update
+ -- in linked bibliographic records
+ UPDATE authority.record_entry
+ SET deleted = FALSE
+ WHERE id = source_record;
+
+ -- 5. "Delete" source_record
DELETE FROM authority.record_entry
WHERE id = source_record;
+ -- 6. Set "reingest on same MARC" flag back to initial value
+ UPDATE config.internal_flag
+ SET enabled = ingest_same
+ WHERE name = 'ingest.reingest.force_on_same_marc'
+ ;
+
RETURN moved_objects;
END;
$func$ LANGUAGE plpgsql;
Copied: branches/rel_2_0/Open-ILS/src/sql/Pg/0454.function.authority_merge_records.sql (from rev 18567, trunk/Open-ILS/src/sql/Pg/0454.function.authority_merge_records.sql)
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/0454.function.authority_merge_records.sql (rev 0)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/0454.function.authority_merge_records.sql 2010-11-02 02:47:47 UTC (rev 18568)
@@ -0,0 +1,60 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0454'); -- dbs
+
+CREATE OR REPLACE FUNCTION authority.merge_records ( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
+DECLARE
+ moved_objects INT := 0;
+ bib_id INT := 0;
+ bib_rec biblio.record_entry%ROWTYPE;
+ auth_link authority.bib_linking%ROWTYPE;
+ ingest_same boolean;
+BEGIN
+
+ -- 1. Update all bib records with the ID from target_record in their $0
+ FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre
+ INNER JOIN authority.bib_linking abl ON abl.bib = bre.id
+ WHERE abl.authority = source_record LOOP
+
+ UPDATE biblio.record_entry
+ SET marc = REGEXP_REPLACE(marc,
+ E'(<subfield\\s+code="0"\\s*>[^<]*?\\))' || source_record || '<',
+ E'\\1' || target_record || '<', 'g')
+ WHERE id = bib_rec.id;
+
+ moved_objects := moved_objects + 1;
+ END LOOP;
+
+ -- 2. Grab the current value of reingest on same MARC flag
+ SELECT enabled INTO ingest_same
+ FROM config.internal_flag
+ WHERE name = 'ingest.reingest.force_on_same_marc'
+ ;
+
+ -- 3. Temporarily set reingest on same to TRUE
+ UPDATE config.internal_flag
+ SET enabled = TRUE
+ WHERE name = 'ingest.reingest.force_on_same_marc'
+ ;
+
+ -- 4. Make a harmless update to target_record to trigger auto-update
+ -- in linked bibliographic records
+ UPDATE authority.record_entry
+ SET DELETED = FALSE
+ WHERE id = source_record;
+
+ -- 5. "Delete" source_record
+ DELETE FROM authority.record_entry
+ WHERE id = source_record;
+
+ -- 6. Set "reingest on same MARC" flag back to initial value
+ UPDATE config.internal_flag
+ SET enabled = ingest_same
+ WHERE name = 'ingest.reingest.force_on_same_marc'
+ ;
+
+ RETURN moved_objects;
+END;
+$func$ LANGUAGE plpgsql;
+
+COMMIT;
More information about the open-ils-commits
mailing list