aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2016-05-24 23:57:43 -0400
committerArthur Neves <arthurnn@gmail.com>2016-05-24 23:57:43 -0400
commit779ccf8a0e6a8bf7bb362c30dac4a340599ab113 (patch)
tree6ba707f5fca16144290128c4a3eb386ca6a6968c /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parent5167b8f7ffa66c8772c455916b8418844e3b4674 (diff)
downloadrails-779ccf8a0e6a8bf7bb362c30dac4a340599ab113.tar.gz
rails-779ccf8a0e6a8bf7bb362c30dac4a340599ab113.tar.bz2
rails-779ccf8a0e6a8bf7bb362c30dac4a340599ab113.zip
Remove `name` from `establish_connection`
Instead of passing a separete name variable, we can make the resolver merge a name on the config, and use that before creating the Specification.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb17
1 files changed, 7 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index c124f1c4b5..ca04058539 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -837,13 +837,9 @@ module ActiveRecord
end
alias :connection_pools :connection_pool_list
- def establish_connection(spec_or_config, name: "primary")
- if spec_or_config.is_a?(ConnectionSpecification)
- spec = spec_or_config
- else
- resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(ActiveRecord::Base.configurations)
- spec = resolver.spec(spec_or_config, name)
- end
+ def establish_connection(config)
+ resolver = ConnectionSpecification::Resolver.new(Base.configurations)
+ spec = resolver.spec(config)
remove_connection(spec.name)
owner_to_pool[spec.name] = ConnectionAdapters::ConnectionPool.new(spec)
@@ -879,9 +875,9 @@ module ActiveRecord
# for (not necessarily the current class).
def retrieve_connection(spec_name) #:nodoc:
pool = retrieve_connection_pool(spec_name)
- raise ConnectionNotEstablished, "No connection pool with id #{spec_name} found." unless pool
+ raise ConnectionNotEstablished, "No connection pool with id '#{spec_name}' found." unless pool
conn = pool.connection
- raise ConnectionNotEstablished, "No connection for #{spec_name} in connection pool" unless conn
+ raise ConnectionNotEstablished, "No connection for '#{spec_name}' in connection pool" unless conn
conn
end
@@ -915,7 +911,8 @@ module ActiveRecord
# A connection was established in an ancestor process that must have
# subsequently forked. We can't reuse the connection, but we can copy
# the specification and establish a new connection with it.
- establish_connection(ancestor_pool.spec).tap do |pool|
+ spec = ancestor_pool.spec
+ establish_connection(spec.config.merge("name" => spec.name)).tap do |pool|
pool.schema_cache = ancestor_pool.schema_cache if ancestor_pool.schema_cache
end
else