aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2019-01-18 07:53:26 -0500
committerGitHub <noreply@github.com>2019-01-18 07:53:26 -0500
commit7235e8493571d2f4a78f70eb8f32d4ae06bfa713 (patch)
treeab14452b80022974d039a1e452ed46f1eb2b2f49 /activerecord
parent5b6daff5b6d5439e07c058718069f54b34970f93 (diff)
parent83b995206a569d8d08b697ee9f86a64ca1854bcc (diff)
downloadrails-7235e8493571d2f4a78f70eb8f32d4ae06bfa713.tar.gz
rails-7235e8493571d2f4a78f70eb8f32d4ae06bfa713.tar.bz2
rails-7235e8493571d2f4a78f70eb8f32d4ae06bfa713.zip
Merge pull request #34969 from eileencodes/fix-error-message-for-multi-db-apps
Fix error message when adapter is not specified
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/connection_specification.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
index f60d8469cc..9eaf9d9a89 100644
--- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
@@ -248,10 +248,29 @@ module ActiveRecord
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.