summaryrefslogtreecommitdiff
path: root/db
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
parent07e1ec5dc1473458c899e745e02e021abfe02212 (diff)
downloadgitlab-ce-9b93f8adc8d04ed2f62be06241723491711a6cbd.tar.gz
Destroy related todos when an issue is deleted
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20160324020319_remove_todos_for_deleted_issues.rb17
-rw-r--r--db/schema.rb2
2 files changed, 18 insertions, 1 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
diff --git a/db/schema.rb b/db/schema.rb
index dce2bfe62ca..9b9319ddb4f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160320204112) do
+ActiveRecord::Schema.define(version: 20160324020319) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"