summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-04-19 11:53:04 +0000
committerLin Jen-Shin <godfat@godfat.org>2017-04-19 20:31:39 +0800
commit6bec04adaef776499be4c3af468083a355d1ee47 (patch)
treed09fbe2e38c80c866da72eddbc88d121e0e45496 /db
parent002fbbe1290a0dccfb4c469ed8a65eb192ddef21 (diff)
downloadgitlab-ce-6bec04adaef776499be4c3af468083a355d1ee47.tar.gz
Merge branch 'fix/orphan-notification-settings' into 'master'
Fix orphaned notification settings Closes #29688 See merge request !10763
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20170418103908_delete_orphan_notification_settings.rb24
-rw-r--r--db/schema.rb2
2 files changed, 25 insertions, 1 deletions
diff --git a/db/migrate/20170418103908_delete_orphan_notification_settings.rb b/db/migrate/20170418103908_delete_orphan_notification_settings.rb
new file mode 100644
index 00000000000..e4b9cf65936
--- /dev/null
+++ b/db/migrate/20170418103908_delete_orphan_notification_settings.rb
@@ -0,0 +1,24 @@
+class DeleteOrphanNotificationSettings < ActiveRecord::Migration
+ DOWNTIME = false
+
+ def up
+ execute("DELETE FROM notification_settings WHERE EXISTS (SELECT true FROM (#{orphan_notification_settings}) AS ns WHERE ns.id = notification_settings.id)")
+ end
+
+ def down
+ # This is a no-op method to make the migration reversible.
+ # If someone is trying to rollback for other reasons, we should not throw an Exception.
+ # raise ActiveRecord::IrreversibleMigration
+ end
+
+ def orphan_notification_settings
+ <<-SQL
+ SELECT notification_settings.id
+ FROM notification_settings
+ LEFT OUTER JOIN namespaces
+ ON namespaces.id = notification_settings.source_id
+ WHERE notification_settings.source_type = 'Namespace'
+ AND namespaces.id IS NULL
+ SQL
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5689f7331dc..26ec6367bd0 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: 20170408033905) do
+ActiveRecord::Schema.define(version: 20170418103908) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"