instance method add_index_options

Ruby on Rails 4.1.16

Since v3.1.12 Last seen in v4.1.16

Available in: v3.1.12 v3.2.22.5 v4.0.13 v4.1.16

Signature

add_index_options(table_name, column_name, options = {})

No documentation comment.

Parameters

table_name req
column_name req
options opt = {}
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 773
        def add_index_options(table_name, column_name, options = {})
          column_names = Array(column_name)
          index_name   = index_name(table_name, column: column_names)

          options.assert_valid_keys(:unique, :order, :name, :where, :length, :internal, :using, :algorithm, :type)

          index_type = options[:unique] ? "UNIQUE" : ""
          index_type = options[:type].to_s if options.key?(:type)
          index_name = options[:name].to_s if options.key?(:name)
          max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length

          if options.key?(:algorithm)
            algorithm = index_algorithms.fetch(options[:algorithm]) {
              raise ArgumentError.new("Algorithm must be one of the following: #{index_algorithms.keys.map(&:inspect).join(', ')}")
            }
          end

          using = "USING #{options[:using]}" if options[:using].present?

          if supports_partial_index?
            index_options = options[:where] ? " WHERE #{options[:where]}" : ""
          end

          if index_name.length > max_index_length
            raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{max_index_length} characters"
          end
          if index_name_exists?(table_name, index_name, false)
            raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
          end
          index_columns = quoted_columns_for_index(column_names, options).join(", ")

          [index_name, index_type, index_columns, index_options, algorithm, using]
        end

Defined in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb line 773 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::SchemaStatements

Type at least 2 characters to search.

↑↓ navigate · open · esc close