lib/schema_plus/indexes/middleware/migration.rb
# Ignore duplicates
#
# SchemaPlus::Indexes 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::Indexes all versions log the warning and do not raise the error.
Ignore duplicates
SchemaPlus::Indexes 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::Indexes all versions log the warning and do not raise the error.
Ignore duplicates SchemaPlus :: Indexes 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 :: Indexes all versions log the warning and do not raise the error .
def around(env)
          yield env
        rescue => e
          raise unless e.message.match(/["']([^"']+)["'].*already exists/)
          name = $1
          existing = env.caller.indexes(env.table_name).find{|i| i.name == name}
          attempted = ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(env.table_name, env.column_names, env.options.merge(:name => name))
          raise if attempted != existing
          ::ActiveRecord::Base.logger.warn "[schema_plus_indexes] Index name #{name.inspect}' on table #{env.table_name.inspect} already exists. Skipping."
        end
def around ( env ) yield env rescue => e raise unless e . message . match ( / ["']([^"']+)["'].*already exists / ) name = $1 existing = env . caller . indexes ( env . table_name ) . find { | i | i . name == name } attempted = :: ActiveRecord :: ConnectionAdapters :: IndexDefinition . new ( env . table_name , env . column_names , env . options . merge ( :name => name ) ) raise if attempted != existing :: ActiveRecord :: Base . logger . warn "[schema_plus_indexes] Index name #{name.inspect}' on table #{env.table_name.inspect} already exists. Skipping." end
Ignore duplicates
SchemaPlus::Indexes modifies SchemaStatements::add_index so that it ignores
errors raised about add an index that already exists -- i.e.
Ignore duplicates SchemaPlus :: Indexes modifies SchemaStatements :: add_index so that it ignores errors raised about add an index that already exists -- i . e .
env