summaryrefslogtreecommitdiff
path: root/rubocop/cop
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-02-09 16:52:43 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2017-02-10 21:51:09 +0100
commit766060bcdf3ff7c37f471b58e5d13721b263e37b (patch)
treebb449aae6f0a9c1c5b0dfd4cc80bc7c002972bfe /rubocop/cop
parenta97dcc077c68f4f320cd7a5686b9056adfef6c09 (diff)
downloadgitlab-ce-766060bcdf3ff7c37f471b58e5d13721b263e37b.tar.gz
Enforce use of add_concurrent_foreign_keyconcurrent-foreign-keys
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.
Diffstat (limited to 'rubocop/cop')
-rw-r--r--rubocop/cop/migration/add_concurrent_foreign_key.rb27
1 files changed, 27 insertions, 0 deletions
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