Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-09 21:09:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-09 21:09:51 +0300
commit6a05cc3fd5c58a17d61ff25bb70b27089d68b99f (patch)
treecd21248b6b3f1b7c829b535fe41ce58eddd327ad /rubocop
parentffd8742a62c5de81792942cd7f9031b1add6cab2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/migration/prevent_index_creation.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/rubocop/cop/migration/prevent_index_creation.rb b/rubocop/cop/migration/prevent_index_creation.rb
new file mode 100644
index 00000000000..c90f911d24e
--- /dev/null
+++ b/rubocop/cop/migration/prevent_index_creation.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ # Cop that checks if new indexes are introduced to forbidden tables.
+ class PreventIndexCreation < RuboCop::Cop::Cop
+ include MigrationHelpers
+
+ FORBIDDEN_TABLES = %i[ci_builds].freeze
+
+ MSG = "Adding new index to #{FORBIDDEN_TABLES.join(", ")} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886"
+
+ def_node_matcher :add_index?, <<~PATTERN
+ (send nil? :add_index (sym #forbidden_tables?) ...)
+ PATTERN
+
+ def_node_matcher :add_concurrent_index?, <<~PATTERN
+ (send nil? :add_concurrent_index (sym #forbidden_tables?) ...)
+ PATTERN
+
+ def forbidden_tables?(node)
+ FORBIDDEN_TABLES.include?(node)
+ end
+
+ def on_def(node)
+ return unless in_migration?(node)
+
+ node.each_descendant(:send) do |send_node|
+ add_offense(send_node, location: :selector) if offense?(send_node)
+ end
+ end
+
+ def offense?(node)
+ add_index?(node) || add_concurrent_index?(node)
+ end
+ end
+ end
+ end
+end