|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
class AddUniqIndexToExerciseAnswer < ActiveRecord::Migration[5.2]
|
|
|
|
|
def change
|
|
|
|
|
remove_index :exercise_answers, column: [:exercise_question_id, :user_id]
|
|
|
|
|
|
|
|
|
|
change_column_default :exercise_answers, :exercise_choice_id, from: nil, to: -1
|
|
|
|
|
ExerciseAnswer.where(exercise_choice_id: nil).update_all(exercise_choice_id: -1)
|
|
|
|
|
# remove_index :exercise_answers, column: [:exercise_question_id, :user_id]
|
|
|
|
|
#
|
|
|
|
|
# change_column_default :exercise_answers, :exercise_choice_id, from: nil, to: -1
|
|
|
|
|
# ExerciseAnswer.where(exercise_choice_id: nil).update_all(exercise_choice_id: -1)
|
|
|
|
|
|
|
|
|
|
sql = %Q(delete from exercise_answers where (exercise_question_id, user_id, exercise_choice_id) in
|
|
|
|
|
(select * from (select exercise_question_id, user_id, exercise_choice_id from exercise_answers group by exercise_question_id, user_id, exercise_choice_id having count(*) > 1) a)
|
|
|
|
|