Sha256: b3ba25b6c698010ff3b88d39805342780065f6135a680a32eadff8f2c4f6ef2e

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

class ConvertReports < ActiveRecord::Migration
  def self.up
    say "About to convert all of the #{Report.count} reports log field into a more DB optimized way... this might take a while....."

    Report.find_in_batches do |reports|
      reports.each do |report|
        case report.log.class.to_s
        when "Puppet::Transaction::Report"
          log = report.log
        when "String"
          log = YAML.load(report.log)
        else
          # this report might have been processed already, skipping
          next
        end

        # Is this a pre 2.6.x report format?
        pre26 = !report.instance_variables.include?("@resource_statuses")

        # Recalcuate the status field if this report is from a 2.6.x puppet client
        report.status = Report.calc_status(Report.metrics_to_hash(log)) unless pre26
        report.metrics = Report.m2h(log.metrics).with_indifferent_access

        report.import_log_messages(log)
        report.log = "" # not really needed, but this way the db can reuse some space instead of claim new one.

        report.save
      end
    end
    remove_column :reports, :log

  end

  def self.down
    add_column :reports, :log, :text
    say "cant recreate the data, import it again"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/db/migrate/20101019183859_convert_reports.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/db/migrate/20101019183859_convert_reports.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/db/migrate/20101019183859_convert_reports.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/db/migrate/20101019183859_convert_reports.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/db/migrate/20101019183859_convert_reports.rb