[open-ils-commits] [GIT] Evergreen ILS branch rel_2_2 updated. 27cfefce8b098f5acc210c73c7c992aba070998e
Evergreen Git
git at git.evergreen-ils.org
Mon May 14 15:21:30 EDT 2012
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_2 has been updated
via 27cfefce8b098f5acc210c73c7c992aba070998e (commit)
from 172ebd640cbed0a6fbebcfdb3e0ff494f4f35ee4 (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 27cfefce8b098f5acc210c73c7c992aba070998e
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date: Mon May 14 12:46:44 2012 -0400
Avoid collisions of normalized values going into metabib.browse_entry
This fixes a bug that prevented successful reingestion of bib records
during the 2.1->2.2 upgrade in some cases. Reported by George Duimovich.
Key part here:
> ERROR: duplicate key value violates unique constraint
> "browse_entry_value_key"
> DETAIL: Key (value)=(545575) already exists.
> CONTEXT: SQL statement "INSERT INTO metabib.browse_entry (value) VALUES
> (metabib.browse_normalize(ind_data.value,
George confirmed that the changes to the version upgrade script fixed
the problem for him.
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous 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 db99514..d541c58 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -87,7 +87,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 ('0710', :eg_version); -- senator
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0711', :eg_version); -- senator
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0711.schema.reingest_avoid_collision_better.sql b/Open-ILS/src/sql/Pg/upgrade/0711.schema.reingest_avoid_collision_better.sql
new file mode 100644
index 0000000..1f5df40
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0711.schema.reingest_avoid_collision_better.sql
@@ -0,0 +1,78 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('0711', :eg_version);
+
+CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries( bib_id BIGINT, skip_facet BOOL DEFAULT FALSE, skip_browse BOOL DEFAULT FALSE, skip_search BOOL DEFAULT FALSE ) RETURNS VOID AS $func$
+DECLARE
+ fclass RECORD;
+ ind_data metabib.field_entry_template%ROWTYPE;
+ mbe_row metabib.browse_entry%ROWTYPE;
+ mbe_id BIGINT;
+ normalized_value TEXT;
+BEGIN
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.assume_inserts_only' AND enabled;
+ IF NOT FOUND THEN
+ IF NOT skip_search THEN
+ FOR fclass IN SELECT * FROM config.metabib_class LOOP
+ -- RAISE NOTICE 'Emptying out %', fclass.name;
+ EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
+ END LOOP;
+ END IF;
+ IF NOT skip_facet THEN
+ DELETE FROM metabib.facet_entry WHERE source = bib_id;
+ END IF;
+ IF NOT skip_browse THEN
+ DELETE FROM metabib.browse_entry_def_map WHERE source = bib_id;
+ END IF;
+ END IF;
+
+ FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) LOOP
+ IF ind_data.field < 0 THEN
+ ind_data.field = -1 * ind_data.field;
+ END IF;
+
+ IF ind_data.facet_field AND NOT skip_facet THEN
+ INSERT INTO metabib.facet_entry (field, source, value)
+ VALUES (ind_data.field, ind_data.source, ind_data.value);
+ END IF;
+
+ IF ind_data.browse_field AND NOT skip_browse THEN
+ -- A caveat about this SELECT: this should take care of replacing
+ -- old mbe rows when data changes, but not if normalization (by
+ -- which I mean specifically the output of
+ -- evergreen.oils_tsearch2()) changes. It may or may not be
+ -- expensive to add a comparison of index_vector to index_vector
+ -- to the WHERE clause below.
+ normalized_value := metabib.browse_normalize(
+ ind_data.value, ind_data.field
+ );
+
+ SELECT INTO mbe_row * FROM metabib.browse_entry WHERE value = normalized_value;
+ IF FOUND THEN
+ mbe_id := mbe_row.id;
+ ELSE
+ INSERT INTO metabib.browse_entry (value) VALUES (normalized_value);
+ mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
+ END IF;
+
+ INSERT INTO metabib.browse_entry_def_map (entry, def, source)
+ VALUES (mbe_id, ind_data.field, ind_data.source);
+ END IF;
+
+ IF ind_data.search_field AND NOT skip_search THEN
+ EXECUTE $$
+ INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
+ VALUES ($$ ||
+ quote_literal(ind_data.field) || $$, $$ ||
+ quote_literal(ind_data.source) || $$, $$ ||
+ quote_literal(ind_data.value) ||
+ $$);$$;
+ END IF;
+
+ END LOOP;
+
+ RETURN;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
diff --git a/Open-ILS/src/sql/Pg/version-upgrade/2.1-2.2-upgrade-db.sql b/Open-ILS/src/sql/Pg/version-upgrade/2.1-2.2-upgrade-db.sql
index 6d1a138..8329a41 100644
--- a/Open-ILS/src/sql/Pg/version-upgrade/2.1-2.2-upgrade-db.sql
+++ b/Open-ILS/src/sql/Pg/version-upgrade/2.1-2.2-upgrade-db.sql
@@ -10082,6 +10082,9 @@ SELECT auditor.update_auditors();
-- check whether patch can be applied
SELECT evergreen.upgrade_deps_block_check('0687', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('0711', :eg_version); -- introduces
+-- changes to metabib.reingest_metabib_field_entries() that must happen here
+-- rather than later in a separate CREATE OR REPLACE FUNCTION statement.
-- FIXME: add/check SQL statements to perform the upgrade
-- New function def
@@ -10091,6 +10094,7 @@ DECLARE
ind_data metabib.field_entry_template%ROWTYPE;
mbe_row metabib.browse_entry%ROWTYPE;
mbe_id BIGINT;
+ normalized_value TEXT;
BEGIN
PERFORM * FROM config.internal_flag WHERE name = 'ingest.assume_inserts_only' AND enabled;
IF NOT FOUND THEN
@@ -10125,12 +10129,15 @@ BEGIN
-- evergreen.oils_tsearch2()) changes. It may or may not be
-- expensive to add a comparison of index_vector to index_vector
-- to the WHERE clause below.
- SELECT INTO mbe_row * FROM metabib.browse_entry WHERE value = ind_data.value;
+ normalized_value := metabib.browse_normalize(
+ ind_data.value, ind_data.field
+ );
+
+ SELECT INTO mbe_row * FROM metabib.browse_entry WHERE value = normalized_value;
IF FOUND THEN
mbe_id := mbe_row.id;
ELSE
- INSERT INTO metabib.browse_entry (value) VALUES
- (metabib.browse_normalize(ind_data.value, ind_data.field));
+ INSERT INTO metabib.browse_entry (value) VALUES (normalized_value);
mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
END IF;
@@ -11700,6 +11707,7 @@ SELECT evergreen.upgrade_deps_block_check('0700', :eg_version);
SELECT evergreen.upgrade_deps_block_check('0706', :eg_version);
SELECT evergreen.upgrade_deps_block_check('0710', :eg_version);
+
CREATE OR REPLACE FUNCTION evergreen.could_be_serial_holding_code(TEXT) RETURNS BOOL AS $$
use JSON::XS;
use MARC::Field;
-----------------------------------------------------------------------
Summary of changes:
Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +-
...711.schema.reingest_avoid_collision_better.sql} | 24 ++++++-------------
.../sql/Pg/version-upgrade/2.1-2.2-upgrade-db.sql | 14 +++++++++--
3 files changed, 20 insertions(+), 20 deletions(-)
copy Open-ILS/src/sql/Pg/upgrade/{0687.schema.enhance_reingest.sql => 0711.schema.reingest_avoid_collision_better.sql} (83%)
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list