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>
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)
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)