From 312955e5dc80027e05aeb20aef7094fa38f4f94e Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 11 Sep 2015 16:45:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20150911064528_alter_user_activities.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 db/migrate/20150911064528_alter_user_activities.rb 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