Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
ushis opened this Issue Nov 2, 2012 · 3 comments

Comments

Projects
None yet
3 participants

ushis commented Nov 2, 2012

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

Member

steveklabnik commented Nov 2, 2012

Could you submit this fix as a pull request, please? That way, if we like it, we can just hit 'merge.' Thanks.

Owner

rafaelfranca commented Nov 2, 2012

I'm working on it

@rafaelfranca rafaelfranca reopened this Nov 2, 2012

ushis commented Nov 2, 2012

Ui, this was fast. Just forked the repo. @rafaelfranca Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment