Skip to content

Commit

Permalink
Extract connection method to percona
Browse files Browse the repository at this point in the history
  • Loading branch information
xjunior committed Jul 23, 2024
1 parent ec6e0ea commit 2a965f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 3 additions & 15 deletions lib/active_record/connection_adapters/percona_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ def percona_connection(config)
config[:username] = 'root'
end
adapter = config[:original_adapter]
connection = if Departure::SUPPORTED_ADAPTERS.include?(adapter)
send("#{adapter}_connection", config)
else
raise ArgumentError, "Unsupported adater #{adapter}. Supported Departure " \
"adapters are #{Departure::SUPPORTED_ADAPTERS.inspect}"
end
connection = send(Departure.connection_method(adapter), config)

connection_details = Departure::ConnectionDetails.new(config)
verbose = ActiveRecord::Migration.verbose
Expand All @@ -28,19 +23,12 @@ def percona_connection(config)
]
percona_logger = Departure::LoggerFactory.build(sanitizers: sanitizers, verbose: verbose)
cli_generator = Departure::CliGenerator.new(connection_details)

runner = Departure::Runner.new(
percona_logger,
cli_generator,
connection
)

connection_options = { mysql_adapter: connection }
runner = Departure::Runner.new(percona_logger, cli_generator, connection)

ConnectionAdapters::DepartureAdapter.new(
runner,
logger,
connection_options,
{ mysql_adapter: connection },
config
)
end
Expand Down
12 changes: 12 additions & 0 deletions lib/departure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ module Departure

class << self
attr_accessor :configuration

def connection_method(adapter)
return "#{adapter}_connection" if Departure::SUPPORTED_ADAPTERS.include?(adapter)

if adapter.blank?
raise ArgumentError, 'You must supply the original_adapter when connecting ' \
"using the percona adapter. Supported adapters: #{SUPPORTED_ADAPTERS}"
end

raise ArgumentError, "Unsupported adater #{adapter}. Supported Departure " \
"adapters are #{Departure::SUPPORTED_ADAPTERS.inspect}"
end
end

def self.configure
Expand Down

0 comments on commit 2a965f3

Please sign in to comment.