index_name_for_remove(table_name, options = {}) protected

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 1193
        def index_name_for_remove(table_name, options = {})
          return options[:name] if can_remove_index_by_name?(options)

          # if the adapter doesn't support the indexes call the best we can do
          # is return the default index name for the options provided
          return index_name(table_name, options) unless respond_to?(:indexes)

          checks = []

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

          if column_names.any?
            checks << lambda { |i| i.columns.join('_and_') == column_names.join('_and_') }
          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.