summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
authorKushal Pandya <kushal@gitlab.com>2017-04-07 02:29:55 +0530
committerKushal Pandya <kushal@gitlab.com>2017-04-07 02:29:55 +0530
commit26a672dabc6b5217a58a2ec9b3c88e869c87c6dd (patch)
treef52e09c39acfcb5cdd93c1bdfa2ae1ea9945bea9 /rubocop
parent3dc8c3127bf96a820efc807c86e62fbffc9a5b0d (diff)
parent55811ac9900af81fb980c3649ee1c9aadedb3a44 (diff)
downloadgitlab-ce-26a672dabc6b5217a58a2ec9b3c88e869c87c6dd.tar.gz
Merge branch '18471-restrict-tag-pushes-protected-tags' of gitlab.com:gitlab-org/gitlab-ce into 18471-restrict-tag-pushes-protected-tags
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/migration/add_concurrent_index.rb2
-rw-r--r--rubocop/cop/migration/remove_concurrent_index.rb29
-rw-r--r--rubocop/cop/migration/remove_index.rb26
-rw-r--r--rubocop/rubocop.rb2
4 files changed, 58 insertions, 1 deletions
diff --git a/rubocop/cop/migration/add_concurrent_index.rb b/rubocop/cop/migration/add_concurrent_index.rb
index 332fb7dcbd7..69852f4d580 100644
--- a/rubocop/cop/migration/add_concurrent_index.rb
+++ b/rubocop/cop/migration/add_concurrent_index.rb
@@ -9,7 +9,7 @@ module RuboCop
include MigrationHelpers
MSG = '`add_concurrent_index` is not reversible so you must manually define ' \
- 'the `up` and `down` methods in your migration class, using `remove_index` in `down`'.freeze
+ 'the `up` and `down` methods in your migration class, using `remove_concurrent_index` in `down`'.freeze
def on_send(node)
return unless in_migration?(node)
diff --git a/rubocop/cop/migration/remove_concurrent_index.rb b/rubocop/cop/migration/remove_concurrent_index.rb
new file mode 100644
index 00000000000..268c49865cb
--- /dev/null
+++ b/rubocop/cop/migration/remove_concurrent_index.rb
@@ -0,0 +1,29 @@
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ # Cop that checks if `remove_concurrent_index` is used with `up`/`down` methods
+ # and not `change`.
+ class RemoveConcurrentIndex < RuboCop::Cop::Cop
+ include MigrationHelpers
+
+ MSG = '`remove_concurrent_index` is not reversible so you must manually define ' \
+ 'the `up` and `down` methods in your migration class, using `add_concurrent_index` in `down`'.freeze
+
+ def on_send(node)
+ return unless in_migration?(node)
+ return unless node.children[1] == :remove_concurrent_index
+
+ node.each_ancestor(:def) do |def_node|
+ add_offense(def_node, :name) if method_name(def_node) == :change
+ end
+ end
+
+ def method_name(node)
+ node.children[0]
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/migration/remove_index.rb b/rubocop/cop/migration/remove_index.rb
new file mode 100644
index 00000000000..613b35dd00d
--- /dev/null
+++ b/rubocop/cop/migration/remove_index.rb
@@ -0,0 +1,26 @@
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ # Cop that checks if indexes are removed in a concurrent manner.
+ class RemoveIndex < RuboCop::Cop::Cop
+ include MigrationHelpers
+
+ MSG = '`remove_index` requires downtime, use `remove_concurrent_index` instead'.freeze
+
+ def on_def(node)
+ return unless in_migration?(node)
+
+ node.each_descendant(:send) do |send_node|
+ add_offense(send_node, :selector) if method_name(send_node) == :remove_index
+ end
+ end
+
+ def method_name(node)
+ node.children[1]
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb
index a50a522cf9d..d580aa6857a 100644
--- a/rubocop/rubocop.rb
+++ b/rubocop/rubocop.rb
@@ -5,3 +5,5 @@ require_relative 'cop/migration/add_column_with_default'
require_relative 'cop/migration/add_concurrent_foreign_key'
require_relative 'cop/migration/add_concurrent_index'
require_relative 'cop/migration/add_index'
+require_relative 'cop/migration/remove_concurrent_index'
+require_relative 'cop/migration/remove_index'