From eb086a4bfd2495168483a2652571f247e6b768a5 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 19 Jun 2018 17:18:15 +0100 Subject: Disallow methods that copy data on large tables {change_column_type,rename_column}_concurrently both copy data from one column to another during a migration, which should not be done on GitLab.com. Instead, we should use background migrations. --- rubocop/cop/migration/update_large_table.rb | 9 ++++++++- .../rubocop/cop/migration/update_large_table_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/rubocop/cop/migration/update_large_table.rb b/rubocop/cop/migration/update_large_table.rb index bb14d0f4f56..e3e3de0a4d7 100644 --- a/rubocop/cop/migration/update_large_table.rb +++ b/rubocop/cop/migration/update_large_table.rb @@ -34,8 +34,15 @@ module RuboCop users ].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 - (send nil? ${:add_column_with_default :update_column_in_batches} $(sym ...) ...) + (send nil? ${#{BATCH_UPDATE_METHODS}} $(sym ...) ...) PATTERN def on_send(node) diff --git a/spec/rubocop/cop/migration/update_large_table_spec.rb b/spec/rubocop/cop/migration/update_large_table_spec.rb index ef724fc8bad..5e08eb4f772 100644 --- a/spec/rubocop/cop/migration/update_large_table_spec.rb +++ b/spec/rubocop/cop/migration/update_large_table_spec.rb @@ -32,6 +32,14 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do include_examples 'large tables', 'add_column_with_default' 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 include_examples 'large tables', 'update_column_in_batches' end @@ -60,6 +68,18 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do expect(cop.offenses).to be_empty 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 inspect_source("add_column_with_default :#{table}, :column, default: true") -- cgit v1.2.1 From 03ccd39a0ccafe79df50702464ff02d3ca0312c4 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 22 Jun 2018 11:09:46 +0100 Subject: Add more large tables to cop These are all over 20 GB on GitLab.com. merge_request_diff_commits is several hundred gigabytes in size. --- rubocop/cop/migration/update_large_table.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rubocop/cop/migration/update_large_table.rb b/rubocop/cop/migration/update_large_table.rb index e3e3de0a4d7..c15eec22d04 100644 --- a/rubocop/cop/migration/update_large_table.rb +++ b/rubocop/cop/migration/update_large_table.rb @@ -20,10 +20,14 @@ module RuboCop 'necessary'.freeze LARGE_TABLES = %i[ - ci_pipelines + ci_build_trace_sections ci_builds + ci_job_artifacts + ci_pipelines + ci_stages events issues + merge_request_diff_commits merge_request_diff_files merge_request_diffs merge_requests -- cgit v1.2.1