Skip to content
Snippets Groups Projects
Commit dd8713aa authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Connect to the proper database while testing Geo migrations

parent 6dd69bb1
No related branches found
No related tags found
1 merge request!80335Connect to the proper database while testing Geo migrations
......@@ -12,6 +12,6 @@ def up
end
def down
remove_column :job_artifact_registry, :missing_on_primary
remove_column :job_artifact_registry, :missing_on_primary if column_exists?(:job_artifact_registry, :missing_on_primary)
end
end
......@@ -4,7 +4,7 @@
require_migration!
RSpec.describe FixStateColumnInFileRegistry do
RSpec.describe FixStateColumnInFileRegistry, :geo do
let(:registry) { table(:file_registry) }
it 'correctly sets registry state value' do
......
......@@ -4,7 +4,7 @@
require_migration!
RSpec.describe FixStateColumnInLfsObjectRegistry do
RSpec.describe FixStateColumnInLfsObjectRegistry, :geo do
let(:registry) { table(:lfs_object_registry) }
before do
......@@ -19,12 +19,12 @@
pending_registries = registry.where(state: 0)
synced_registries = registry.where(state: 2)
expect(pending_registries.pluck(:id)).to contain_exactly(1, 2)
expect(synced_registries.pluck(:id)).to contain_exactly(4)
expect(pending_registries.pluck(:lfs_object_id)).to contain_exactly(1, 2)
expect(synced_registries.pluck(:lfs_object_id)).to contain_exactly(4)
migrate!
expect(pending_registries.pluck(:id)).to contain_exactly(1)
expect(synced_registries.pluck(:id)).to contain_exactly(2, 4)
expect(pending_registries.pluck(:lfs_object_id)).to contain_exactly(1)
expect(synced_registries.pluck(:lfs_object_id)).to contain_exactly(2, 4)
end
end
......@@ -45,12 +45,24 @@ def migrate!
def with_db_config(&block)
if geo_migration?
::Geo::TrackingBase.connected_to(database: :geo) { yield }
with_added_geo_connection { yield }
else
yield
end
end
def with_added_geo_connection
with_reestablished_active_record_base(reconnect: true) do
reconfigure_db_connection(
name: :geo,
config_model: Geo::TrackingBase,
model: ActiveRecord::Base
)
yield
end
end
def geo_migration?
self.class.metadata[:geo]
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment