Method: ActiveRecord::ConnectionAdapters::SchemaStatements#add_index_options

Defined in:
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

#add_index_options(table_name, column_name, name: nil, if_not_exists: false, internal: false, **options) ⇒ Object

:nodoc:



1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb', line 1476

def add_index_options(table_name, column_name, name: nil, if_not_exists: false, internal: false, **options) # :nodoc:
  options.assert_valid_keys(:unique, :length, :order, :opclass, :where, :type, :using, :comment, :algorithm, :include, :nulls_not_distinct)

  column_names = index_column_names(column_name)

  index_name = name&.to_s
  index_name ||= index_name(table_name, column_names)

  validate_index_length!(table_name, index_name, internal)

  index = IndexDefinition.new(
    table_name, index_name,
    options[:unique],
    column_names,
    lengths: options[:length] || {},
    orders: options[:order] || {},
    opclasses: options[:opclass] || {},
    where: options[:where],
    type: options[:type],
    using: options[:using],
    include: options[:include],
    nulls_not_distinct: options[:nulls_not_distinct],
    comment: options[:comment]
  )

  [index, index_algorithm(options[:algorithm]), if_not_exists]
end