Skip to content

Raise ArgumentError in add_index_options() for unsupported options. #8104

@ushis

Description

@ushis

Can we please check the options in ActiveRecord::ConnectionAdapters::SchemaStatements#add_index_options() for unsupported ones before applying them. This would be very usefull to avoid spelling errors, such as unqiue: true, which would pass silently at the moment.

Maybe something like this:

if Hash === options
  unless (unsupported = options.keys - [:unique, :name]).empty?
    raise ArgumtentError, "Unsupported index options: #{unsupported.map(&:to_s).join(', ')}"
  end

  index_type = options[:unique] ? "UNIQUE" : ""
  index_name = options[:name].to_s if options.key?(:name)
else
  index_type = options
end

EDIT

Link to the code: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L618-L641

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions