From 7b4fdf3ce7eec995f6b285183ff1b50389776da0 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Thu, 4 Jun 2020 15:03:40 -0400 Subject: [PATCH] Remove assumption that a primary config exists Applications may not have a primary configuration so we should not assume there is one. In both these cases we can get the right connection without that. For the databases.rake file we want to re-establish a connection for the environment we're in. The first config defined under an environment for a multi-db app will win. This is already the case on application boot so we should be consistent. For the info.rb file we already have a connection so we can lookup the adapter from the connection's db_config. If a primary hadn't existed this would have thrown an exception. Followup to https://github.com/rails/rails/pull/39535 which removed the assumption there was a primary config from the schema cache load railtie. Co-authored-by: John Crepezzi --- activerecord/lib/active_record/railties/databases.rake | 2 +- railties/lib/rails/info.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 6cf8c0e136..3835c8a114 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -563,7 +563,7 @@ db_namespace = namespace :db do end ensure if should_reconnect - ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: "primary")) + ActiveRecord::Base.establish_connection(ActiveRecord::Tasks::DatabaseTasks.env.to_sym) end end diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index 0b7f7ae89f..e68cc0994e 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -95,7 +95,7 @@ module Rails # The name of the database adapter for the current environment. property "Database adapter" do - ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").adapter + ActiveRecord::Base.connection.pool.db_config.adapter end property "Database schema version" do