Sha256: 1ad7a25c9b7b285eeac1f18155159a393cb007443ed0cf8e4ed9d2d46679c3c8

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

class MigrateEnvironmentToPuppetFacet < ActiveRecord::Migration[6.0]
  def up
    puppet_hostgroups = ::Hostgroup.unscoped.where.not(environment_id: nil).pluck(:id, :environment_id)
    puppet_hostgroups.map! { |hg_id, env_id| { hostgroup_id: hg_id, environment_id: env_id } }
    ForemanPuppet::HostgroupPuppetFacet.insert_all(puppet_hostgroups) if puppet_hostgroups.any?

    puppet_hosts = Host::Managed.unscoped.where.not(environment_id: nil).pluck(:id, :environment_id)
    puppet_hosts.map! { |host_id, env_id| { host_id: host_id, environment_id: env_id } }
    ForemanPuppet::HostPuppetFacet.insert_all(puppet_hosts) if puppet_hosts.any?
  end

  def down
    hostgroup_facet_ids = ForemanPuppet::HostgroupPuppetFacet.all.pluck(:hostgroup_id, :environment_id)
    hostgroup_facet_ids.each do |hostgroup_id, env_id|
      ::Hostgroup.unscoped.where(id: hostgroup_id).update_all(environment_id: env_id)
    end
    host_facet_ids = ForemanPuppet::HostPuppetFacet.all.pluck(:host_id, :environment_id)
    host_facet_ids.each do |host_id, env_id|
      ::Host::Managed.unscoped.where(id: host_id).update_all(environment_id: env_id)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foreman_puppet-1.0.2 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-1.0.1 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-1.0.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-1.0.0.rc.2 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-1.0.0.rc.1 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-0.1.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-0.0.2 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-0.0.1 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb