#lib/tasks/db.rake
namespace :db do
namespace :test do
desc "Overridden version of rails' standard db:test :prepare task since the schema dump used in that can't handle DB enums"
task :prepare => [:environment] do
puts "doing db:structure:dump"
Rake: :Task['db:structure:dump'].invoke
puts "doing db:test:clone_structure"
Rake::Task['db:test:clone_structure'].invoke
end
end
end
I got the behavior of the standard task. If I change the name of the task to: prepare2 and then execute rake db:test:prepare2, then it works. The natural conclusion I draw from this is that my rake task was defined before the built-in Rails, so my standard was overwritten: preparation task.
Can anyone see how I can solve this problem? I would rather overwrite it than use a new task. Thank you, at most
If you want to redefine the task, you need to clear the original task first:
Rake::Task["db:test:prepare"].clear
Note that once the task is executed in rake, it will not be executed again even if it is called again, This is also useful. This is by design, but you can call .reset on the task to allow it to run again.
I have a Rails 2.2 project and I want to Which covers the function of rake db: test: prepare task. I think this will work, but it does not:
#lib/tasks/db.rake
namespace :db do
namespace :test do
desc "Overridden version of rails' standard db:test:prepare task since the schema dump used in that can't handle DB enums"
task :prepare => [:environment] do
puts "doing db:structure:dump"
Rake::Task['db:structure:dump'].invoke
puts "doing db :test:clone_structure"
Rake::Task['db:test:clone_structure'].invoke
end
end
end
I got the standard The behavior of the task. If I change the name of the task to: prepare2 and then execute rake db:test:prepare2, then it works. The natural conclusion I draw from this is that my rake task is defined before the built-in Rails, So my standard is Coverage: Preparing the task.
Can anyone see how I can solve this problem? I would rather overwrite it than use a new task. Thank you, at most
If you define an existing rake task, its execution will be appended to the execution of the original task Medium; these two tasks will be executed.
If you want to redefine the task, you need to clear the original task first:
Rake: :Task["db:test:prepare"].clear
Note that once the task is executed in rake, it will not be executed again even if it is called again. This is also useful. This is by design, but you You can call .reset on the task to allow it to run again.