课程动态的数据迁移
This commit is contained in:
parent
6a3089bb9b
commit
a2d6168043
|
@ -0,0 +1,53 @@
|
|||
class AlterActivities < ActiveRecord::Migration
|
||||
def up
|
||||
UserActivity.all.each do |activity|
|
||||
if activity.act_type == 'JournalsForMessage'
|
||||
if activity.act
|
||||
unless activity.act.m_parent_id.nil?
|
||||
parent_act = UserActivity.where("act_id = #{activity.act.parent.id} and act_type='JournalsForMessage' and container_type='Course'").first
|
||||
if parent_act
|
||||
parent_act.created_at = activity.act.parent.children.maximum("created_on")
|
||||
parent_act.save
|
||||
activity.destroy
|
||||
end
|
||||
end
|
||||
else
|
||||
activity.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
CourseActivity.all.each do |activity|
|
||||
if activity.course_act_type == 'JournalsForMessage'
|
||||
if activity.course_act
|
||||
unless activity.course_act.m_parent_id.nil?
|
||||
parent_act = CourseActivity.where("course_act_id = #{activity.course_act.parent.id} and course_act_type='JournalsForMessage'").first
|
||||
if parent_act
|
||||
parent_act.created_at = activity.course_act.parent.children.maximum("created_on")
|
||||
parent_act.save
|
||||
activity.destroy
|
||||
end
|
||||
end
|
||||
else
|
||||
activity.destroy
|
||||
end
|
||||
elsif activity.course_act_type == 'Message'
|
||||
if activity.course_act
|
||||
unless activity.course_act.parent_id.nil?
|
||||
parent_act = CourseActivity.where("course_act_id = #{activity.course_act.parent.id} and course_act_type='Message'").first
|
||||
if parent_act
|
||||
parent_act.created_at = activity.course_act.parent.children.maximum("created_on")
|
||||
parent_act.save
|
||||
activity.destroy
|
||||
end
|
||||
end
|
||||
else
|
||||
activity.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
class UpdateCourseActivitiesUpdatedAt < ActiveRecord::Migration
|
||||
def up
|
||||
count = CourseActivity.all.count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
CourseActivity.page(i).per(30).each do |activity|
|
||||
activity.updated_at = activity.created_at
|
||||
activity.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue