From 1d83ab936672790ea3abd407df8c16d696aaef70 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Thu, 25 Jul 2019 11:35:44 -0400 Subject: Make sure AR can load without Rails In #36560 I accidentally re-introduced a bug where ActiveRecord can't be used without Rails. This returns an empty hash if we're outside the context of Rails since we can't create the database tasks without loading and reading the database yaml which is something only Railties can do. --- activerecord/lib/active_record/tasks/database_tasks.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index a78bebf764..5d1ce19829 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -154,6 +154,8 @@ module ActiveRecord end def for_each(databases) + return {} unless defined?(Rails) + database_configs = ActiveRecord::DatabaseConfigurations.new(databases).configs_for(env_name: Rails.env) # if this is a single database application we don't want tasks for each primary database -- cgit v1.2.3