diff --git a/app/models/miq_search.rb b/app/models/miq_search.rb index 34d97da8a84..893090147a8 100644 --- a/app/models/miq_search.rb +++ b/app/models/miq_search.rb @@ -76,24 +76,32 @@ def self.descriptions FIXTURE_DIR = File.join(Rails.root, "db/fixtures") def self.seed + searches = where("name like 'default%'").index_by { |ms| "#{ms.name}-#{ms.db}" } fixture_file = File.join(FIXTURE_DIR, "miq_searches.yml") slist = YAML.load_file(fixture_file) if File.exist?(fixture_file) slist ||= [] - + slist.group_by { |s| [s['attributes']['name'], s['attributes']['db']] }.each do |(name, db), dups| + _log.warn("duplicate entry for db=#{db} name=#{name}") if dups.size > 1 + end slist.each do |search| attrs = search['attributes'] name = attrs['name'] db = attrs['db'] - rec = find_by(:name => name, :db => db) + rec = searches["#{name}-#{db}"] if rec.nil? _log.info("Creating [#{name}]") - create!(attrs) + searches["#{name}-#{db}"] = 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') + + # properly compare filter + filter = attrs.delete('filter') + rec.filter = filter if rec.filter.exp != filter.exp rec.attributes = attrs - rec.save! + + rec.save! if rec.changed? end end end diff --git a/db/fixtures/miq_searches.yml b/db/fixtures/miq_searches.yml index 796cc433754..e4c75bbfc07 100644 --- a/db/fixtures/miq_searches.yml +++ b/db/fixtures/miq_searches.yml @@ -328,16 +328,6 @@ value: "on" search_type: default db: Host -- attributes: - name: default_Status / Running - description: Status / Running - filter: !ruby/object:MiqExpression - exp: - INCLUDES: - field: Host-power_state - value: "on" - search_type: default - db: Host - attributes: name: default_Status / Stopped description: Status / Stopped @@ -379,17 +369,6 @@ value: "on" search_type: default db: Host -- attributes: - name: default_Status / Stopped - description: Status / Stopped - filter: !ruby/object:MiqExpression - exp: - not: - INCLUDES: - field: Host-power_state - value: "on" - search_type: default - db: Host - attributes: name: default_Store Type / NFS description: Store Type / NFS