lib/inventory_refresh/inventory_collection.rb
def uniq_keys_candidates(keys)
      # Find all uniq indexes that that are covering our keys
      uniq_key_candidates = unique_indexes.each_with_object([]) { |i, obj| obj << i if (keys - i.columns.map(&:to_sym)).empty? }

      if unique_indexes.blank? || uniq_key_candidates.blank?
        raise "#{self} and its table #{model_class.table_name} must have a unique index defined "\
                "covering columns #{keys} to be able to use saver_strategy :concurrent_safe_batch."
      end

      uniq_key_candidates
    end
def uniq_keys_candidates(keys)
      # Find all uniq indexes that that are covering our keys
      uniq_key_candidates = unique_indexes.each_with_object([]) { |i, obj| obj << i if (keys - i.columns.map(&:to_sym)).empty? }

      if unique_indexes.blank? || uniq_key_candidates.blank?
        raise "#{self} and its table #{model_class.table_name} must have a unique index defined "\
                "covering columns #{keys} to be able to use saver_strategy :concurrent_safe_batch."
      end

      uniq_key_candidates
    end
Find candidates for unique key. Candidate must cover all columns we are passing as keys.

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