class MigrateExcellentCourseCourseList < ActiveRecord::Migration[5.2]
  def change
    courses = Course.where(excellent: true)
    courses.each do |course|
      if !course.course_list.present? && course.subject
        subject = course.subject
        course_list = CourseList.find_by(name: subject.name) || CourseList.create!(name: subject.name, user_id: course.tea_id, is_admin: 0)
        course.update_attributes(course_list_id: course_list.id)
      end
    end
  end
end
