Commit 20a758a7 authored by pbair's avatar pbair Committed by Krasimir Angelov

ReplaceTable helper should be passed a connection

Update the `ReplaceTable` helper to accept an external database
connection rather than relying directly on
`ActiveRecord::Base.connection`
parent 24b5a5d4
...@@ -2445,7 +2445,6 @@ Database/MultipleDatabases: ...@@ -2445,7 +2445,6 @@ Database/MultipleDatabases:
- 'lib/gitlab/database/migrations/observers/query_log.rb' - 'lib/gitlab/database/migrations/observers/query_log.rb'
- 'lib/gitlab/database/multi_threaded_migration.rb' - 'lib/gitlab/database/multi_threaded_migration.rb'
- 'lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb' - 'lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb'
- 'lib/gitlab/database/partitioning/replace_table.rb'
- 'lib/gitlab/database/postgres_hll/batch_distinct_counter.rb' - 'lib/gitlab/database/postgres_hll/batch_distinct_counter.rb'
- 'lib/gitlab/database/postgresql_adapter/dump_schema_versions_mixin.rb' - 'lib/gitlab/database/postgresql_adapter/dump_schema_versions_mixin.rb'
- 'lib/gitlab/database/postgresql_database_tasks/load_schema_versions_mixin.rb' - 'lib/gitlab/database/postgresql_database_tasks/load_schema_versions_mixin.rb'
......
...@@ -9,7 +9,8 @@ module Gitlab ...@@ -9,7 +9,8 @@ module Gitlab
attr_reader :original_table, :replacement_table, :replaced_table, :primary_key_column, attr_reader :original_table, :replacement_table, :replaced_table, :primary_key_column,
:sequence, :original_primary_key, :replacement_primary_key, :replaced_primary_key :sequence, :original_primary_key, :replacement_primary_key, :replaced_primary_key
def initialize(original_table, replacement_table, replaced_table, primary_key_column) def initialize(connection, original_table, replacement_table, replaced_table, primary_key_column)
@connection = connection
@original_table = original_table @original_table = original_table
@replacement_table = replacement_table @replacement_table = replacement_table
@replaced_table = replaced_table @replaced_table = replaced_table
...@@ -29,10 +30,8 @@ module Gitlab ...@@ -29,10 +30,8 @@ module Gitlab
private private
attr_reader :connection
delegate :execute, :quote_table_name, :quote_column_name, to: :connection delegate :execute, :quote_table_name, :quote_column_name, to: :connection
def connection
@connection ||= ActiveRecord::Base.connection
end
def default_sequence(table, column) def default_sequence(table, column)
"#{table}_#{column}_seq" "#{table}_#{column}_seq"
......
...@@ -428,8 +428,8 @@ module Gitlab ...@@ -428,8 +428,8 @@ module Gitlab
end end
def replace_table(original_table_name, replacement_table_name, replaced_table_name, primary_key_name) def replace_table(original_table_name, replacement_table_name, replaced_table_name, primary_key_name)
replace_table = Gitlab::Database::Partitioning::ReplaceTable.new(original_table_name.to_s, replace_table = Gitlab::Database::Partitioning::ReplaceTable.new(connection,
replacement_table_name, replaced_table_name, primary_key_name) original_table_name.to_s, replacement_table_name, replaced_table_name, primary_key_name)
transaction do transaction do
drop_sync_trigger(original_table_name) drop_sync_trigger(original_table_name)
......
...@@ -5,7 +5,9 @@ require 'spec_helper' ...@@ -5,7 +5,9 @@ require 'spec_helper'
RSpec.describe Gitlab::Database::Partitioning::ReplaceTable, '#perform' do RSpec.describe Gitlab::Database::Partitioning::ReplaceTable, '#perform' do
include Database::TableSchemaHelpers include Database::TableSchemaHelpers
subject(:replace_table) { described_class.new(original_table, replacement_table, archived_table, 'id').perform } subject(:replace_table) do
described_class.new(connection, original_table, replacement_table, archived_table, 'id').perform
end
let(:original_table) { '_test_original_table' } let(:original_table) { '_test_original_table' }
let(:replacement_table) { '_test_replacement_table' } let(:replacement_table) { '_test_replacement_table' }
......
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