diff --git a/lib/active_record/configurations.rb b/lib/active_record/configurations.rb index 9845699..54e2caa 100644 --- a/lib/active_record/configurations.rb +++ b/lib/active_record/configurations.rb @@ -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 @@ -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