socialforge/db/migrate/20161125024643_migrate_stud...

19 lines
674 B
Ruby

class MigrateStudentWorks < ActiveRecord::Migration
def up
count = Course.all.count / 30 + 2
transaction do
for i in 1 ... count do i
Course.page(i).per(30).each do |course|
homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")"
student_ids = course.student.blank? ? "(-1)" : "(" + course.student.map{|st| st.student_id}.join(",") + ")"
student_works = StudentWork.where("homework_common_id in #{homework_ids} and user_id not in #{student_ids}")
student_works.update_all(:is_delete => 1)
end
end
end
end
def down
end
end