Skip to content

Commit

Permalink
Completely bypass `ConnectionAdapters::ConnectionSpecification::Resol…
Browse files Browse the repository at this point in the history
…ver`.
  • Loading branch information
ioquatix committed Mar 19, 2019
1 parent 5d6562d commit a0dc900
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/active_record/configurations.rb
Expand Up @@ -32,11 +32,11 @@ def self.establish_connection(config = nil)
config ||= DEFAULT_ENV.call.to_sym
spec_name = self == Base ? "primary" : name
self.connection_specification_name = spec_name

resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(self.configurations)
spec = resolver.resolve(config).symbolize_keys
spec = self.configurations.fetch(config.to_s, config).symbolize_keys

spec[:name] = spec_name

connection_handler.establish_connection(spec)
end
end
Expand Down Expand Up @@ -150,4 +150,24 @@ def configure(name, parent: :default, **options, &block)
self.configurations[name.to_s] = configuration.stringify_keys
end
end

module ConnectionAdapters
class ConnectionSpecification
def resolve_symbol_connection(env_name, pool_name)
db_config = configurations.find_db_config(env_name)

if db_config
resolve_connection(db_config.config).merge("name" => pool_name.to_s)
else
raise AdapterNotSpecified, <<~MSG
The `#{env_name}` database is not configured for the `#{ActiveRecord::ConnectionHandling::DEFAULT_ENV.call}` environment.
Available databases configurations are:
#{build_configuration_sentence}
MSG
end
end
end
end
end

0 comments on commit a0dc900

Please sign in to comment.