增加课程资源分离出来相关表数据迁移

This commit is contained in:
sw 2014-08-12 15:02:55 +08:00
parent 0064018a37
commit ef6f239182
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,5 @@
class AddColunToCourseAttachments < ActiveRecord::Migration
def change
add_column :course_attachments, :container_id, :integer, :default => 0
end
end

View File

@ -0,0 +1,29 @@
class UpdateCourseAttachments < ActiveRecord::Migration
def up
attachments = Attachment.where(" container_type = 'Course'")
attachments.each do |attachment|
course_attachment = CourseAttachment.new
course_attachment.container_id = attachment.container_id
course_attachment.filename = attachment.filename
course_attachment.disk_filename = attachment.disk_filename
course_attachment.filesize = attachment.filesize
course_attachment.content_type = attachment.content_type
course_attachment.digest = attachment.digest
course_attachment.downloads = attachment.downloads
course_attachment.author_id = attachment.author_id
course_attachment.created_at = attachment.created_on
course_attachment.description = attachment.description
course_attachment.disk_directory = attachment.disk_directory
course_attachment.attachtype = attachment.attachtype
course_attachment.is_public = attachment.is_public
course_attachment.save(:validate => false)
end
end
def down
coll = CourseAttachment.all
coll.each do |model|
model.destroy
end
end
end