class UpdateForgeAndUserActivity < ActiveRecord::Migration
  def up
    user_count = UserActivity.all.count / 30 + 2
    transaction do
      for i in 1 ... user_count do i
      UserActivity.page(i).per(30).each do |user_act|
        if user_act.act_type == 'Issue'
          if user_act.act
            if user_act.act.journals.count > 0
              user_act.updated_at = user_act.act.journals.maximum("created_on")
              user_act.save
            end
          else
            user_act.destroy
          end
        end
      end
      end
    end

    for_count = ForgeActivity.all.count / 30 + 2
    transaction do
      for i in 1 ... for_count do i
      ForgeActivity.page(i).per(30).each do |for_act|
        if for_act.forge_act_type == 'Issue'
          if for_act.forge_act
            if for_act.forge_act.journals.count > 0
              for_act.updated_at = for_act.forge_act.journals.maximum("created_on")
              for_act.save
            end
          else
            for_act.destroy
          end
        end
      end
      end
    end
  end

  def down
  end
end
