测验历史数据的题号迁移

This commit is contained in:
cxt 2017-10-12 18:35:55 +08:00
parent c3671baa6e
commit 10884221b5
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
class MigrateExerciseQuestionNum < ActiveRecord::Migration
def up
count = Exercise.all.count / 30 + 2
transaction do
for i in 1 ... count do i
Exercise.page(i).per(30).each do |exercise|
exercise.exercise_questions.reorder("created_at asc").each_with_index do |question, j|
question.update_column('question_number', j + 1)
end
end
end
end
end
def down
end
end