修改迁移文件的bug

This commit is contained in:
ouyangxuhua 2015-11-20 09:26:58 +08:00
parent 0c891236a8
commit d71d9730bd
2 changed files with 14 additions and 8 deletions

View File

@ -3,7 +3,7 @@ class CopyForgeActivitiesToOrgActivities < ActiveRecord::Migration
count = ForgeActivity.all.count/30 + 1 count = ForgeActivity.all.count/30 + 1
for i in 1 ... count do for i in 1 ... count do
transaction do transaction do
ForgeActivity.page(i).per(30).each do ForgeActivity.page(i).per(30).each do |forge_act|
OrgActivity.create(:user_id => forge_act.user_id, OrgActivity.create(:user_id => forge_act.user_id,
:org_act_id => forge_act.forge_act_id, :org_act_id => forge_act.forge_act_id,
:org_act_type => forge_act.forge_act_type, :org_act_type => forge_act.forge_act_type,

View File

@ -4,17 +4,23 @@ class CopyCourseActivitiesToOrgActivities < ActiveRecord::Migration
for i in 1 ... count do for i in 1 ... count do
transaction do transaction do
CourseActivity.page(i).per(30).each do |course_act| CourseActivity.page(i).per(30).each do |course_act|
if course_act.course_act_type == 'Message' && !course_act.course_act.parent_id.nil?
org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{course_act.course_act.parent.id}").first
org_activity.created_at = course_act.created_at
org_activity.save
else
OrgActivity.create(:user_id => course_act.user_id, OrgActivity.create(:user_id => course_act.user_id,
:org_act_type => course_act.course_act_type,
:org_act_id => course_act.course_act_id, :org_act_id => course_act.course_act_id,
:org_act_type => course_act.course_act_type,
:container_id => course_act.course_id, :container_id => course_act.course_id,
:container_type => "Course", :container_type => 'Course',
:created_at => course_act.created_at, :created_at => course_act.created_at,
:updated_at => course_act.updated_at) :updated_at => course_act.updated_at)
end end
end end
end end
end end
end
def down def down
end end