我想使用迁移运行 rake 任务,因为我们希望当用户运行时rails db:migrate
,该任务将通过迁移运行。
我的 rake 任务是:
namespace :task_for_log do
desc "This task set by default as current date for those logs where log_date is nil"
task set_by_default_date_of_log: :environment do
Log.where("log_date IS NULL").each do |log|
log.update_attributes(log_date: log.created_at.to_date)
end
end
end
请指导执行此任务的迁移是什么,这里有什么人可以挽救我的生命吗?