历史数据迁移

This commit is contained in:
cxt 2016-10-15 18:35:36 +08:00
parent 3358f4233c
commit 1433bcb8ab
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
class UpdateAllRake < ActiveRecord::Migration
def up
attachments = Attachment.where("is_publish = 0 and publish_time <= #{Date.today}")
attachments.update_all(:is_publish => 1)
exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises.update_all(:exercise_status => 2)
end_exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
end_exercises.each do |exercise|
course = exercise.course
exercise.update_column('exercise_status', 3)
course.student.each do |student|
if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,exercise.id).empty?
ExerciseUser.create(:user_id => student.student_id, :exercise_id => exercise.id, :start_at => exercise.end_time, :status => true,:score=>0)
end
end
end
end
def down
end
end