class MigrateCourseStages < ActiveRecord::Migration[5.2]
  def change
    Course.where(excellent: 1).each do |course|
      if course.subject
        course.subject.stages.each do |stage|
          new_stage = CourseStage.create!(course_id: course.id, name: stage.name, description: stage.description, position: stage.position)
          stage.stage_shixuns.each do |stage_shixun|
            CourseStageShixun.create!(course_id: course.id, course_stage_id: new_stage.id, shixun_id: stage_shixun.shixun_id, position: stage_shixun.position)
          end
        end
      end
    end
  end
end
