summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/migration/update_large_table.rb (renamed from rubocop/cop/migration/add_column_with_default_to_large_table.rb)22
-rw-r--r--rubocop/rubocop.rb2
2 files changed, 13 insertions, 11 deletions
diff --git a/rubocop/cop/migration/add_column_with_default_to_large_table.rb b/rubocop/cop/migration/update_large_table.rb
index fb363f95b56..3ae3fb1b68e 100644
--- a/rubocop/cop/migration/add_column_with_default_to_large_table.rb
+++ b/rubocop/cop/migration/update_large_table.rb
@@ -12,12 +12,12 @@ module RuboCop
#
# See https://gitlab.com/gitlab-com/infrastructure/issues/1602 for more
# information.
- class AddColumnWithDefaultToLargeTable < RuboCop::Cop::Cop
+ class UpdateLargeTable < RuboCop::Cop::Cop
include MigrationHelpers
- MSG = 'Using `add_column_with_default` on the `%s` table will take a ' \
- 'long time to complete, and should be avoided unless absolutely ' \
- 'necessary'.freeze
+ MSG = 'Using `%s` on the `%s` table will take a long time to ' \
+ 'complete, and should be avoided unless absolutely ' \
+ 'necessary'.freeze
LARGE_TABLES = %i[
ci_pipelines
@@ -34,20 +34,22 @@ module RuboCop
users
].freeze
- def_node_matcher :add_column_with_default?, <<~PATTERN
- (send nil :add_column_with_default $(sym ...) ...)
+ def_node_matcher :batch_update?, <<~PATTERN
+ (send nil ${:add_column_with_default :update_column_in_batches} $(sym ...) ...)
PATTERN
def on_send(node)
return unless in_migration?(node)
- matched = add_column_with_default?(node)
- return unless matched
+ matches = batch_update?(node)
+ return unless matches
+
+ update_method = matches.first
+ table = matches.last.to_a.first
- table = matched.to_a.first
return unless LARGE_TABLES.include?(table)
- add_offense(node, :expression, format(MSG, table))
+ add_offense(node, :expression, format(MSG, update_method, table))
end
end
end
diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb
index 4ebbe010e90..a1668749dd9 100644
--- a/rubocop/rubocop.rb
+++ b/rubocop/rubocop.rb
@@ -7,7 +7,6 @@ require_relative 'cop/polymorphic_associations'
require_relative 'cop/project_path_helper'
require_relative 'cop/redirect_with_status'
require_relative 'cop/migration/add_column'
-require_relative 'cop/migration/add_column_with_default_to_large_table'
require_relative 'cop/migration/add_concurrent_foreign_key'
require_relative 'cop/migration/add_concurrent_index'
require_relative 'cop/migration/add_index'
@@ -20,6 +19,7 @@ require_relative 'cop/migration/reversible_add_column_with_default'
require_relative 'cop/migration/safer_boolean_column'
require_relative 'cop/migration/timestamps'
require_relative 'cop/migration/update_column_in_batches'
+require_relative 'cop/migration/update_large_table'
require_relative 'cop/rspec/env_assignment'
require_relative 'cop/rspec/single_line_hook'
require_relative 'cop/rspec/verbose_include_metadata'