Permalink
Browse files

Change a way ActiveRecord's config is prepared for rake tasks

In commit d1d7c86 I moved setting migrations paths into activerecord's
railtie to remove Rails dependency on databases.rake. However, it
introduced a regression, ENGINE_PATH was not available at the moment, so
engine's migrations where not added properly to paths. Fix was added
at 97a4a77, but it changes a way things work from using ENGINE_PATH to
APP_RAKEFILE. Additionally, the config runs when the code loads, while
previously it ran in the db:load_config rake task

In order to make it more in pair with original version this commit
changes the config to run only on load_config task. This code uses the
fact that defining a task in rake does not overwrite, but only appends.

It also allows to get back to checking for ENGINE_PATH
  • Loading branch information...
1 parent e1f4f64 commit 84fd0aada42c01abf40424fea5b32df64c597d97 @drogus drogus committed Jun 21, 2013
Showing with 14 additions and 10 deletions.
  1. +14 −10 activerecord/lib/active_record/railtie.rb
@@ -37,16 +37,20 @@ class Railtie < Rails::Railtie # :nodoc:
rake_tasks do
require "active_record/base"
- ActiveRecord::Tasks::DatabaseTasks.env = Rails.env
- ActiveRecord::Tasks::DatabaseTasks.db_dir = Rails.application.config.paths["db"].first
- ActiveRecord::Tasks::DatabaseTasks.seed_loader = Rails.application
- ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths['db/migrate'].to_a
- ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures'
-
- if defined?(APP_RAKEFILE) && engine = Rails::Engine.find(find_engine_path(APP_RAKEFILE))
- if engine.paths['db/migrate'].existent
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths += engine.paths['db/migrate'].to_a
+ namespace :db do
+ task :load_config do
+ ActiveRecord::Tasks::DatabaseTasks.env = Rails.env
+ ActiveRecord::Tasks::DatabaseTasks.db_dir = Rails.application.config.paths["db"].first
+ ActiveRecord::Tasks::DatabaseTasks.seed_loader = Rails.application
+ ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths['db/migrate'].to_a
+ ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures'
+
+ if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
+ if engine.paths['db/migrate'].existent
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths += engine.paths['db/migrate'].to_a
+ end
+ end
end
end

0 comments on commit 84fd0aa

Please sign in to comment.