From: Bill Erickson Date: Wed, 30 Mar 2016 21:57:59 +0000 (-0400) Subject: LP#1564079 Checkout history skips nonexistent items X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=83c957265c98893a2a2072eb043563315318fce2;p=evergreen%2Fpines.git LP#1564079 Checkout history skips nonexistent items Modify the user checkout history migration process (2.9.3-2.10.0-upgrade-db.sql and 0960.schema.decouple_co_history.sql) to avoid inserting history rows for circulations whose copies do not exist in the database. For reference, this is a rare condition that cannot be recreated in a modern EG system short of modifying constraints. Signed-off-by: Bill Erickson Signed-off-by: Kathy Lussier --- diff --git a/Open-ILS/src/sql/Pg/upgrade/0960.schema.decouple_co_history.sql b/Open-ILS/src/sql/Pg/upgrade/0960.schema.decouple_co_history.sql index 59e13b7d61..135c244987 100644 --- a/Open-ILS/src/sql/Pg/upgrade/0960.schema.decouple_co_history.sql +++ b/Open-ILS/src/sql/Pg/upgrade/0960.schema.decouple_co_history.sql @@ -213,6 +213,14 @@ BEGIN FOR cur_circ IN SELECT * FROM action.usr_visible_circs(cur_usr) LOOP + PERFORM TRUE FROM asset.copy WHERE id = cur_circ.target_copy; + + -- Avoid inserting a circ history row when the circulated + -- item has been (forcibly) removed from the database. + IF NOT FOUND THEN + CONTINUE; + END IF; + -- Find the last circ in the circ chain. SELECT INTO last_circ * FROM action.circ_chain(cur_circ.id) diff --git a/Open-ILS/src/sql/Pg/version-upgrade/2.9.3-2.10.0-upgrade-db.sql b/Open-ILS/src/sql/Pg/version-upgrade/2.9.3-2.10.0-upgrade-db.sql index 7440667420..9ed7e229e6 100644 --- a/Open-ILS/src/sql/Pg/version-upgrade/2.9.3-2.10.0-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/version-upgrade/2.9.3-2.10.0-upgrade-db.sql @@ -1527,6 +1527,14 @@ BEGIN FOR cur_circ IN SELECT * FROM action.usr_visible_circs(cur_usr) LOOP + PERFORM TRUE FROM asset.copy WHERE id = cur_circ.target_copy; + + -- Avoid inserting a circ history row when the circulated + -- item has been (forcibly) removed from the database. + IF NOT FOUND THEN + CONTINUE; + END IF; + -- Find the last circ in the circ chain. SELECT INTO last_circ * FROM action.circ_chain(cur_circ.id)