index_name_for_remove(table_name, column_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 1607
        def index_name_for_remove(table_name, column_name, options)
          return options[:name] if can_remove_index_by_name?(column_name, options)

          checks = []

          if !options.key?(:name) && expression_column_name?(column_name)
            options[:name] = index_name(table_name, column_name)
            column_names = []
          else
            column_names = index_column_names(column_name || options[:column])
          end

          checks << lambda { |i| i.name == options[:name].to_s } if options.key?(:name)

          if column_names.present? && !(options.key?(:name) && expression_column_name?(column_names))
            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.