lib/inventory_refresh/inventory_collection.rb
def unique_index_for(keys)
      @unique_index_for_keys_cache ||= {}
      @unique_index_for_keys_cache[keys] if @unique_index_for_keys_cache[keys]

      # Take the uniq key having the least number of columns
      @unique_index_for_keys_cache[keys] = uniq_keys_candidates(keys).min_by { |x| x.columns.count }
    end
def unique_index_for(keys)
      @unique_index_for_keys_cache ||= {}
      @unique_index_for_keys_cache[keys] if @unique_index_for_keys_cache[keys]

      # Take the uniq key having the least number of columns
      @unique_index_for_keys_cache[keys] = uniq_keys_candidates(keys).min_by { |x| x.columns.count }
    end
Finds an index that fits the list of columns (keys) the best

 @param keys [Array<Symbol>]
 @raise [Exception] if the unique index for the columns was not found
 @return [ActiveRecord::ConnectionAdapters::IndexDefinition] unique index fitting the keys