summaryrefslogtreecommitdiff
path: root/db/migrate/20160324020319_remove_todos_for_deleted_issues.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-23 23:14:02 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-30 12:09:34 -0300
commit9b93f8adc8d04ed2f62be06241723491711a6cbd (patch)
tree1a72351e92209386853d58bc3473df98f86060e7 /db/migrate/20160324020319_remove_todos_for_deleted_issues.rb
parent07e1ec5dc1473458c899e745e02e021abfe02212 (diff)
downloadgitlab-ce-9b93f8adc8d04ed2f62be06241723491711a6cbd.tar.gz
Destroy related todos when an issue is deleted
Diffstat (limited to 'db/migrate/20160324020319_remove_todos_for_deleted_issues.rb')
-rw-r--r--db/migrate/20160324020319_remove_todos_for_deleted_issues.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/db/migrate/20160324020319_remove_todos_for_deleted_issues.rb b/db/migrate/20160324020319_remove_todos_for_deleted_issues.rb
new file mode 100644
index 00000000000..1fff9759d1e
--- /dev/null
+++ b/db/migrate/20160324020319_remove_todos_for_deleted_issues.rb
@@ -0,0 +1,17 @@
+class RemoveTodosForDeletedIssues < ActiveRecord::Migration
+ def up
+ execute <<-SQL
+ DELETE FROM todos
+ WHERE todos.target_type = 'Issue'
+ AND NOT EXISTS (
+ SELECT *
+ FROM issues
+ WHERE issues.id = todos.target_id
+ AND issues.deleted_at IS NULL
+ )
+ SQL
+ end
+
+ def down
+ end
+end