diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-31 21:36:28 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-17 20:10:12 +0300 |
commit | bde0202693508aa9eb3ce76876b1c64120d51ef3 (patch) | |
tree | e7844d9b4f3756bfdaa84a4ef334990f49bd5781 /db/migrate/20161031181638_add_unique_index_to_subscriptions.rb | |
parent | 731946bad2df5b2b369db53d965061d71bf6be77 (diff) |
Add unique index to subscriptions on subscribable and user and project
Diffstat (limited to 'db/migrate/20161031181638_add_unique_index_to_subscriptions.rb')
-rw-r--r-- | db/migrate/20161031181638_add_unique_index_to_subscriptions.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/db/migrate/20161031181638_add_unique_index_to_subscriptions.rb b/db/migrate/20161031181638_add_unique_index_to_subscriptions.rb new file mode 100644 index 00000000000..4b1b29e1265 --- /dev/null +++ b/db/migrate/20161031181638_add_unique_index_to_subscriptions.rb @@ -0,0 +1,18 @@ +class AddUniqueIndexToSubscriptions < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = true + DOWNTIME_REASON = 'This migration requires downtime because it changes a column to not accept null values.' + + disable_ddl_transaction! + + def up + add_concurrent_index :subscriptions, [:subscribable_id, :subscribable_type, :user_id, :project_id], { unique: true, name: 'index_subscriptions_on_subscribable_and_user_id_and_project_id' } + remove_index :subscriptions, name: 'subscriptions_user_id_and_ref_fields' if index_name_exists?(:subscriptions, 'subscriptions_user_id_and_ref_fields', false) + end + + def down + add_concurrent_index :subscriptions, [:subscribable_id, :subscribable_type, :user_id], { unique: true, name: 'subscriptions_user_id_and_ref_fields' } + remove_index :subscriptions, name: 'index_subscriptions_on_subscribable_and_user_id_and_project_id' if index_name_exists?(:subscriptions, 'index_subscriptions_on_subscribable_and_user_id_and_project_id', false) + end +end |