[open-ils-commits] [GIT] Evergreen ILS branch rel_2_10 updated. 7f35fb315deb12fd2e37f02668858db885733911
Evergreen Git
git at git.evergreen-ils.org
Wed Nov 16 14:57:36 EST 2016
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".
The branch, rel_2_10 has been updated
via 7f35fb315deb12fd2e37f02668858db885733911 (commit)
via 237a26cbf4a1c5bf3ec285ae1ec400d431d0a7de (commit)
via 720d5b5495e72867229b6d0c1d024218c0840272 (commit)
from 350d602421df7d24cdd0c446e92005d946aa3450 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7f35fb315deb12fd2e37f02668858db885733911
Author: Galen Charlton <gmc at esilibrary.com>
Date: Wed Nov 16 14:55:02 2016 -0500
LP#1488655: stamp schema upgrade script
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 8fdf4f2..d72d83a 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps
BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1002', :eg_version); -- gmcharlt
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1003', :eg_version); -- gmcharlt/rhamby/csharp
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_metarecord_remapping.sql b/Open-ILS/src/sql/Pg/upgrade/1003.schema.fix_metarecord_remapping.sql
similarity index 97%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_metarecord_remapping.sql
rename to Open-ILS/src/sql/Pg/upgrade/1003.schema.fix_metarecord_remapping.sql
index 62d9781..cfe7b83 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_metarecord_remapping.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/1003.schema.fix_metarecord_remapping.sql
@@ -1,6 +1,6 @@
BEGIN;
---- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('1003', :eg_version); -- gmcharlt/rhamby/csharp
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
commit 237a26cbf4a1c5bf3ec285ae1ec400d431d0a7de
Author: Galen Charlton <gmc at esilibrary.com>
Date: Fri Oct 28 11:42:52 2016 -0400
LP#1488655: fix MR remapping upon fingerprint change
This patch ensures that if the fingerprint of a bib changes, the
bib will be moved to a new metarecord as opposed to ending up
as a member of more than one metarecord.
To test
-------
[1] Note the metarecord that a bib belongs to.
[2] Change the bib so that its fingerprint changes -- with stock
cbf settings, editing the 245$a should suffice.
[3] Note that it is now a component of two metarecords.
[4] Apply the patch.
[5] Repeat step 2 or force a reingest. The bib should now be part
of exactly one metarecord.
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
Signed-off-by: Rogan Hamby <rogan.hamby at gmail.com>
Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
index f7aa05a..4ccb04f 100644
--- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql
+++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
@@ -1266,7 +1266,7 @@ BEGIN
new_mapping := FALSE;
ELSE -- Our fingerprint changed ... maybe remove the old MR
- DELETE FROM metabib.metarecord_source_map WHERE metarecord = old_mr AND source = bib_id; -- remove the old source mapping
+ DELETE FROM metabib.metarecord_source_map WHERE metarecord = tmp_mr.id AND source = bib_id; -- remove the old source mapping
SELECT COUNT(*) INTO source_count FROM metabib.metarecord_source_map WHERE metarecord = tmp_mr.id;
IF source_count = 0 THEN -- No other records
deleted_mrs := ARRAY_APPEND(deleted_mrs, tmp_mr.id);
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_metarecord_remapping.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_metarecord_remapping.sql
new file mode 100644
index 0000000..62d9781
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_metarecord_remapping.sql
@@ -0,0 +1,94 @@
+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
+ new_mapping BOOL := TRUE;
+ source_count INT;
+ old_mr BIGINT;
+ tmp_mr metabib.metarecord%ROWTYPE;
+ deleted_mrs BIGINT[];
+BEGIN
+
+ -- We need to make sure we're not a deleted master record of an MR
+ IF bib_is_deleted THEN
+ FOR old_mr IN SELECT id FROM metabib.metarecord WHERE master_record = bib_id LOOP
+
+ IF NOT retain_deleted THEN -- Go away for any MR that we're master of, unless retained
+ DELETE FROM metabib.metarecord_source_map WHERE source = bib_id;
+ END IF;
+
+ -- Now, are there any more sources on this MR?
+ SELECT COUNT(*) INTO source_count FROM metabib.metarecord_source_map WHERE metarecord = old_mr;
+
+ IF source_count = 0 AND NOT retain_deleted THEN -- No other records
+ deleted_mrs := ARRAY_APPEND(deleted_mrs, old_mr); -- Just in case...
+ DELETE FROM metabib.metarecord WHERE id = old_mr;
+
+ ELSE -- indeed there are. Update it with a null cache and recalcualated master record
+ UPDATE metabib.metarecord
+ SET mods = NULL,
+ master_record = ( SELECT id FROM biblio.record_entry WHERE fingerprint = fp AND NOT deleted ORDER BY quality DESC LIMIT 1)
+ WHERE id = old_mr;
+ END IF;
+ END LOOP;
+
+ ELSE -- insert or update
+
+ FOR tmp_mr IN SELECT m.* FROM metabib.metarecord m JOIN metabib.metarecord_source_map s ON (s.metarecord = m.id) WHERE s.source = bib_id LOOP
+
+ -- Find the first fingerprint-matching
+ IF old_mr IS NULL AND fp = tmp_mr.fingerprint THEN
+ old_mr := tmp_mr.id;
+ new_mapping := FALSE;
+
+ ELSE -- Our fingerprint changed ... maybe remove the old MR
+ DELETE FROM metabib.metarecord_source_map WHERE metarecord = tmp_mr.id AND source = bib_id; -- remove the old source mapping
+ SELECT COUNT(*) INTO source_count FROM metabib.metarecord_source_map WHERE metarecord = tmp_mr.id;
+ IF source_count = 0 THEN -- No other records
+ deleted_mrs := ARRAY_APPEND(deleted_mrs, tmp_mr.id);
+ DELETE FROM metabib.metarecord WHERE id = tmp_mr.id;
+ END IF;
+ END IF;
+
+ END LOOP;
+
+ -- we found no suitable, preexisting MR based on old source maps
+ IF old_mr IS NULL THEN
+ SELECT id INTO old_mr FROM metabib.metarecord WHERE fingerprint = fp; -- is there one for our current fingerprint?
+
+ IF old_mr IS NULL THEN -- nope, create one and grab its id
+ INSERT INTO metabib.metarecord ( fingerprint, master_record ) VALUES ( fp, bib_id );
+ SELECT id INTO old_mr FROM metabib.metarecord WHERE fingerprint = fp;
+
+ ELSE -- indeed there is. update it with a null cache and recalcualated master record
+ UPDATE metabib.metarecord
+ SET mods = NULL,
+ master_record = ( SELECT id FROM biblio.record_entry WHERE fingerprint = fp AND NOT deleted ORDER BY quality DESC LIMIT 1)
+ WHERE id = old_mr;
+ END IF;
+
+ ELSE -- there was one we already attached to, update its mods cache and master_record
+ UPDATE metabib.metarecord
+ SET mods = NULL,
+ master_record = ( SELECT id FROM biblio.record_entry WHERE fingerprint = fp AND NOT deleted ORDER BY quality DESC LIMIT 1)
+ WHERE id = old_mr;
+ END IF;
+
+ IF new_mapping THEN
+ INSERT INTO metabib.metarecord_source_map (metarecord, source) VALUES (old_mr, bib_id); -- new source mapping
+ END IF;
+
+ END IF;
+
+ IF ARRAY_UPPER(deleted_mrs,1) > 0 THEN
+ UPDATE action.hold_request SET target = old_mr WHERE target IN ( SELECT unnest(deleted_mrs) ) AND hold_type = 'M'; -- if we had to delete any MRs above, make sure their holds are moved
+ END IF;
+
+ RETURN old_mr;
+
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
commit 720d5b5495e72867229b6d0c1d024218c0840272
Author: Galen Charlton <gmc at esilibrary.com>
Date: Fri Oct 28 11:40:52 2016 -0400
LP#1488655: regression test for metarecord remapping
This patch contains pgTAP tests for verifying that when
the fingerprint of a bib is changed, it remains part of
exactly one metarecord (as opposed to being part of both
its old and new MRs).
Signed-off-by: Galen Charlton <gmc at esilibrary.com>
Signed-off-by: Rogan Hamby <rogan.hamby at gmail.com>
Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
diff --git a/Open-ILS/src/sql/Pg/t/lp1488655_metarecord_remapping.pg b/Open-ILS/src/sql/Pg/t/lp1488655_metarecord_remapping.pg
new file mode 100644
index 0000000..92205a3
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/t/lp1488655_metarecord_remapping.pg
@@ -0,0 +1,57 @@
+-- tests to verify that metarecord mapping updates happen correctly
+BEGIN;
+
+SELECT plan(4);
+
+INSERT INTO biblio.record_entry (last_xact_id, marc) VALUES (
+ 'metarecord-remap-test',
+ $record$<record xmlns="http://www.loc.gov/MARC21/slim">
+ <leader>02137cam a2200457 a 4500</leader>
+ <controlfield tag="001">ocn694080497</controlfield>
+ <controlfield tag="005">20160729104757.0</controlfield>
+ <controlfield tag="008">101217s2011 txu b 001 0 eng </controlfield>
+ <datafield tag="245" ind1="0" ind2="0">
+ <subfield code="a">Random Title AFDSDGFJ /</subfield>
+ <subfield code="c">Felix T. Cat.</subfield>
+ </datafield>
+</record>$record$);
+
+SELECT is(
+ (
+ SELECT COUNT(*) FROM metabib.metarecord
+ WHERE master_record = CURRVAL('biblio.record_entry_id_seq')
+ )::INT,
+ 1,
+ 'unique bib becomes master of just one metarecord'
+);
+SELECT is(
+ (
+ SELECT COUNT(*) FROM metabib.metarecord_source_map
+ WHERE source = CURRVAL('biblio.record_entry_id_seq')
+ )::INT,
+ 1,
+ 'unique bib part of just one metarecord mapping'
+);
+
+UPDATE biblio.record_entry
+SET marc = REPLACE(marc, 'Random Title AFDSDGFJ', 'Random Title XXDFYLNJ')
+WHERE id = CURRVAL('biblio.record_entry_id_seq');
+
+SELECT is(
+ (
+ SELECT COUNT(*) FROM metabib.metarecord
+ WHERE master_record = CURRVAL('biblio.record_entry_id_seq')
+ )::INT,
+ 1,
+ 'LP#1488655: after fingerprint change, bib still master of just one metarecord'
+);
+SELECT is(
+ (
+ SELECT COUNT(*) FROM metabib.metarecord_source_map
+ WHERE source = CURRVAL('biblio.record_entry_id_seq')
+ )::INT,
+ 1,
+ 'LP#1488655: after fingerprint change, bib still in just one metarecord mapping'
+);
+
+ROLLBACK;
-----------------------------------------------------------------------
Summary of changes:
Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +-
Open-ILS/src/sql/Pg/030.schema.metabib.sql | 2 +-
.../src/sql/Pg/t/lp1488655_metarecord_remapping.pg | 57 ++++++++++++
.../1003.schema.fix_metarecord_remapping.sql | 94 ++++++++++++++++++++
4 files changed, 153 insertions(+), 2 deletions(-)
create mode 100644 Open-ILS/src/sql/Pg/t/lp1488655_metarecord_remapping.pg
create mode 100644 Open-ILS/src/sql/Pg/upgrade/1003.schema.fix_metarecord_remapping.sql
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list