class AddStatusToStudentWork < ActiveRecord::Migration
  def change
    add_column :student_works, :work_status, :integer, :default => 0

    count = HomeworkCommon.all.count / 30 + 2
    transaction do
      for i in 1 ... count do i
      HomeworkCommon.page(i).per(30).each do |hc|
        student_works = hc.student_works
        end_time = hc.end_time
        unless student_works.empty?
          student_works.each do |st|
            if Time.parse(end_time.to_s).strftime("%Y-%m-%d") < Time.parse(st.created_at.to_s).strftime("%Y-%m-%d")
              st.update_column('work_status', 2)
            else
              st.update_column('work_status', 1)
            end
          end
        end
        end
      end
    end
  end
end
