add event output removal
[migration-tools.git] / remove_ou_data / 15_remove_ou_extras.sql
index 08bab80..4670ad8 100644 (file)
@@ -38,6 +38,13 @@ WHERE copy_location IN (SELECT id FROM asset.copy_location WHERE owning_lib IN
 DELETE FROM asset.copy_location WHERE owning_lib IN
 (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
 
+DELETE FROM money.account_adjustment WHERE billing IN 
+    (SELECT id FROM money.billing WHERE btype IN (
+        SELECT id FROM config.billing_type
+        WHERE owner IN
+        (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
+));
+
 DELETE FROM money.billing
 WHERE btype IN (
     SELECT id FROM config.billing_type
@@ -45,6 +52,30 @@ WHERE btype IN (
     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
 );
 
+DELETE FROM action_trigger.event_output WHERE id IN (
+SELECT template_output FROM action_trigger.event 
+WHERE  event_def IN (
+    SELECT id FROM action_trigger.event_definition
+    WHERE owner IN
+    (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
+));
+
+DELETE FROM action_trigger.event_output WHERE id IN (
+SELECT async_output FROM action_trigger.event 
+WHERE  event_def IN (
+    SELECT id FROM action_trigger.event_definition
+    WHERE owner IN
+    (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
+));
+
+DELETE FROM action_trigger.event_output WHERE id IN (
+SELECT error_output FROM action_trigger.event 
+WHERE  event_def IN (
+    SELECT id FROM action_trigger.event_definition
+    WHERE owner IN
+    (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
+));
+
 DELETE FROM action_trigger.event
 WHERE event_def IN (
     SELECT id FROM action_trigger.event_definition
@@ -63,6 +94,7 @@ WHERE event_def IN (
     WHERE owner IN
     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
 );
+
 DELETE FROM action_trigger.event_definition
     WHERE owner IN
     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);