debian-mirror-gitlab/db/migrate/20161031181638_add_unique_index_to_subscriptions.rb

20 lines
1 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
# rubocop:disable RemoveIndex
2019-02-15 15:39:39 +05:30
class AddUniqueIndexToSubscriptions < ActiveRecord::Migration[4.2]
2017-08-17 22:00:37 +05:30
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' }
2019-07-31 22:56:46 +05:30
remove_index :subscriptions, name: 'subscriptions_user_id_and_ref_fields' if index_name_exists?(:subscriptions, 'subscriptions_user_id_and_ref_fields')
2017-08-17 22:00:37 +05:30
end
def down
add_concurrent_index :subscriptions, [:subscribable_id, :subscribable_type, :user_id], { unique: true, name: 'subscriptions_user_id_and_ref_fields' }
2019-07-31 22:56:46 +05:30
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')
2017-08-17 22:00:37 +05:30
end
end