diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /rubocop/cop/migration | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) | |
download | gitlab-ce-e8d2c2579383897a1dd7f9debd359abe8ae8373d.tar.gz |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'rubocop/cop/migration')
-rw-r--r-- | rubocop/cop/migration/prevent_index_creation.rb | 41 | ||||
-rw-r--r-- | rubocop/cop/migration/sidekiq_queue_migrate.rb | 29 | ||||
-rw-r--r-- | rubocop/cop/migration/with_lock_retries_disallowed_method.rb | 1 |
3 files changed, 71 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 diff --git a/rubocop/cop/migration/sidekiq_queue_migrate.rb b/rubocop/cop/migration/sidekiq_queue_migrate.rb new file mode 100644 index 00000000000..134bda590da --- /dev/null +++ b/rubocop/cop/migration/sidekiq_queue_migrate.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require_relative '../../migration_helpers' + +module RuboCop + module Cop + module Migration + # Cop that checks if sidekiq_queue_migrate is used in a regular + # (not post-deployment) migration. + class SidekiqQueueMigrate < RuboCop::Cop::Cop + include MigrationHelpers + + MSG = '`sidekiq_queue_migrate` must only be used in post-deployment migrations' + + def on_def(node) + return unless in_migration?(node) && !in_post_deployment_migration?(node) + + node.each_descendant(:send) do |send_node| + send_method = send_node.children[1] + + if send_method == :sidekiq_queue_migrate + add_offense(send_node, location: :selector) + end + end + end + end + end + end +end diff --git a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb index cb36e7413ab..b3d05ad1a6d 100644 --- a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb +++ b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb @@ -22,6 +22,7 @@ module RuboCop remove_foreign_key_if_exists remove_foreign_key_without_error rename_index + rename_constraint table_exists? index_exists_by_name? foreign_key_exists? |