diff options
Diffstat (limited to 'rubocop/cop/migration/add_concurrent_foreign_key.rb')
-rw-r--r-- | rubocop/cop/migration/add_concurrent_foreign_key.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/rubocop/cop/migration/add_concurrent_foreign_key.rb b/rubocop/cop/migration/add_concurrent_foreign_key.rb index d78c7b9b043..236de6224a4 100644 --- a/rubocop/cop/migration/add_concurrent_foreign_key.rb +++ b/rubocop/cop/migration/add_concurrent_foreign_key.rb @@ -10,17 +10,29 @@ module RuboCop MSG = '`add_foreign_key` requires downtime, use `add_concurrent_foreign_key` instead'.freeze + def_node_matcher :false_node?, <<~PATTERN + (false) + PATTERN + def on_send(node) return unless in_migration?(node) name = node.children[1] - add_offense(node, location: :selector) if name == :add_foreign_key + if name == :add_foreign_key && !not_valid_fk?(node) + add_offense(node, location: :selector) + end end def method_name(node) node.children.first end + + def not_valid_fk?(node) + node.each_node(:pair).any? do |pair| + pair.children[0].children[0] == :validate && false_node?(pair.children[1]) + end + end end end end |