Sha256: 2f21067a892754f48a1b7486f97c997ba26a1b223883f640d07b75a6b59ce0c2

Contents?: true

Size: 823 Bytes

Versions: 4

Compression:

Stored size: 823 Bytes

Contents

class FixIncorrectReportMetrics < ActiveRecord::Migration[4.2]
  def up
    Report.all.find_each do |report|
      next unless report.metrics && report.metrics['time']

      metrics = report.metrics.dup

      report.metrics['time'].each do |resource, time|
        metrics['time'][resource] = if time.is_a? String
                                      begin
                                        Float(time.delete(' ms'))
                                      rescue StandardError
                                        nil
                                      end
                                    else
                                      time
                                    end
      end

      report.update(metrics: metrics) if metrics != report.metrics
    end
  end

  def down
    # Nothing
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_salt-17.0.0 db/migrate/20150220122707_fix_incorrect_report_metrics.rb
foreman_salt-16.0.3 db/migrate/20150220122707_fix_incorrect_report_metrics.rb
foreman_salt-16.0.2 db/migrate/20150220122707_fix_incorrect_report_metrics.rb
foreman_salt-16.0.1 db/migrate/20150220122707_fix_incorrect_report_metrics.rb