diff --git a/app/models/miq_search.rb b/app/models/miq_search.rb index 25356fa8e24..131ae1794d9 100644 --- a/app/models/miq_search.rb +++ b/app/models/miq_search.rb @@ -93,10 +93,10 @@ def self.seed name = attrs['name'] db = attrs['db'] - rec = searches["#{name}-#{db}"] + rec = searches.delete("#{name}-#{db}") if rec.nil? _log.info("Creating [#{name}]") - searches["#{name}-#{db}"] = create!(attrs) + create!(attrs) else # Avoid undoing user changes made to enable/disable default searches which is held in the search_key column attrs.delete('search_key') @@ -109,6 +109,10 @@ def self.seed rec.save! if rec.changed? end end + if searches.any? + _log.warn("Deleting the following MiqSearch(es) as they no longer exist: #{searches.keys.sort.collect(&:inspect).join(", ")}") + MiqSearch.destroy(searches.values.map(&:id)) + end end def self.display_name(number = 1)