Skip to content

Commit

Permalink
Force the insert on migration
Browse files Browse the repository at this point in the history
If we do not force inserts, Rails tries to skip duplicates, which is not supported on some environments.
This makes the migration flaky and fail on badly configured environmets for no reason.

Fixes #191
  • Loading branch information
ezr-ondrej committed Sep 17, 2021
1 parent 6f7bed7 commit 115599b
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ 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?
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?
ForemanPuppet::HostPuppetFacet.insert_all!(puppet_hosts) if puppet_hosts.any?
end

def down
Expand Down

0 comments on commit 115599b

Please sign in to comment.