Commit d3059622 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'update-large-tables-cop' into 'master'

Disallow methods that copy data on large tables

See merge request gitlab-org/gitlab-ce!20021
parents f855cbf6 03ccd39a
...@@ -20,10 +20,14 @@ module RuboCop ...@@ -20,10 +20,14 @@ module RuboCop
'necessary'.freeze 'necessary'.freeze
LARGE_TABLES = %i[ LARGE_TABLES = %i[
ci_pipelines ci_build_trace_sections
ci_builds ci_builds
ci_job_artifacts
ci_pipelines
ci_stages
events events
issues issues
merge_request_diff_commits
merge_request_diff_files merge_request_diff_files
merge_request_diffs merge_request_diffs
merge_requests merge_requests
...@@ -34,8 +38,15 @@ module RuboCop ...@@ -34,8 +38,15 @@ module RuboCop
users users
].freeze ].freeze
BATCH_UPDATE_METHODS = %w[
:add_column_with_default
:change_column_type_concurrently
:rename_column_concurrently
:update_column_in_batches
].join(' ').freeze
def_node_matcher :batch_update?, <<~PATTERN def_node_matcher :batch_update?, <<~PATTERN
(send nil? ${:add_column_with_default :update_column_in_batches} $(sym ...) ...) (send nil? ${#{BATCH_UPDATE_METHODS}} $(sym ...) ...)
PATTERN PATTERN
def on_send(node) def on_send(node)
......
...@@ -32,6 +32,14 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do ...@@ -32,6 +32,14 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
include_examples 'large tables', 'add_column_with_default' include_examples 'large tables', 'add_column_with_default'
end end
context 'for the change_column_type_concurrently method' do
include_examples 'large tables', 'change_column_type_concurrently'
end
context 'for the rename_column_concurrently method' do
include_examples 'large tables', 'rename_column_concurrently'
end
context 'for the update_column_in_batches method' do context 'for the update_column_in_batches method' do
include_examples 'large tables', 'update_column_in_batches' include_examples 'large tables', 'update_column_in_batches'
end end
...@@ -60,6 +68,18 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do ...@@ -60,6 +68,18 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
expect(cop.offenses).to be_empty expect(cop.offenses).to be_empty
end end
it 'registers no offense for change_column_type_concurrently' do
inspect_source("change_column_type_concurrently :#{table}, :column, default: true")
expect(cop.offenses).to be_empty
end
it 'registers no offense for update_column_in_batches' do
inspect_source("rename_column_concurrently :#{table}, :column, default: true")
expect(cop.offenses).to be_empty
end
it 'registers no offense for update_column_in_batches' do it 'registers no offense for update_column_in_batches' do
inspect_source("add_column_with_default :#{table}, :column, default: true") inspect_source("add_column_with_default :#{table}, :column, default: true")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment