summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
author🙈 jacopo beschi 🙉 <intrip@gmail.com>2018-08-02 09:34:44 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-08-02 09:34:44 +0000
commita0a36a9994fcae93da850a679e475d501442041f (patch)
tree4382966168e685c8aa7e87bd585c0a6287c5587c /db
parent1db427f91db593880c00416f0b50588613cf0dc7 (diff)
downloadgitlab-ce-a0a36a9994fcae93da850a679e475d501442041f.tar.gz
Resolve "Remove ghost notification settings for groups and projects"
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180710162338_add_foreign_key_from_notification_settings_to_users.rb30
-rw-r--r--db/schema.rb1
2 files changed, 31 insertions, 0 deletions
diff --git a/db/migrate/20180710162338_add_foreign_key_from_notification_settings_to_users.rb b/db/migrate/20180710162338_add_foreign_key_from_notification_settings_to_users.rb
new file mode 100644
index 00000000000..91656f194e5
--- /dev/null
+++ b/db/migrate/20180710162338_add_foreign_key_from_notification_settings_to_users.rb
@@ -0,0 +1,30 @@
+class AddForeignKeyFromNotificationSettingsToUsers < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ class NotificationSetting < ActiveRecord::Base
+ self.table_name = 'notification_settings'
+
+ include EachBatch
+ end
+
+ class User < ActiveRecord::Base
+ self.table_name = 'users'
+ end
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ NotificationSetting.each_batch(of: 1000) do |batch|
+ batch.where('NOT EXISTS (?)', User.select(1).where('users.id = notification_settings.user_id'))
+ .delete_all
+ end
+
+ add_concurrent_foreign_key(:notification_settings, :users, column: :user_id, on_delete: :cascade)
+ end
+
+ def down
+ remove_foreign_key(:notification_settings, column: :user_id)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 769baa825a5..2bef2971f29 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -2350,6 +2350,7 @@ ActiveRecord::Schema.define(version: 20180726172057) do
add_foreign_key "milestones", "projects", name: "fk_9bd0a0c791", on_delete: :cascade
add_foreign_key "note_diff_files", "notes", column: "diff_note_id", on_delete: :cascade
add_foreign_key "notes", "projects", name: "fk_99e097b079", on_delete: :cascade
+ add_foreign_key "notification_settings", "users", name: "fk_0c95e91db7", on_delete: :cascade
add_foreign_key "oauth_openid_requests", "oauth_access_grants", column: "access_grant_id", name: "fk_oauth_openid_requests_oauth_access_grants_access_grant_id"
add_foreign_key "pages_domains", "projects", name: "fk_ea2f6dfc6f", on_delete: :cascade
add_foreign_key "personal_access_tokens", "users"