Commit 0f652393 authored by Thong Kuah's avatar Thong Kuah Committed by Dylan Griffith

Fix loose foreign key test to use right connection

Similar to what we did in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75511 we need to
ensure the right connection is being used around anywhere we interact
with the `LooseForeignKeys::DeletedRecord` table. This spec was
otherwise failing when using 2 databases because the it was choosing the
wrong database to load the `LooseForeignKeys::DeletedRecord` from and
this meant that it did not find anything.
parent dad714c5
......@@ -7,6 +7,12 @@ RSpec.shared_examples 'it has loose foreign keys' do
let(:fully_qualified_table_name) { "#{connection.current_schema}.#{table_name}" }
let(:deleted_records) { LooseForeignKeys::DeletedRecord.where(fully_qualified_table_name: fully_qualified_table_name) }
around do |example|
LooseForeignKeys::DeletedRecord.using_connection(connection) do
example.run
end
end
it 'has at least one loose foreign key definition' do
definitions = Gitlab::Database::LooseForeignKeys.definitions_by_table[table_name]
expect(definitions.size).to be > 0
......@@ -69,7 +75,9 @@ RSpec.shared_examples 'cleanup by a loose foreign key' do
expect(find_model).to be_present
LooseForeignKeys::ProcessDeletedRecordsService.new(connection: model.connection).execute
LooseForeignKeys::DeletedRecord.using_connection(parent.connection) do
LooseForeignKeys::ProcessDeletedRecordsService.new(connection: parent.connection).execute
end
if foreign_key_definition.on_delete.eql?(:async_delete)
expect(find_model).not_to be_present
......
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