Exception: DatabaseValidations::Errors::IndexNotFound

Inherits:
Base
  • Object
show all
Defined in:
lib/database_validations/validations/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns, where_clause, index_name, available_indexes) ⇒ IndexNotFound

Returns a new instance of IndexNotFound.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/database_validations/validations/errors.rb', line 8

def initialize(columns, where_clause, index_name, available_indexes)
  @columns = columns
  @where_clause = where_clause
  @available_indexes = available_indexes
  @index_name = index_name

  text = if index_name
           "No unique index found with name: \"#{index_name}\". "\
           "Available indexes are: #{self.available_indexes.map(&:name)}. "
         else
           "No unique index found with #{columns_and_where_text(columns, where_clause)}. "\
           "Available indexes are: [#{self.available_indexes.map { |ind| columns_and_where_text(ind.columns, ind.where) }.join(', ')}]. "
         end

  super text + "Use ENV['SKIP_DB_UNIQUENESS_VALIDATOR_INDEX_CHECK']=true in case you want to skip the check. For example, when you run migrations."
end

Instance Attribute Details

#available_indexesObject (readonly)

Returns the value of attribute available_indexes.



6
7
8
# File 'lib/database_validations/validations/errors.rb', line 6

def available_indexes
  @available_indexes
end

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/database_validations/validations/errors.rb', line 6

def columns
  @columns
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



6
7
8
# File 'lib/database_validations/validations/errors.rb', line 6

def index_name
  @index_name
end

#where_clauseObject (readonly)

Returns the value of attribute where_clause.



6
7
8
# File 'lib/database_validations/validations/errors.rb', line 6

def where_clause
  @where_clause
end

Instance Method Details

#columns_and_where_text(columns, where) ⇒ Object



25
26
27
# File 'lib/database_validations/validations/errors.rb', line 25

def columns_and_where_text(columns, where)
  "columns: #{columns}#{" and where: #{where}" if where}"
end