Sha256: d777c11991a5abad22de2fb21a852bb79214b47ddb97b39983da11512aec6ae0

Contents?: true

Size: 1.25 KB

Versions: 36

Compression:

Stored size: 1.25 KB

Contents

class MigrateEnvironmentToPuppetFacet < ActiveRecord::Migration[6.0]
  def up
    return true unless column_exists?(:hosts, :environment_id)
    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
    return true unless column_exists?(:hosts, :environment_id)
    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

36 entries across 36 versions & 1 rubygems

Version Path
foreman_puppet-8.0.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-6.4.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-7.0.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-6.3.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-6.2.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-6.1.1 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-5.1.3 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-6.1.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-6.0.1 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-6.0.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-5.1.2 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-4.1.1 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-5.1.1 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-5.1.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-4.1.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-4.0.4 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-5.0.0 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-4.0.3 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-4.0.2 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
foreman_puppet-3.0.7 db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb