From 0037604f9a3e405183724724b5c97aa0830d83b2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Apr 2019 18:17:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190419101132_update_exerise_user_end_at.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 db/migrate/20190419101132_update_exerise_user_end_at.rb diff --git a/db/migrate/20190419101132_update_exerise_user_end_at.rb b/db/migrate/20190419101132_update_exerise_user_end_at.rb new file mode 100644 index 00000000..79a64443 --- /dev/null +++ b/db/migrate/20190419101132_update_exerise_user_end_at.rb @@ -0,0 +1,14 @@ +class UpdateExeriseUserEndAt < ActiveRecord::Migration + def up + exercise = Exercise.where(:id => 123).first + exercise.exercise_group_settings.each do |group| + if group.end_time.present? && group.end_time < Time.now + user_ids = exercise.course.members.where(:course_group_id => group.course_group_id).map(&:user_id) + exercise.exercise_users.where(:commit_status => 1, :user_id => user_ids).update_all(:end_at => group.end_time) + end + end + end + + def down + end +end