2014-06-11 16:46:13 +08:00
|
|
|
class AddCourseidToNews < ActiveRecord::Migration
|
2014-06-18 11:08:44 +08:00
|
|
|
#迁移原课程通知数据
|
2014-06-11 16:46:13 +08:00
|
|
|
def change
|
|
|
|
add_column :news, :course_id, :int
|
|
|
|
|
2014-06-18 11:08:44 +08:00
|
|
|
# course_id不能直接设置为 project_id
|
|
|
|
#News.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
|
|
|
|
#News.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
|
|
|
|
|
|
|
|
News.all.each do |news|
|
|
|
|
project = Project.find_by_id(news.project_id)
|
|
|
|
if project && project.project_type == 1
|
|
|
|
news.course_id = project.course_extra.id
|
|
|
|
news.project_id = -1
|
2014-07-01 15:29:16 +08:00
|
|
|
news.save(:validate => false)
|
2014-06-18 11:08:44 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-06-11 16:46:13 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|