socialforge/db/migrate/20150925025200_alter_activi...

54 lines
1.8 KiB
Ruby
Raw Normal View History

2015-09-28 10:51:44 +08:00
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?
2015-09-29 11:19:53 +08:00
parent_act = UserActivity.where("act_id = #{activity.act.m_parent_id} and act_type='JournalsForMessage' and container_type='Course'").first
2015-09-28 10:51:44 +08:00
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?
2015-09-29 11:19:53 +08:00
parent_act = CourseActivity.where("course_act_id = #{activity.course_act.m_parent_id} and course_act_type='JournalsForMessage'").first
2015-09-28 10:51:44 +08:00
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?
2015-09-29 11:19:53 +08:00
parent_act = CourseActivity.where("course_act_id = #{activity.course_act.parent_id} and course_act_type='Message'").first
2015-09-28 10:51:44 +08:00
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