aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/tasks
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2019-04-18 14:06:37 -0400
committereileencodes <eileencodes@gmail.com>2019-04-18 14:06:37 -0400
commit456c3f10563402cab1f4a2f4e541bd3d053a5caf (patch)
tree572297d51c2340be00db3bca8ecc7f71637b798c /activerecord/lib/active_record/tasks
parent0f39a7488ed736a76cc6cee166fba01d1e3c5686 (diff)
downloadrails-456c3f10563402cab1f4a2f4e541bd3d053a5caf.tar.gz
rails-456c3f10563402cab1f4a2f4e541bd3d053a5caf.tar.bz2
rails-456c3f10563402cab1f4a2f4e541bd3d053a5caf.zip
Ensure active record can load without Railties
When I added the rake tasks for multiple databases I accidentally made it so you couldn't use Active Record without Railties. Since getting the database configuration depends on being able to load Railties (there is no other way to read and parse the yaml file and load it) I've decided that using multiple databases outside of Rails is a no-op. I've changed the code here to return if Rails isn't defined. Then I changed the other tasks to use `ActiveRecord::Tasks::DatabaseTasks.env` instead of `Rails.env`. The multi-db tasks can keep using `Rails.env` because they'll only be generated if we're using Rails and not just Active Record.
Diffstat (limited to 'activerecord/lib/active_record/tasks')
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 7285c15477..53e7e1e6d7 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -142,6 +142,8 @@ module ActiveRecord
end
def for_each
+ return {} unless defined?(Rails)
+
databases = Rails.application.config.load_database_yaml
database_configs = ActiveRecord::DatabaseConfigurations.new(databases).configs_for(env_name: Rails.env)