20120131142400_remove_noisy_attachment_journals.rb 857 Bytes
Newer Older
1 2 3 4
#-- encoding: UTF-8
#-- copyright
# ChiliProject is a project management system.
#
Holger Just's avatar
Holger Just committed
5
# Copyright (C) 2010-2013 the ChiliProject Team
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# See doc/COPYRIGHT.rdoc for more details.
#++

class RemoveNoisyAttachmentJournals < ActiveRecord::Migration
  def self.up
    AttachmentJournal.find_each(:batch_size => 100 ) do |j|
      if j.changes.keys == ["downloads"]
        j.destroy
      elsif j.changes.keys.include? "downloads"
        j.changes.delete("downloads")
        j.save!
      end
    end
  end

  def self.down
    # no-op as the downloads counter shouldn't be journaled in the first time
  end
end