aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrate/099_move_raw_email_to_filesystem.rb
blob: ea77580e11dfc8380507d5448870d2e215f7a7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class MoveRawEmailToFilesystem < ActiveRecord::Migration
    def self.up
        batch_size = 10
        0.step(RawEmail.count, batch_size) do |i|
            RawEmail.find(:all, :limit => batch_size, :offset => i, :order => :id).each do |raw_email|
                if !File.exists?(raw_email.filepath)
                    STDERR.puts "converting raw_email " + raw_email.id.to_s
                    raw_email.data = raw_email.dbdata
                    #raw_email.dbdata = nil
                    #raw_email.save!
                end
            end
        end
    end

    def self.down
        raise "safer not to have reverse migration scripts, and we never use them"
    end
end