summaryrefslogtreecommitdiff
path: root/db/migrate/20160527020117_remove_notification_settings_for_deleted_projects.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20160527020117_remove_notification_settings_for_deleted_projects.rb')
-rw-r--r--db/migrate/20160527020117_remove_notification_settings_for_deleted_projects.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/db/migrate/20160527020117_remove_notification_settings_for_deleted_projects.rb b/db/migrate/20160527020117_remove_notification_settings_for_deleted_projects.rb
new file mode 100644
index 00000000000..3e26be7c09c
--- /dev/null
+++ b/db/migrate/20160527020117_remove_notification_settings_for_deleted_projects.rb
@@ -0,0 +1,14 @@
+# rubocop:disable all
+class RemoveNotificationSettingsForDeletedProjects < ActiveRecord::Migration
+ def up
+ execute <<-SQL
+ DELETE FROM notification_settings
+ WHERE notification_settings.source_type = 'Project'
+ AND NOT EXISTS (
+ SELECT *
+ FROM projects
+ WHERE projects.id = notification_settings.source_id
+ )
+ SQL
+ end
+end