Skip to content
代码片段 群组 项目
提交 abd050b7 编辑于 作者: Leonardo da Rosa's avatar Leonardo da Rosa 提交者: Peter Leitzen
浏览文件

Adds a new cop to check the use of finalize_background_migration method

It prevents the usage of this deprecated method
上级 9289fe04
No related branches found
No related tags found
无相关合并请求
...@@ -935,6 +935,10 @@ Migration/BackgroundMigrationBaseClass: ...@@ -935,6 +935,10 @@ Migration/BackgroundMigrationBaseClass:
BackgroundMigration/AvoidSilentRescueExceptions: BackgroundMigration/AvoidSilentRescueExceptions:
Enabled: false Enabled: false
Migration/AvoidFinalizeBackgroundMigration:
Include:
- 'db/post_migrate/*.rb'
Style/ClassAndModuleChildren: Style/ClassAndModuleChildren:
Enabled: true Enabled: true
......
---
Migration/AvoidFinalizeBackgroundMigration:
Details: grace period
Exclude:
- 'db/post_migrate/20220502015011_clean_up_fix_merge_request_diff_commit_users.rb'
- 'db/post_migrate/20220525131557_cleanup_backfill_integrations_enable_ssl_verification.rb'
- 'db/post_migrate/20220713133515_cleanup_backfill_draft_statuses_on_merge_requests.rb'
# frozen_string_literal: true
require_relative '../../migration_helpers'
module RuboCop
module Cop
module Migration
class AvoidFinalizeBackgroundMigration < RuboCop::Cop::Base
include MigrationHelpers
RESTRICT_ON_SEND = [:finalize_background_migration].freeze
MSG = 'Prefer `ensure_batched_background_migration_is_finished` over ' \
'`finalize_background_migration` in Batched Background Migrations. ' \
'See https://docs.gitlab.com/ee/development/database/batched_background_migrations.html'
def on_send(node)
add_offense(node)
end
end
end
end
end
# frozen_string_literal: true
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/avoid_finalize_background_migration'
RSpec.describe RuboCop::Cop::Migration::AvoidFinalizeBackgroundMigration, feature_category: :database do
context 'when file is under db/post_migration' do
it "flags the use of 'finalize_background_migration' method" do
expect_offense(<<~RUBY)
class FinalizeMyMigration < Gitlab::Database::Migration[2.1]
MIGRATION = 'MyMigration'
def up
finalize_background_migration(MIGRATION)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
end
end
RUBY
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册