Class: Gitlab::Styles::Rubocop::Cop::Migration::UpdateLargeTable

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
MigrationHelpers
Defined in:
lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb

Overview

This cop checks for methods that may lead to batch type issues on a table that’s been explicitly denied because of its size.

Even though though these methods perform functions to avoid downtime, using it with tables with millions of rows still causes a significant delay in the deploy process and is best avoided.

See gitlab.com/gitlab-com/infrastructure/issues/1602 for more information.

Constant Summary collapse

MSG =
'Using `%s` on the `%s` table will take a long time to ' \
'complete, and should be avoided unless absolutely ' \
'necessary'

Instance Method Summary collapse

Methods included from MigrationHelpers

#in_migration?

Instance Method Details

#on_send(node) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb', line 31

def on_send(node)
  return if denied_tables.empty? || denied_methods.empty?
  return unless in_migration?(node)

  matches = batch_update?(node)
  return unless matches

  update_method = matches.first
  table = matches.last.to_a.first

  return unless denied_tables.include?(table)

  add_offense(node, message: format(MSG, update_method, table))
end