[open-ils-commits] r19032 - in trunk/Open-ILS/src/sql/Pg: . upgrade (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Dec 21 15:22:03 EST 2010
Author: dbs
Date: 2010-12-21 15:21:58 -0500 (Tue, 21 Dec 2010)
New Revision: 19032
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0472.schema.authority-merge.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql
trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
Log:
Propagate merged authority record change to bibliographic record
Launchpad bug 688015 reported that the merge of authority records
resulted in the control number identifier in a controlled field
in a bibliographic record changing to the right value, but the
value of the field itself wasn't being changed.
The problem turned out to be a confusion of the "source" and
"target" values in the authority.merge_record() function. Once
that was straightened out, the merge updated the controlled
field as expected.
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-21 19:37:57 UTC (rev 19031)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-21 20:21:58 UTC (rev 19032)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0471'); -- dbs
+INSERT INTO config.upgrade_log (version) VALUES ('0472'); -- dbs
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-12-21 19:37:57 UTC (rev 19031)
+++ trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-12-21 20:21:58 UTC (rev 19032)
@@ -200,6 +200,11 @@
ingest_same boolean;
BEGIN
+ -- Defining our terms:
+ -- "target record" = the record that will survive the merge
+ -- "source record" = the record that is sacrifing its existence and being
+ -- replaced by the target record
+
-- 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
@@ -230,7 +235,7 @@
-- in linked bibliographic records
UPDATE authority.record_entry
SET deleted = FALSE
- WHERE id = source_record;
+ WHERE id = target_record;
-- 5. "Delete" source_record
DELETE FROM authority.record_entry
Modified: trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2010-12-21 19:37:57 UTC (rev 19031)
+++ trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2010-12-21 20:21:58 UTC (rev 19032)
@@ -17325,6 +17325,11 @@
ingest_same boolean;
BEGIN
+ -- Defining our terms:
+ -- "target record" = the record that will survive the merge
+ -- "source record" = the record that is sacrifing its existence and being
+ -- replaced by the target record
+
-- 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
@@ -17354,8 +17359,8 @@
-- 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;
+ SET deleted = FALSE
+ WHERE id = target_record;
-- 5. "Delete" source_record
DELETE FROM authority.record_entry
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0472.schema.authority-merge.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0472.schema.authority-merge.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0472.schema.authority-merge.sql 2010-12-21 20:21:58 UTC (rev 19032)
@@ -0,0 +1,65 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0472'); -- 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
+
+ -- Defining our terms:
+ -- "target record" = the record that will survive the merge
+ -- "source record" = the record that is sacrifing its existence and being
+ -- replaced by the target record
+
+ -- 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 = target_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