diff options
author | Toon Claes <toon@gitlab.com> | 2018-11-22 21:13:36 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2018-11-27 11:40:38 +0100 |
commit | 54b639195ddb2d11b5a5e8208d5f94df365041db (patch) | |
tree | df4502706a4e7af55c0d8f27f3e8ddb65f37e957 /rubocop | |
parent | b18556f0adbd05151c026146a7929ac830ca4bc6 (diff) | |
download | gitlab-ce-54b639195ddb2d11b5a5e8208d5f94df365041db.tar.gz |
Make add_reference cop accept a hash for :index
It might happen you want to make the reference column have a unique
value, or you want to create partial indexes. So instead of only
accepting a `true` value, also accept a hash of options.
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/migration/add_reference.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/rubocop/cop/migration/add_reference.rb b/rubocop/cop/migration/add_reference.rb index 4b67270c97a..1d471b9797e 100644 --- a/rubocop/cop/migration/add_reference.rb +++ b/rubocop/cop/migration/add_reference.rb @@ -8,7 +8,7 @@ module RuboCop class AddReference < RuboCop::Cop::Cop include MigrationHelpers - MSG = '`add_reference` requires `index: true`' + MSG = '`add_reference` requires `index: true` or `index: { options... }`' def on_send(node) return unless in_migration?(node) @@ -33,7 +33,12 @@ module RuboCop private def index_enabled?(pair) - hash_key_type(pair) == :sym && hash_key_name(pair) == :index && pair.children[1].true_type? + return unless hash_key_type(pair) == :sym + return unless hash_key_name(pair) == :index + + index = pair.children[1] + + index.true_type? || index.hash_type? end def hash_key_type(pair) |