Add Rails/AddColumnIndex rubocop rule

The `column` method in ActiveRecord::ConnectionAdapters::TableDefinition
supports adding the `index:` option. The documentation says:

> Instantiates a new column for the table. See connection.add_column for
> available options.
>
> Additional options are:
>
> :index - Create an index for the column. Can be either true or an
> options hash.

So basically the `connection.add_column` method silently ignores the
`index:` option, and whenever we intended to create an index this way,
we didn't.

We're creating a new migration where we properly add the indexes that
weren't added when we intended to.

Thanks to the rubocop-rails team, who added this cop in version 2.11.0
and helped us notice this bug.
This commit is contained in:
Javi Martín
2021-08-11 05:28:35 +02:00
parent 5b6dc9d7ff
commit 5abd0466e2
12 changed files with 47 additions and 14 deletions

View File

@@ -208,6 +208,9 @@ Performance/Sum:
Rails/ActiveRecordCallbacksOrder:
Enabled: true
Rails/AddColumnIndex:
Enabled: true
Rails/CreateTableWithTimestamps:
Enabled: true
Exclude: