diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 18:09:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 18:09:35 +0000 |
commit | 5bfb8d1fad825eec90b0af688c7cd1b352c9056e (patch) | |
tree | 385411919c4186d11a769385ad8dafeef6cc36a7 /rubocop | |
parent | aaf59610548d9b0fd01acfd50e831cbe519ecba2 (diff) | |
download | gitlab-ce-5bfb8d1fad825eec90b0af688c7cd1b352c9056e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/migration/add_column.rb | 5 | ||||
-rw-r--r-- | rubocop/cop/migration/add_column_with_default.rb | 32 | ||||
-rw-r--r-- | rubocop/cop/migration/safer_boolean_column.rb | 6 | ||||
-rw-r--r-- | rubocop/cop/migration/update_large_table.rb | 22 | ||||
-rw-r--r-- | rubocop/migration_helpers.rb | 43 |
5 files changed, 45 insertions, 63 deletions
diff --git a/rubocop/cop/migration/add_column.rb b/rubocop/cop/migration/add_column.rb index a25bd843559..0af90fb7fd1 100644 --- a/rubocop/cop/migration/add_column.rb +++ b/rubocop/cop/migration/add_column.rb @@ -8,11 +8,6 @@ module RuboCop class AddColumn < RuboCop::Cop::Cop include MigrationHelpers - WHITELISTED_TABLES = %i[ - application_settings - plan_limits - ].freeze - MSG = '`add_column` with a default value requires downtime, ' \ 'use `add_column_with_default` instead'.freeze diff --git a/rubocop/cop/migration/add_column_with_default.rb b/rubocop/cop/migration/add_column_with_default.rb index 68e53b17f19..383653ef5a5 100644 --- a/rubocop/cop/migration/add_column_with_default.rb +++ b/rubocop/cop/migration/add_column_with_default.rb @@ -10,38 +10,6 @@ module RuboCop class AddColumnWithDefault < RuboCop::Cop::Cop include MigrationHelpers - # Tables >= 10 GB on GitLab.com as of 02/2020 - BLACKLISTED_TABLES = %i[ - audit_events - ci_build_trace_sections - ci_builds - ci_builds_metadata - ci_job_artifacts - ci_pipeline_variables - ci_pipelines - ci_stages - deployments - events - issues - merge_request_diff_commits - merge_request_diff_files - merge_request_diffs - merge_request_metrics - merge_requests - note_diff_files - notes - project_authorizations - projects - push_event_payloads - resource_label_events - sent_notifications - system_note_metadata - taggings - todos - users - web_hook_logs - ].freeze - MSG = '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, ' \ 'see https://gitlab.com/gitlab-org/gitlab/issues/38060'.freeze diff --git a/rubocop/cop/migration/safer_boolean_column.rb b/rubocop/cop/migration/safer_boolean_column.rb index fa524efe5be..25aaf42d00e 100644 --- a/rubocop/cop/migration/safer_boolean_column.rb +++ b/rubocop/cop/migration/safer_boolean_column.rb @@ -23,10 +23,6 @@ module RuboCop NULL_OFFENSE = 'Boolean columns on the `%s` table should disallow nulls.'.freeze DEFAULT_AND_NULL_OFFENSE = 'Boolean columns on the `%s` table should have a default and should disallow nulls. You may wish to use `add_column_with_default`.'.freeze - SMALL_TABLES = %i[ - application_settings - ].freeze - def_node_matcher :add_column?, <<~PATTERN (send nil? :add_column $...) PATTERN @@ -41,7 +37,7 @@ module RuboCop table, _, type = matched.to_a.take(3).map(&:children).map(&:first) opts = matched[3] - return unless SMALL_TABLES.include?(table) && type == :boolean + return unless WHITELISTED_TABLES.include?(table) && type == :boolean no_default = no_default?(opts) nulls_allowed = nulls_allowed?(opts) diff --git a/rubocop/cop/migration/update_large_table.rb b/rubocop/cop/migration/update_large_table.rb index 94bba31c249..e44eadbdb92 100644 --- a/rubocop/cop/migration/update_large_table.rb +++ b/rubocop/cop/migration/update_large_table.rb @@ -19,26 +19,6 @@ module RuboCop 'complete, and should be avoided unless absolutely ' \ 'necessary'.freeze - LARGE_TABLES = %i[ - 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 - namespaces - notes - projects - project_ci_cd_settings - routes - users - ].freeze - BATCH_UPDATE_METHODS = %w[ :add_column_with_default :change_column_type_concurrently @@ -59,7 +39,7 @@ module RuboCop update_method = matches.first table = matches.last.to_a.first - return unless LARGE_TABLES.include?(table) + return unless BLACKLISTED_TABLES.include?(table) add_offense(node, location: :expression, message: format(MSG, update_method, table)) end diff --git a/rubocop/migration_helpers.rb b/rubocop/migration_helpers.rb index 767cacaecaf..b5edb502d4c 100644 --- a/rubocop/migration_helpers.rb +++ b/rubocop/migration_helpers.rb @@ -1,6 +1,49 @@ module RuboCop # Module containing helper methods for writing migration cops. module MigrationHelpers + WHITELISTED_TABLES = %i[ + application_settings + plan_limits + ].freeze + + # Blacklisted table due to: + # - size in GB (>= 10 GB on GitLab.com as of 02/2020) + # - number of records + BLACKLISTED_TABLES = %i[ + audit_events + ci_build_trace_sections + ci_builds + ci_builds_metadata + ci_job_artifacts + ci_pipeline_variables + ci_pipelines + ci_stages + deployments + events + issues + merge_request_diff_commits + merge_request_diff_files + merge_request_diffs + merge_request_metrics + merge_requests + namespaces + note_diff_files + notes + project_authorizations + projects + project_ci_cd_settings + push_event_payloads + resource_label_events + routes + sent_notifications + services + system_note_metadata + taggings + todos + users + web_hook_logs + ].freeze + # Returns true if the given node originated from the db/migrate directory. def in_migration?(node) dirname(node).end_with?('db/migrate', 'db/geo/migrate') || in_post_deployment_migration?(node) |