Ruby

Ruby

Made by DeepSource

add_column does not accept an index argument RB-W1013

Anti-pattern
Major
Autofix

ActiveRecord#add_column does not accept index, but also does not raise an error for extra keys, so it is possible to mistakenly add the key without realizing it will not actually add an index.

ActiveRecord#add_column will fail silently and will cause an issue during runtime. If you wan to add an index, use ActiveRecord#add_index instead.

Bad practice

add_column :table, :column, :integer, index: true

Recommended

add_column :table, :column, :integer
add_index :table, :column

References

  1. ActiveRecord#add_column - APIDock
  2. ActiveRecord#add_index - APIDock