迁移调整

dev_forge
cxt 5 years ago
parent 6227ee6568
commit 27916c5d4e

@ -1,7 +1,5 @@
class AddIndexToExerciseChoice < ActiveRecord::Migration[5.2] class AddIndexToExerciseChoice < ActiveRecord::Migration[5.2]
def change def change
remove_index :exercise_answers, name: :index_on_question_id_user_id
change_column_default :exercise_answers, :exercise_choice_id, from: nil, to: -1 change_column_default :exercise_answers, :exercise_choice_id, from: nil, to: -1
ExerciseAnswer.where(exercise_choice_id: nil).update_all(exercise_choice_id: -1) ExerciseAnswer.where(exercise_choice_id: nil).update_all(exercise_choice_id: -1)
@ -12,5 +10,7 @@ class AddIndexToExerciseChoice < ActiveRecord::Migration[5.2]
add_index :exercise_answers, [:exercise_question_id, :user_id, :exercise_choice_id], name: 'exercise_choice_index', unique: true add_index :exercise_answers, [:exercise_question_id, :user_id, :exercise_choice_id], name: 'exercise_choice_index', unique: true
remove_index :exercise_answers, name: :index_on_question_id_user_id
end end
end end

Loading…
Cancel
Save