Commit d6ecc99d authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '354776-remove-database-async-index-creation-ff-from-migration-helpers' into 'master'

Remove `database_async_index_creation` feature flag check from migration helpers

See merge request gitlab-org/gitlab!82565
parents ac1c2533 f296a13d
...@@ -72,8 +72,7 @@ module Gitlab ...@@ -72,8 +72,7 @@ module Gitlab
end end
def async_index_creation_available? def async_index_creation_available?
ApplicationRecord.connection.table_exists?(:postgres_async_indexes) && connection.table_exists?(:postgres_async_indexes)
Feature.enabled?(:database_async_index_creation, type: :ops)
end end
end end
end end
......
...@@ -16,45 +16,29 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do ...@@ -16,45 +16,29 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do
describe '#unprepare_async_index' do describe '#unprepare_async_index' do
let!(:async_index) { create(:postgres_async_index, name: index_name) } let!(:async_index) { create(:postgres_async_index, name: index_name) }
context 'when the flag is enabled' do it 'destroys the record' do
before do expect do
stub_feature_flags(database_async_index_creation: true) migration.unprepare_async_index(table_name, 'id')
end end.to change { index_model.where(name: index_name).count }.by(-1)
end
context 'when an explicit name is given' do
let(:index_name) { 'my_test_async_index' }
it 'destroys the record' do it 'destroys the record' do
expect do expect do
migration.unprepare_async_index(table_name, 'id') migration.unprepare_async_index(table_name, 'id', name: index_name)
end.to change { index_model.where(name: index_name).count }.by(-1) end.to change { index_model.where(name: index_name).count }.by(-1)
end end
context 'when an explicit name is given' do
let(:index_name) { 'my_test_async_index' }
it 'destroys the record' do
expect do
migration.unprepare_async_index(table_name, 'id', name: index_name)
end.to change { index_model.where(name: index_name).count }.by(-1)
end
end
context 'when the async index table does not exist' do
it 'does not raise an error' do
connection.drop_table(:postgres_async_indexes)
expect(index_model).not_to receive(:find_by)
expect { migration.unprepare_async_index(table_name, 'id') }.not_to raise_error
end
end
end end
context 'when the feature flag is disabled' do context 'when the async index table does not exist' do
it 'does not destroy the record' do it 'does not raise an error' do
stub_feature_flags(database_async_index_creation: false) connection.drop_table(:postgres_async_indexes)
expect do expect(index_model).not_to receive(:find_by)
migration.unprepare_async_index(table_name, 'id')
end.not_to change { index_model.where(name: index_name).count } expect { migration.unprepare_async_index(table_name, 'id') }.not_to raise_error
end end
end end
end end
...@@ -63,35 +47,19 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do ...@@ -63,35 +47,19 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do
let(:index_name) { "index_#{table_name}_on_id" } let(:index_name) { "index_#{table_name}_on_id" }
let!(:async_index) { create(:postgres_async_index, name: index_name) } let!(:async_index) { create(:postgres_async_index, name: index_name) }
context 'when the flag is enabled' do it 'destroys the record' do
before do expect do
stub_feature_flags(database_async_index_creation: true) migration.unprepare_async_index_by_name(table_name, index_name)
end end.to change { index_model.where(name: index_name).count }.by(-1)
it 'destroys the record' do
expect do
migration.unprepare_async_index_by_name(table_name, index_name)
end.to change { index_model.where(name: index_name).count }.by(-1)
end
context 'when the async index table does not exist' do
it 'does not raise an error' do
connection.drop_table(:postgres_async_indexes)
expect(index_model).not_to receive(:find_by)
expect { migration.unprepare_async_index_by_name(table_name, index_name) }.not_to raise_error
end
end
end end
context 'when the feature flag is disabled' do context 'when the async index table does not exist' do
it 'does not destroy the record' do it 'does not raise an error' do
stub_feature_flags(database_async_index_creation: false) connection.drop_table(:postgres_async_indexes)
expect do expect(index_model).not_to receive(:find_by)
migration.unprepare_async_index_by_name(table_name, index_name)
end.not_to change { index_model.where(name: index_name).count } expect { migration.unprepare_async_index_by_name(table_name, index_name) }.not_to raise_error
end end
end end
end end
...@@ -101,14 +69,23 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do ...@@ -101,14 +69,23 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do
connection.create_table(table_name) connection.create_table(table_name)
end end
context 'when the feature flag is enabled' do it 'creates the record for the async index' do
before do expect do
stub_feature_flags(database_async_index_creation: true) migration.prepare_async_index(table_name, 'id')
end end.to change { index_model.where(name: index_name).count }.by(1)
record = index_model.find_by(name: index_name)
it 'creates the record for the async index' do expect(record.table_name).to eq(table_name)
expect(record.definition).to match(/CREATE INDEX CONCURRENTLY "#{index_name}"/)
end
context 'when an explicit name is given' do
let(:index_name) { 'my_async_index_name' }
it 'creates the record with the given name' do
expect do expect do
migration.prepare_async_index(table_name, 'id') migration.prepare_async_index(table_name, 'id', name: index_name)
end.to change { index_model.where(name: index_name).count }.by(1) end.to change { index_model.where(name: index_name).count }.by(1)
record = index_model.find_by(name: index_name) record = index_model.find_by(name: index_name)
...@@ -116,77 +93,52 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do ...@@ -116,77 +93,52 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers do
expect(record.table_name).to eq(table_name) expect(record.table_name).to eq(table_name)
expect(record.definition).to match(/CREATE INDEX CONCURRENTLY "#{index_name}"/) expect(record.definition).to match(/CREATE INDEX CONCURRENTLY "#{index_name}"/)
end end
end
context 'when an explicit name is given' do context 'when the index already exists' do
let(:index_name) { 'my_async_index_name' } it 'does not create the record' do
connection.add_index(table_name, 'id', name: index_name)
it 'creates the record with the given name' do
expect do
migration.prepare_async_index(table_name, 'id', name: index_name)
end.to change { index_model.where(name: index_name).count }.by(1)
record = index_model.find_by(name: index_name)
expect(record.table_name).to eq(table_name) expect do
expect(record.definition).to match(/CREATE INDEX CONCURRENTLY "#{index_name}"/) migration.prepare_async_index(table_name, 'id')
end end.not_to change { index_model.where(name: index_name).count }
end end
end
context 'when the index already exists' do context 'when the record already exists' do
it 'does not create the record' do it 'does attempt to create the record' do
connection.add_index(table_name, 'id', name: index_name) create(:postgres_async_index, table_name: table_name, name: index_name)
expect do expect do
migration.prepare_async_index(table_name, 'id') migration.prepare_async_index(table_name, 'id')
end.not_to change { index_model.where(name: index_name).count } end.not_to change { index_model.where(name: index_name).count }
end
end end
context 'when the record already exists' do it 'updates definition if changed' do
it 'does attempt to create the record' do index = create(:postgres_async_index, table_name: table_name, name: index_name, definition: '...')
create(:postgres_async_index, table_name: table_name, name: index_name)
expect do
migration.prepare_async_index(table_name, 'id')
end.not_to change { index_model.where(name: index_name).count }
end
it 'updates definition if changed' do
index = create(:postgres_async_index, table_name: table_name, name: index_name, definition: '...')
expect do
migration.prepare_async_index(table_name, 'id', name: index_name)
end.to change { index.reload.definition }
end
it 'does not update definition if not changed' do expect do
definition = "CREATE INDEX CONCURRENTLY \"index_#{table_name}_on_id\" ON \"#{table_name}\" (\"id\")" migration.prepare_async_index(table_name, 'id', name: index_name)
index = create(:postgres_async_index, table_name: table_name, name: index_name, definition: definition) end.to change { index.reload.definition }
expect do
migration.prepare_async_index(table_name, 'id', name: index_name)
end.not_to change { index.reload.updated_at }
end
end end
context 'when the async index table does not exist' do it 'does not update definition if not changed' do
it 'does not raise an error' do definition = "CREATE INDEX CONCURRENTLY \"index_#{table_name}_on_id\" ON \"#{table_name}\" (\"id\")"
connection.drop_table(:postgres_async_indexes) index = create(:postgres_async_index, table_name: table_name, name: index_name, definition: definition)
expect(index_model).not_to receive(:safe_find_or_create_by!)
expect { migration.prepare_async_index(table_name, 'id') }.not_to raise_error expect do
end migration.prepare_async_index(table_name, 'id', name: index_name)
end.not_to change { index.reload.updated_at }
end end
end end
context 'when the feature flag is disabled' do context 'when the async index table does not exist' do
it 'does not create the record' do it 'does not raise an error' do
stub_feature_flags(database_async_index_creation: false) connection.drop_table(:postgres_async_indexes)
expect do expect(index_model).not_to receive(:safe_find_or_create_by!)
migration.prepare_async_index(table_name, 'id')
end.not_to change { index_model.where(name: index_name).count } expect { migration.prepare_async_index(table_name, 'id') }.not_to raise_error
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment