update the noncat circ code to note delete non cat circs when the staff member is...
[migration-tools.git] / remove_ou_data / 04_remove_circ.sql
index c34da32..3073085 100644 (file)
@@ -24,6 +24,10 @@ ALTER TABLE action.circulation DISABLE TRIGGER age_parent_circ;
 
 BEGIN;
 
+UPDATE action.circulation SET parent_circ = NULL WHERE parent_circ
+(SELECT id FROM action.circulation WHERE circ_lib = (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del))
+AND circ_lib NOT IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
+
 DELETE FROM action.circulation WHERE usr IN
 (SELECT id FROM actor.usr WHERE home_ou IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
 
@@ -40,6 +44,13 @@ DELETE FROM action.aged_circulation WHERE copy_circ_lib IN
 DELETE FROM action.aged_circulation WHERE copy_owning_lib IN
 (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
 
+DELETE FROM action.non_cat_in_house_use WHERE org_unit IN 
+(SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
+
+UPDATE action.non_cat_in_house_use SET staff = 1 WHERE staff IN
+(SELECT id FROM actor.usr WHERE home_ou IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del))
+AND org_unit IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
+
 COMMIT;
 
 ALTER TABLE action.circulation ENABLE TRIGGER action_circulation_aging_tgr;