未验证 提交 ff42b219 编写于 作者: W Will Jessop

When DATABASE_URL is specified don't trample envs that use a url: key

fixes #36610
上级 7729dfc6
...@@ -153,11 +153,11 @@ def build_db_config_from_hash(env_name, spec_name, config) ...@@ -153,11 +153,11 @@ def build_db_config_from_hash(env_name, spec_name, config)
def build_url_config(url, configs) def build_url_config(url, configs)
env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_s env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_s
if original_config = configs.find(&:for_current_env?) if configs.find(&:for_current_env?)
if original_config.url_config? configs.map do |config|
configs if config.url_config?
else config
configs.map do |config| else
ActiveRecord::DatabaseConfigurations::UrlConfig.new(config.env_name, config.spec_name, url, config.config) ActiveRecord::DatabaseConfigurations::UrlConfig.new(config.env_name, config.spec_name, url, config.config)
end end
end end
......
...@@ -244,6 +244,25 @@ def test_url_sub_key_with_database_url ...@@ -244,6 +244,25 @@ def test_url_sub_key_with_database_url
assert_equal expected, actual assert_equal expected, actual
end end
def test_no_url_sub_key_with_database_url_doesnt_trample_other_envs
ENV["DATABASE_URL"] = "postgres://localhost/baz"
config = { "default_env" => { "database" => "foo" }, "other_env" => { "url" => "postgres://foohost/bardb" } }
actual = resolve_config(config)
expected = { "default_env" =>
{ "database" => "baz",
"adapter" => "postgresql",
"host" => "localhost"
},
"other_env" =>
{ "adapter" => "postgresql",
"database" => "bardb",
"host" => "foohost"
}
}
assert_equal expected, actual
end
def test_merge_no_conflicts_with_database_url def test_merge_no_conflicts_with_database_url
ENV["DATABASE_URL"] = "postgres://localhost/foo" ENV["DATABASE_URL"] = "postgres://localhost/foo"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册