socialforge/db/migrate/20140611161801_add_courseid...

11 lines
377 B
Ruby

class AddCourseidToNews < ActiveRecord::Migration
#迁移原课程新闻数据
def change
add_column :news, :course_id, :int
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)
end
end