LP#1564079 Checkout history skips nonexistent items
authorBill Erickson <berickxx@gmail.com>
Wed, 30 Mar 2016 21:57:59 +0000 (17:57 -0400)
committerKathy Lussier <klussier@masslnc.org>
Wed, 27 Apr 2016 14:27:03 +0000 (10:27 -0400)
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 <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/sql/Pg/upgrade/0960.schema.decouple_co_history.sql
Open-ILS/src/sql/Pg/version-upgrade/2.9.3-2.10.0-upgrade-db.sql

index 59e13b7..135c244 100644 (file)
@@ -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) 
index 7440667..9ed7e22 100644 (file)
@@ -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)