Sha256: 30a5df7970e39453ed89b0aa043895333553e21346ee4ee9c969c8e14d240937

Contents?: true

Size: 685 Bytes

Versions: 16

Compression:

Stored size: 685 Bytes

Contents

class MigratePortOverridesToInt < ActiveRecord::Migration[5.2]
  def up
    transform_lookup_values :to_i
  end

  def down
    transform_lookup_values :to_s
  end

  private

  def transform_lookup_values(method)
    return unless Foreman::Plugin.installed?("foreman_puppet")
    puppet_class = ::ForemanPuppet::Puppetclass.find_by :name => 'foreman_scap_client'
    return unless puppet_class
    port_key = puppet_class.class_params.find_by :key => 'port'
    return unless port_key
    port_key.lookup_values.in_batches do |batch|
      batch.each do |lookup_value|
        lookup_value.value = lookup_value.value.send(method)
        lookup_value.save
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
foreman_openscap-10.0.3 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-10.0.2 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-10.0.1 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-10.0.0 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-9.0.4 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-9.0.3 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-9.0.2 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-9.0.1 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-9.0.0 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-8.0.0 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-7.1.1 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-7.1.0 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-7.0.0 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-6.0.0 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-5.2.3 db/migrate/20200117135424_migrate_port_overrides_to_int.rb
foreman_openscap-5.2.2 db/migrate/20200117135424_migrate_port_overrides_to_int.rb