socialforge/db/migrate/20140603042015_stored_cours...

44 lines
1.5 KiB
Ruby

class StoredCourseProcedure < ActiveRecord::Migration
def self.up
# 需要完成的数据导入:
# project中所有的课程导入至course
# Project_status导入至course_status
#
Project.all.each do |project|
if project.project_type == 1
course = Course.find_by_extra(project.identifier)
if course
sql = "update courses set name='" + project.name.to_s + "',description='"
sql += project.description.to_s + "',status=" + project.status.to_s
sql += ",attachmenttype=2 where id=" +course.id.to_s
execute(sql)
# 以下方式保存,描述等经常不能成功
#course.name = project.name
#course.description = project.description
#course.status = project.status
#course.attachmenttype = 2
#course.lft = project.lft
#course.rgt = project.rgt
#course.save(:validate => false)
# 更新状态表
projectstatus = ProjectStatus.find_by_project_id(project.id)
if projectstatus
courseStatus = CourseStatus.new
courseStatus.course_id = course.id
courseStatus.changesets_count = projectstatus.changesets_count
courseStatus.watchers_count = projectstatus.watchers_count
courseStatus.grade = projectstatus.grade
courseStatus.course_ac_para = projectstatus.course_ac_para
courseStatus.save()
end
end
end
end
end
def self.down
end
end