diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 03:09:56 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 03:09:56 +0300 |
commit | cc626f14115f740bd4aa247cf3ac42dfb2082a4e (patch) | |
tree | b5c7f25711903177ea0e756b1fabd8eef2a9ca14 /rubocop | |
parent | 19db7fd1fefc4e4249d4e55f409f321fdb85aed1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/migration/batch_migrations_post_only.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/rubocop/cop/migration/batch_migrations_post_only.rb b/rubocop/cop/migration/batch_migrations_post_only.rb new file mode 100644 index 00000000000..3a1f3b64d75 --- /dev/null +++ b/rubocop/cop/migration/batch_migrations_post_only.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require_relative '../../migration_helpers' + +module RuboCop + module Cop + module Migration + # Cop that checks that no background batched migration helpers are called by regular migrations. + class BatchMigrationsPostOnly < RuboCop::Cop::Base + include MigrationHelpers + + MSG = "This method must only be used in post-deployment migrations." + + FORBIDDEN_METHODS = %w[ + ensure_batched_background_migration_is_finished + queue_batched_background_migration + delete_batched_background_migration + finalize_batched_background_migration + ].freeze + + SYMBOLIZED_MATCHER = FORBIDDEN_METHODS.map { |w| ":#{w}" }.join(' | ') + + def_node_matcher :on_forbidden_method, <<~PATTERN + (send nil? {#{SYMBOLIZED_MATCHER}} ...) + PATTERN + + def on_send(node) + on_forbidden_method(node) do + break if in_post_deployment_migration?(node) + + add_offense(node, message: MSG) + end + end + end + end + end +end |