class MigrateExerciseShixunAnswerComment < ActiveRecord::Migration[5.2]
  def change
    ExerciseAnswerComment.where.not(exercise_shixun_answer_id: ExerciseShixunAnswer.all).where("exercise_shixun_answer_id is not null and exercise_answer_id is not null").each do |answer|
      exercise_shixun_answer = ExerciseShixunAnswer.find_by(id: answer.exercise_answer_id)
      if exercise_shixun_answer.present?
        answer.update_columns(exercise_shixun_answer_id: exercise_shixun_answer&.id)
      end
    end
  end
end
