Module: SchemaPlus::ActiveRecord::ConnectionAdapters::SchemaStatements::AddIndex

Defined in:
lib/schema_plus/active_record/connection_adapters/schema_statements.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:


72
73
74
75
76
# File 'lib/schema_plus/active_record/connection_adapters/schema_statements.rb', line 72

def self.included(base) #:nodoc:
  base.class_eval do
    alias_method_chain :add_index, :schema_plus
  end
end

Instance Method Details

#add_index_with_schema_plus(table, columns, options = {}) ⇒ Object

:method: add_index

SchemaPlus modifies SchemaStatements::add_index so that it ignores errors raised about add an index that already exists – i.e. that has the same index name, same columns, and same options – and writes a warning to the log. Some combinations of rails & DB adapter versions would log such a warning, others would raise an error; with SchemaPlus all versions log the warning and do not raise the error.

(This avoids collisions between SchemaPlus's auto index behavior and legacy explicit add_index statements, for platforms that would raise an error.)


92
93
94
95
96
97
# File 'lib/schema_plus/active_record/connection_adapters/schema_statements.rb', line 92

def add_index_with_schema_plus(table, columns, options={})
  options.delete(:if_exists) if options # some callers explcitly pass options=nil
  add_index_without_schema_plus(table, columns, options)
rescue => e
  SchemaStatements.add_index_exception_handler(self, table, columns, options, e)
end