class AddOldExerciseTiankongChoiceId < ActiveRecord::Migration[5.2]

  def up
    #类型为3 的问题答案及标准答案更新exercise_choice_id 为1，即表示第一空
    exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id)
    ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1)
    ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1)

    exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id)
    ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:1)
  end

  def down
    #类型为3 的问题答案及标准答案更新exercise_choice_id 为1，即表示第一空
    exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id)
    ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil)
    ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil)

    exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id)
    ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:nil)
  end

end
