class RenameProjectIdToHomeworkForCourses < ActiveRecord::Migration
  def change
    rename_column(:homework_for_courses, :project_id, :course_id)

    # 作业数据迁移
    HomeworkForCourse.all.each do |work|
      project = Project.find_by_id(work.course_id)
      if project && project.project_type == 1
        work.course_id = project.course_extra.id
        work.save(:validate => false)
      end
    end
  end
end
