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