socialforge/db/migrate/20140603042015_stored_cours...

44 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

2014-05-30 10:48:06 +08:00
class StoredCourseProcedure < ActiveRecord::Migration
def self.up
2014-05-30 10:48:06 +08:00
# 需要完成的数据导入:
# project中所有的课程导入至course
# Project_status导入至course_status
#
2014-06-03 09:39:33 +08:00
Project.all.each do |project|
if project.project_type == 1
course = Course.find_by_extra(project.identifier)
if course
2014-07-01 16:19:42 +08:00
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
2014-06-16 14:42:48 +08:00
#course.lft = project.lft
#course.rgt = project.rgt
2014-07-01 16:19:42 +08:00
#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()
2014-05-30 10:48:06 +08:00
end
end
end
end
end
def self.down
2014-05-30 10:48:06 +08:00
end
end