socialforge/db/migrate/20140605025302_migrate_cour...

19 lines
507 B
Ruby

class MigrateCourseAttachments < ActiveRecord::Migration
def self.up
# 原课程的资源数据迁移成新模式
Attachment.all.each do |attach|
if attach.container_type == "Project"
project = Project.find_by_id(attach.container_id)
if project && project.project_type == 1
attach.container_type= 'Course'
attach.container_id = project.course_extra.id
attach.save
end
end
end
end
def self.down
end
end