diff --git a/db/migrate/20150911064528_alter_user_activities.rb b/db/migrate/20150911064528_alter_user_activities.rb new file mode 100644 index 000000000..a65f933d8 --- /dev/null +++ b/db/migrate/20150911064528_alter_user_activities.rb @@ -0,0 +1,26 @@ +class AlterUserActivities < ActiveRecord::Migration + def up + count = UserActivity.all.count / 30 + 3 + transaction do + for i in 1 ... count do i + UserActivity.page(i).per(30).each do |activity| + if activity.act_type == 'Message' + if activity.act + unless activity.act.parent_id.nil? + parent_act = UserActivity.where("act_id = #{activity.act.parent.id} and act_type='Message'").first + parent_act.created_at = activity.act.parent.children.maximum("created_on") + parent_act.save + activity.destroy + end + else + activity.destroy + end + end + end + end + end + end + + def down + end +end