change add_concurrent_index function arguments

This commit is contained in:
Felipe Artur 2016-06-06 11:30:17 -03:00
parent 8450fe3074
commit 9264203103
2 changed files with 13 additions and 10 deletions

View file

@ -11,7 +11,7 @@ module Gitlab
# add_concurrent_index :users, :some_column
#
# See Rails' `add_index` for more info on the available arguments.
def add_concurrent_index(*args)
def add_concurrent_index(table_name, column_name, options = {})
if transaction_open?
raise 'add_concurrent_index can not be run inside a transaction, ' \
'you can disable transactions by calling disable_ddl_transaction! ' \
@ -19,14 +19,10 @@ module Gitlab
end
if Database.postgresql?
if args[2].present?
args[2].merge!({ algorithm: :concurrently })
else
args << { algorithm: :concurrently }
end
options = options.merge({ algorithm: :concurrently })
end
add_index(*args)
add_index(table_name, column_name, options)
end
# Updates the value of a column in batches.

View file

@ -16,14 +16,21 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
end
context 'using PostgreSQL' do
it 'creates the index concurrently' do
expect(Gitlab::Database).to receive(:postgresql?).and_return(true)
before { expect(Gitlab::Database).to receive(:postgresql?).and_return(true) }
it 'creates the index concurrently' do
expect(model).to receive(:add_index).
with(:users, :foo, algorithm: :concurrently)
model.add_concurrent_index(:users, :foo)
end
it 'creates unique index concurrently' do
expect(model).to receive(:add_index).
with(:users, :foo, { algorithm: :concurrently, unique: true })
model.add_concurrent_index(:users, :foo, unique: true)
end
end
context 'using MySQL' do
@ -31,7 +38,7 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
expect(Gitlab::Database).to receive(:postgresql?).and_return(false)
expect(model).to receive(:add_index).
with(:users, :foo)
with(:users, :foo, {})
model.add_concurrent_index(:users, :foo)
end