I had the same issue and thanks to the help of the gitter folks, I could solve it:
cd /var/www/miq/vmdb/tools
irb
and execute following script:
require File.expand_path(’…/config/environment’, dir)
#resources can have multiple relationships
#each of those should have only 1 parent - bring back the ones with multiple parents
Relationship.where(:resource_type =>‘EmsCluster’).group(:resource_type, :resource_id, :relationship)
.having(“count() > 1”)
.count
.each do |(resource_type, resource_id, relationship), count|
#those were aggregate values. we want the individual relationship records
#order by most recent to older
Relationship.where(:resource_type=>resource_type, :resource_id=>resource_id, :relationship=>relationship)
.includes(:resource).order(:created_at => :desc)
.each_with_index do |rel, index|
puts “>>> #{rel.resource.name} #{rel.created_at} #{rel.ancestry} (#{index == 0 ? ‘keeping’ : ‘destroying’})”
#rel.destroy if index > 0 ### <<< uncomment to execute >>>
end
end