Skip to content

Commit

Permalink
Merge pull request #34969 from eileencodes/fix-error-message-for-mult…
Browse files Browse the repository at this point in the history
…i-db-apps

Fix error message when adapter is not specified
  • Loading branch information
eileencodes committed Jan 18, 2019
2 parents 5b6daff + 83b9952 commit 7235e84
Showing 1 changed file with 20 additions and 1 deletion.
Expand Up @@ -248,10 +248,29 @@ def resolve_symbol_connection(env_name, pool_name)
if db_config
resolve_connection(db_config.config).merge("name" => pool_name.to_s)
else
raise(AdapterNotSpecified, "'#{env_name}' database is not configured. Available: #{configurations.configurations.map(&:env_name).join(", ")}")
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

def build_configuration_sentence # :nodoc:
configs = configurations.configs_for(include_replicas: true)

configs.group_by(&:env_name).map do |env, config|
namespaces = config.map(&:spec_name)
if namespaces.size > 1
"#{env}: #{namespaces.join(", ")}"
else
env
end
end.join("\n")
end

# Accepts a hash. Expands the "url" key that contains a
# URL database connection to a full connection
# hash and merges with the rest of the hash.
Expand Down

0 comments on commit 7235e84

Please sign in to comment.