Skip to content

Commit

Permalink
Fetch adapter from database configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
xjunior committed Jul 23, 2024
1 parent 3cc5f29 commit 3a84e1b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
7 changes: 6 additions & 1 deletion lib/active_record/connection_adapters/percona_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def percona_connection(config)
config = config.dup if config.frozen?
config[:username] = 'root'
end
connection = send("#{Departure.configuration.adapter}_connection", config)
adapter = config[:adapter]
connection = if Departure::SUPPORTED_ADAPTERS.include?(adapter)
send("#{adapter}_connection", config)
else
raise ArgumentError, "Supported Departure adapters are #{Departure::SUPPORTED_ADAPTERS.inspect}"
end

connection_details = Departure::ConnectionDetails.new(config)
verbose = ActiveRecord::Migration.verbose
Expand Down
2 changes: 2 additions & 0 deletions lib/departure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
end

module Departure
SUPPORTED_ADAPTERS = %i[trilogy mysql2].freeze

class << self
attr_accessor :configuration
end
Expand Down
11 changes: 0 additions & 11 deletions lib/departure/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module Departure
class Configuration
SUPPORTED_ADAPTERS = %i[trilogy mysql2].freeze

attr_accessor :tmp_path, :global_percona_args, :enabled_by_default, :redirect_stderr
attr_reader :adapter

def initialize
@tmp_path = '.'.freeze
Expand All @@ -18,14 +15,6 @@ def error_log_path
File.join(tmp_path, error_log_filename)
end

def adapter=(name)
unless SUPPORTED_ADAPTERS.include?(name)
raise ArgumentError, "Supported Departure adapters are #{SUPPORTED_ADAPTERS.inspect}"
end

@adapter = name
end

private

attr_reader :error_log_filename
Expand Down

0 comments on commit 3a84e1b

Please sign in to comment.