From 766060bcdf3ff7c37f471b58e5d13721b263e37b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 9 Feb 2017 16:52:43 +0100 Subject: Enforce use of add_concurrent_foreign_key This adds a Rubocop rule to enforce the use of add_concurrent_foreign_key instead of the regular add_foreign_key method. This cop has been disabled for existing migrations so we don't need to change those. --- .../cop/migration/add_concurrent_foreign_key.rb | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rubocop/cop/migration/add_concurrent_foreign_key.rb (limited to 'rubocop/cop/migration') diff --git a/rubocop/cop/migration/add_concurrent_foreign_key.rb b/rubocop/cop/migration/add_concurrent_foreign_key.rb new file mode 100644 index 00000000000..e40a7087a47 --- /dev/null +++ b/rubocop/cop/migration/add_concurrent_foreign_key.rb @@ -0,0 +1,27 @@ +require_relative '../../migration_helpers' + +module RuboCop + module Cop + module Migration + # Cop that checks if `add_concurrent_foreign_key` is used instead of + # `add_foreign_key`. + class AddConcurrentForeignKey < RuboCop::Cop::Cop + include MigrationHelpers + + MSG = '`add_foreign_key` requires downtime, use `add_concurrent_foreign_key` instead' + + def on_send(node) + return unless in_migration?(node) + + name = node.children[1] + + add_offense(node, :selector) if name == :add_foreign_key + end + + def method_name(node) + node.children.first + end + end + end + end +end -- cgit v1.2.1