index_name_for_remove(table_name, options = {}) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1222
        def index_name_for_remove(table_name, options = {})
          return options[:name] if can_remove_index_by_name?(options)

          checks = []

          if options.is_a?(Hash)
            checks << lambda { |i| i.name == options[:name].to_s } if options.key?(:name)
            column_names = index_column_names(options[:column])
          else
            column_names = index_column_names(options)
          end

          if column_names.present?
            checks << lambda { |i| index_name(table_name, i.columns) == index_name(table_name, column_names) }
          end

          raise ArgumentError, "No name or columns specified" if checks.none?

          matching_indexes = indexes(table_name).select { |i| checks.all? { |check| check[i] } }

          if matching_indexes.count > 1
            raise ArgumentError, "Multiple indexes found on #{table_name} columns #{column_names}. "                                   "Specify an index name from #{matching_indexes.map(&:name).join(', ')}"
          elsif matching_indexes.none?
            raise ArgumentError, "No indexes found on #{table_name} with the options provided."
          else
            matching_indexes.first.name
          end
        end
Register or log in to add new notes.