mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #40048 from eileencodes/fix-incorrect-removal-of-current_shard-from-establish_connection
Fix incorrect removal of current_shard in establish_connection
This commit is contained in:
commit
a22df78626
2 changed files with 11 additions and 1 deletions
|
@ -49,7 +49,7 @@ module ActiveRecord
|
||||||
def establish_connection(config_or_env = nil)
|
def establish_connection(config_or_env = nil)
|
||||||
config_or_env ||= DEFAULT_ENV.call.to_sym
|
config_or_env ||= DEFAULT_ENV.call.to_sym
|
||||||
db_config, owner_name = resolve_config_for_connection(config_or_env)
|
db_config, owner_name = resolve_config_for_connection(config_or_env)
|
||||||
connection_handler.establish_connection(db_config, owner_name: owner_name)
|
connection_handler.establish_connection(db_config, owner_name: owner_name, shard: current_shard)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Connects a model to the databases specified. The +database+ keyword
|
# Connects a model to the databases specified. The +database+ keyword
|
||||||
|
|
|
@ -25,6 +25,16 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
unless in_memory_db?
|
unless in_memory_db?
|
||||||
|
def test_establishing_a_connection_in_connected_to_block_uses_current_role_and_shard
|
||||||
|
ActiveRecord::Base.connected_to(shard: :shard_one) do
|
||||||
|
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
|
||||||
|
ActiveRecord::Base.establish_connection(db_config)
|
||||||
|
assert_nothing_raised { Person.first }
|
||||||
|
|
||||||
|
assert_equal [:default, :shard_one], ActiveRecord::Base.connection_handlers[:writing].send(:owner_to_pool_manager).fetch("ActiveRecord::Base").instance_variable_get(:@name_to_pool_config).keys
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_establish_connection_using_3_levels_config
|
def test_establish_connection_using_3_levels_config
|
||||||
previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env"
|
previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue