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 2555087
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 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
12 changes: 0 additions & 12 deletions lib/departure/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
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
@error_log_filename = 'departure_error.log'.freeze
@global_percona_args = nil
@enabled_by_default = true
@redirect_stderr = true
@adapter = :mysql2
end

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 2555087

Please sign in to comment.