From 1433bcb8ab76cd390fc1a88c23c49cc7018bf88c Mon Sep 17 00:00:00 2001 From: cxt Date: Sat, 15 Oct 2016 18:35:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20161015102324_update_all_rake.rb | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 db/migrate/20161015102324_update_all_rake.rb diff --git a/db/migrate/20161015102324_update_all_rake.rb b/db/migrate/20161015102324_update_all_rake.rb new file mode 100644 index 000000000..af3934c0f --- /dev/null +++ b/db/migrate/20161015102324_update_all_rake.rb @@ -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