diff --git a/scripts/cleanup-closed.sql b/scripts/cleanup-closed.sql new file mode 100644 index 00000000..b1815071 --- /dev/null +++ b/scripts/cleanup-closed.sql @@ -0,0 +1,25 @@ +BEGIN TRANSACTION; + +DELETE FROM divisions +WHERE incident_id IN ( + SELECT id FROM incidents WHERE closed_at IS NOT NULL +); + +DELETE FROM messages +WHERE journal_id IN ( + SELECT id FROM journals + WHERE incident_id IN ( + SELECT id FROM incidents WHERE closed_at IS NOT NULL + ) +); + +DELETE FROM journals +WHERE incident_id IN ( + SELECT id FROM incidents WHERE closed_at IS NOT NULL +); + + +DELETE FROM incidents +WHERE closed_at IS NOT NULL; + +COMMIT;