【发布时间】:2018-12-03 20:34:44
【问题描述】:
我想使用迁移运行 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
请指导执行此任务的迁移是什么,这里有谁可以救我的命??
【问题讨论】:
-
如果您打算使用迁移,为什么要在此处使用 rake 任务?这些
updates本身可以成为迁移的一部分 -
因为这是我客户的要求,所以我需要这个。
标签: ruby-on-rails ruby ruby-on-rails-5 rails-migrations