题序迁移

dev_trainings
cxt 6 years ago
parent ef8b9bd5d3
commit 8f70ad8053

@ -0,0 +1,22 @@
class MigrationExerciseBankQuestionNumber < ActiveRecord::Migration
def up
Exercise.includes(:exercise_questions).find_each do |exercise|
if exercise.exercise_questions.pluck(:question_number).max != exercise.exercise_questions.size
exercise.exercise_questions.each_with_index do |question, j|
question.update_column('question_number', j + 1)
end
end
end
ExerciseBank.includes(:exercise_bank_questions).find_each do |exercise|
if exercise.exercise_bank_questions.pluck(:question_number).max != exercise.exercise_bank_questions.size
exercise.exercise_bank_questions.each_with_index do |question, j|
question.update_column('question_number', j + 1)
end
end
end
end
def down
end
end
Loading…
Cancel
Save