parent
bf88d3d53c
commit
74ebb896a1
@ -0,0 +1,23 @@
|
|||||||
|
class MigrateExerciseUserQuestions < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
exercises = Exercise.where("id > 900")
|
||||||
|
|
||||||
|
exercises.each do |exercise|
|
||||||
|
if exercise.exercise_level_settings.where("num != exercise_questions_count").size > 0
|
||||||
|
exercise.exercise_users.each do |exercise_user|
|
||||||
|
user_question_count = exercise_user.exercise_user_questions.size
|
||||||
|
if user_question_count > exercise.questions_count
|
||||||
|
exercise_user.exercise_user_questions.
|
||||||
|
where(id: exercise_user.exercise_user_questions[exercise.questions_count...user_question_count].map(&:id)).delete_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :exercise_user_questions, [:exercise_user_id, :exercise_question_id], unique: true,
|
||||||
|
name: "index_exercise_user_id_and_exercise_question_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue