change to the data directly automatically with mig env use
[migration-tools.git] / remove_ou_data / 06_remove_copies.sql
index d37b113..58cbcb0 100644 (file)
@@ -25,6 +25,12 @@ CREATE INDEX tmp_import_as ON vandelay.import_item(imported_as);
 
 BEGIN;
 
+DELETE FROM asset.copy_alert WHERE copy IN (
+  SELECT id FROM asset.copy WHERE circ_lib IN
+    (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
+);
+
+
 -- NOTE: no FK
 DELETE FROM asset.opac_visible_copies WHERE copy_id IN (
   SELECT id FROM asset.copy WHERE circ_lib IN
@@ -55,6 +61,10 @@ DELETE FROM vandelay.import_item WHERE imported_as IN (
 DELETE FROM asset.copy WHERE circ_lib IN
 (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
 
+DELETE FROM asset.latest_inventory WHERE copy IN 
+    (SELECT li.copy FROM asset.latest_inventory li LEFT JOIN asset.copy acp ON acp.id = li.copy WHERE acp.id IS NULL)
+;
+
 COMMIT;
 
 DROP INDEX vandelay.tmp_import_as;