From cd148be07298e298bb84f5df7b973f2b188830ee Mon Sep 17 00:00:00 2001 From: eileencodes Date: Wed, 31 Jul 2019 12:22:01 -0400 Subject: Fix db:seed The `rake db:seed` command was broken for the primary environment if the application is using multiple databases. We never implemented `rake db:seed` for other databases (coming soon), but that shouldn't break the default case. The reason this was broken was because `abort_if_pending_migrations` would loop through the configs for all databases and check for migrations but would leave the last established connection. So `db:seed` was looking in the wrong database for the table to seed. This PR doesn't fix the fact that `db:seed` doesn't work for multiple databases but does fix the default case. Fixes #36817 Co-authored-by: John Crepezzi --- activerecord/lib/active_record/railties/databases.rake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 4d9acc911b..d699e2e21b 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -265,6 +265,8 @@ db_namespace = namespace :db do end abort %{Run `rails db:migrate` to update your database then try again.} end + ensure + ActiveRecord::Base.establish_connection(ActiveRecord::Tasks::DatabaseTasks.env.to_sym) end namespace :abort_if_pending_migrations do -- cgit v1.2.3