class MigrateHomeworkLateTime < ActiveRecord::Migration[5.2] def change homeworks = HomeworkCommon.where.not(end_time: nil).where(homework_type: [1, 3 ,4], allow_late: 1, late_time: nil) homeworks.each do |homework| if homework.course.try(:end_date).present? homework.update_column("late_time", homework.course.end_date) elsif homework.end_time.present? homework.update_column("late_time", Time.at(homework.end_time.to_i + 30*24*3600)) end end tasks = GraduationTask.where.not(end_time: nil).where(allow_late: 1, late_time: nil) tasks.each do |task| if task.course.try(:end_date).present? task.update_column("late_time", task.course.end_date) elsif task.end_time.present? task.update_column("late_time", Time.at(task.end_time.to_i + 30*24*3600)) end end end end