From 3335006cb7ed6363b7c15930f9f7b8d77579cf05 Mon Sep 17 00:00:00 2001 From: Max Orefice <morefice@gitlab.com> Date: Mon, 2 Dec 2024 11:26:00 +0000 Subject: [PATCH] Update PreventAddingColumns cop --- ...lnerability_count_into_sbom_occurrences.rb | 4 +- ...33539_create_sbom_source_packages_table.rb | 2 - ...fications_on_issue_email_participant_id.rb | 2 - ...839_add_partition_id_to_pipeline_config.rb | 2 - ...aversal_ids_columns_to_sbom_occurrences.rb | 4 -- ...dd_ancestors_column_to_sbom_occurrences.rb | 2 - ...le_final_path_to_packages_package_files.rb | 2 - ...add_partition_id_to_ci_pipeline_message.rb | 2 - ...20240517192053_add_advanced_token_scope.rb | 2 - ...anceled_by_partition_id_to_ci_pipelines.rb | 4 +- ...dd_project_id_to_packages_package_files.rb | 2 +- ...d_to_vulnerability_occurrence_pipelines.rb | 2 +- ...o_merge_request_diff_commits_b5377a7a34.rb | 2 - ...d_to_merge_request_diff_files99208b8fac.rb | 2 +- ...ganization_id_to_personal_access_tokens.rb | 2 - ...ability_column_to_sbom_occurances_table.rb | 2 +- ...fication_cols_to_personal_access_tokens.rb | 6 -- ..._add_project_id_to_ci_pipeline_messages.rb | 2 +- ...53_add_auto_resolved_to_vulnerabilities.rb | 2 - ...ge_request_diffs_project_id_index_async.rb | 2 - ...dd_merge_request_diffs_project_id_index.rb | 2 - ...re_iid_namespace_unique_index_in_issues.rb | 2 - ...dd_iid_namespace_unique_index_to_issues.rb | 2 - ...hor_group_action_target_type_created_at.rb | 2 - ...237_add_index_to_ci_job_artifact_states.rb | 2 + ...08_add_index_to_ci_build_trace_metadata.rb | 2 - ..._with_project_id_on_vulnerability_reads.rb | 2 - ..._events_author_group_action_target_type.rb | 2 - ...ndex_on_issues_table_tmp_epic_id_column.rb | 2 - ...dex_merge_requests_on_unmerged_state_id.rb | 2 - ...dex_merge_requests_on_unmerged_state_id.rb | 2 - ...rt_type_severity_traversal_ids_archived.rb | 2 - ...lity_reads_for_common_group_level_query.rb | 2 - ...14121644_replace_issues_milestone_index.rb | 2 - ...ues_milestone_and_id_index_concurrently.rb | 2 - ...ulnerability_occurences_on_prim_iden_id.rb | 3 +- ...ex_owasp_top_10_for_group_level_reports.rb | 3 +- ...033346_tmp_index_on_vulnerability_reads.rb | 3 +- ...lnerability_finding_links_on_project_id.rb | 3 +- ...lity_occurrence_pipelines_on_project_id.rb | 3 +- ..._index_for_owasp_on_vulnerability_reads.rb | 3 +- ...dx_owasp_top_10_for_group_level_reports.rb | 3 +- ...index_on_events_personal_namespace_id_2.rb | 3 +- ...ents_personal_namespace_id_self_managed.rb | 3 +- ...ex_ci_job_artifact_states_on_project_id.rb | 2 + ...ulnerability_reads_for_filtered_removal.rb | 3 +- ...es_by_project_correct_type_where_closed.rb | 2 +- ...oject_health_id_desc_state_correct_type.rb | 2 +- ...roject_health_id_asc_state_correct_type.rb | 2 +- ...s_correct_type_project_created_at_state.rb | 2 +- ...es_by_project_correct_type_where_closed.rb | 2 +- ...oject_health_id_desc_state_correct_type.rb | 2 +- ...roject_health_id_asc_state_correct_type.rb | 2 +- ...s_correct_type_project_created_at_state.rb | 2 +- ...te_sent_notifications_index_on_noteable.rb | 3 +- .../cop/migration/prevent_adding_columns.rb | 8 +-- rubocop/migration_helpers.rb | 4 ++ rubocop/rubocop-migrations.yml | 57 +++++++++++-------- .../migration/prevent_adding_columns_spec.rb | 16 +++--- .../migration/prevent_index_creation_spec.rb | 31 ++-------- 60 files changed, 88 insertions(+), 159 deletions(-) diff --git a/db/migrate/20231031114050_add_highest_severity_and_vulnerability_count_into_sbom_occurrences.rb b/db/migrate/20231031114050_add_highest_severity_and_vulnerability_count_into_sbom_occurrences.rb index 621db3aea567b..7b33d31b642f9 100644 --- a/db/migrate/20231031114050_add_highest_severity_and_vulnerability_count_into_sbom_occurrences.rb +++ b/db/migrate/20231031114050_add_highest_severity_and_vulnerability_count_into_sbom_occurrences.rb @@ -4,9 +4,7 @@ class AddHighestSeverityAndVulnerabilityCountIntoSbomOccurrences < Gitlab::Datab milestone '16.7' def change - add_column :sbom_occurrences, :highest_severity, :smallint, null: true # rubocop:disable Migration/PreventAddingColumns -- Legacy migration - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + add_column :sbom_occurrences, :highest_severity, :smallint, null: true add_column :sbom_occurrences, :vulnerability_count, :integer, null: false, default: 0 - # rubocop:enable Migration/PreventAddingColumns end end diff --git a/db/migrate/20231221033539_create_sbom_source_packages_table.rb b/db/migrate/20231221033539_create_sbom_source_packages_table.rb index 382fe22d60e73..2528102270c31 100644 --- a/db/migrate/20231221033539_create_sbom_source_packages_table.rb +++ b/db/migrate/20231221033539_create_sbom_source_packages_table.rb @@ -13,9 +13,7 @@ class CreateSbomSourcePackagesTable < Gitlab::Database::Migration[2.2] # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up with_lock_retries do - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :sbom_occurrences, :source_package_id, :bigint, if_not_exists: true - # rubocop:enable Migration/PreventAddingColumns end create_table :sbom_source_packages, if_not_exists: true do |t| diff --git a/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb b/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb index f7d17a28c12a8..c9b755294702d 100644 --- a/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb +++ b/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb @@ -7,11 +7,9 @@ class AddIndexSentNotificationsOnIssueEmailParticipantId < Gitlab::Database::Mig INDEX_NAME = 'index_sent_notifications_on_issue_email_participant_id' - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up add_concurrent_index :sent_notifications, :issue_email_participant_id, name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name :sent_notifications, INDEX_NAME diff --git a/db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb b/db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb index 943ff8d60802b..e4f661a5e31e3 100644 --- a/db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb +++ b/db/migrate/20240109145839_add_partition_id_to_pipeline_config.rb @@ -5,8 +5,6 @@ class AddPartitionIdToPipelineConfig < Gitlab::Database::Migration[2.2] enable_lock_retries! def change - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column(:ci_pipelines_config, :partition_id, :bigint, default: 100, null: false) - # rubocop:enable Migration/PreventAddingColumns end end diff --git a/db/migrate/20240129175101_add_archived_and_traversal_ids_columns_to_sbom_occurrences.rb b/db/migrate/20240129175101_add_archived_and_traversal_ids_columns_to_sbom_occurrences.rb index fa95155580fb7..4e5cc8736da52 100644 --- a/db/migrate/20240129175101_add_archived_and_traversal_ids_columns_to_sbom_occurrences.rb +++ b/db/migrate/20240129175101_add_archived_and_traversal_ids_columns_to_sbom_occurrences.rb @@ -4,11 +4,7 @@ class AddArchivedAndTraversalIdsColumnsToSbomOccurrences < Gitlab::Database::Mig milestone '16.9' def change - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :sbom_occurrences, :archived, :boolean, default: false, null: false - # rubocop:enable Migration/PreventAddingColumns - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :sbom_occurrences, :traversal_ids, 'bigint[]', default: [], null: false - # rubocop:enable Migration/PreventAddingColumns end end diff --git a/db/migrate/20240212170304_add_ancestors_column_to_sbom_occurrences.rb b/db/migrate/20240212170304_add_ancestors_column_to_sbom_occurrences.rb index d5ba53f31122a..459ce27da3812 100644 --- a/db/migrate/20240212170304_add_ancestors_column_to_sbom_occurrences.rb +++ b/db/migrate/20240212170304_add_ancestors_column_to_sbom_occurrences.rb @@ -6,9 +6,7 @@ class AddAncestorsColumnToSbomOccurrences < Gitlab::Database::Migration[2.2] enable_lock_retries! def up - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :sbom_occurrences, :ancestors, :jsonb, default: [], null: false - # rubocop:enable Migration/PreventAddingColumns end def down diff --git a/db/migrate/20240320110318_add_file_final_path_to_packages_package_files.rb b/db/migrate/20240320110318_add_file_final_path_to_packages_package_files.rb index 0bd245137bcf4..2f9c166ea2523 100644 --- a/db/migrate/20240320110318_add_file_final_path_to_packages_package_files.rb +++ b/db/migrate/20240320110318_add_file_final_path_to_packages_package_files.rb @@ -6,9 +6,7 @@ class AddFileFinalPathToPackagesPackageFiles < Gitlab::Database::Migration[2.2] def up with_lock_retries do - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :packages_package_files, :file_final_path, :text, if_not_exists: true - # rubocop:enable Migration/PreventAddingColumns end add_text_limit :packages_package_files, :file_final_path, 1024 diff --git a/db/migrate/20240516133122_add_partition_id_to_ci_pipeline_message.rb b/db/migrate/20240516133122_add_partition_id_to_ci_pipeline_message.rb index 11e39dd06407e..1b29d339e63ec 100644 --- a/db/migrate/20240516133122_add_partition_id_to_ci_pipeline_message.rb +++ b/db/migrate/20240516133122_add_partition_id_to_ci_pipeline_message.rb @@ -4,8 +4,6 @@ class AddPartitionIdToCiPipelineMessage < Gitlab::Database::Migration[2.2] milestone '17.1' def change - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column(:ci_pipeline_messages, :partition_id, :bigint, default: 100, null: false) - # rubocop:enable Migration/PreventAddingColumns end end diff --git a/db/migrate/20240517192053_add_advanced_token_scope.rb b/db/migrate/20240517192053_add_advanced_token_scope.rb index e6b85b9fc64f1..fb34cdcaea94f 100644 --- a/db/migrate/20240517192053_add_advanced_token_scope.rb +++ b/db/migrate/20240517192053_add_advanced_token_scope.rb @@ -7,9 +7,7 @@ class AddAdvancedTokenScope < Gitlab::Database::Migration[2.2] def up with_lock_retries do - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :personal_access_tokens, :advanced_scopes, :text, if_not_exists: true - # rubocop:enable Migration/PreventAddingColumns end add_text_limit :personal_access_tokens, :advanced_scopes, 4096 diff --git a/db/migrate/20240627121919_add_auto_canceled_by_partition_id_to_ci_pipelines.rb b/db/migrate/20240627121919_add_auto_canceled_by_partition_id_to_ci_pipelines.rb index 035046c0d3960..10e95433bb213 100644 --- a/db/migrate/20240627121919_add_auto_canceled_by_partition_id_to_ci_pipelines.rb +++ b/db/migrate/20240627121919_add_auto_canceled_by_partition_id_to_ci_pipelines.rb @@ -4,6 +4,8 @@ class AddAutoCanceledByPartitionIdToCiPipelines < Gitlab::Database::Migration[2. milestone '17.2' def change - add_column :ci_pipelines, :auto_canceled_by_partition_id, :bigint # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + add_column :ci_pipelines, :auto_canceled_by_partition_id, :bigint + # rubocop:enable Migration/PreventAddingColumns end end diff --git a/db/migrate/20240729130349_add_project_id_to_packages_package_files.rb b/db/migrate/20240729130349_add_project_id_to_packages_package_files.rb index 97b5f22de226e..264f28f888610 100644 --- a/db/migrate/20240729130349_add_project_id_to_packages_package_files.rb +++ b/db/migrate/20240729130349_add_project_id_to_packages_package_files.rb @@ -4,6 +4,6 @@ class AddProjectIdToPackagesPackageFiles < Gitlab::Database::Migration[2.2] milestone '17.3' def change - add_column :packages_package_files, :project_id, :bigint # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + add_column :packages_package_files, :project_id, :bigint end end diff --git a/db/migrate/20240730172815_add_project_id_to_vulnerability_occurrence_pipelines.rb b/db/migrate/20240730172815_add_project_id_to_vulnerability_occurrence_pipelines.rb index 32cfb192daf3c..5b54c0fc3a267 100644 --- a/db/migrate/20240730172815_add_project_id_to_vulnerability_occurrence_pipelines.rb +++ b/db/migrate/20240730172815_add_project_id_to_vulnerability_occurrence_pipelines.rb @@ -4,6 +4,6 @@ class AddProjectIdToVulnerabilityOccurrencePipelines < Gitlab::Database::Migrati milestone '17.3' def change - add_column :vulnerability_occurrence_pipelines, :project_id, :bigint # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + add_column :vulnerability_occurrence_pipelines, :project_id, :bigint end end diff --git a/db/migrate/20240802194745_add_project_id_to_merge_request_diff_commits_b5377a7a34.rb b/db/migrate/20240802194745_add_project_id_to_merge_request_diff_commits_b5377a7a34.rb index 8c52ceb9141e6..9072b546eeeba 100644 --- a/db/migrate/20240802194745_add_project_id_to_merge_request_diff_commits_b5377a7a34.rb +++ b/db/migrate/20240802194745_add_project_id_to_merge_request_diff_commits_b5377a7a34.rb @@ -4,9 +4,7 @@ class AddProjectIdToMergeRequestDiffCommitsB5377a7a34 < Gitlab::Database::Migrat milestone '17.3' def up - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :merge_request_diff_commits_b5377a7a34, :project_id, :bigint - # rubocop:enable Migration/PreventAddingColumns end def down diff --git a/db/migrate/20240802203135_add_project_id_to_merge_request_diff_files99208b8fac.rb b/db/migrate/20240802203135_add_project_id_to_merge_request_diff_files99208b8fac.rb index 63067fa28351f..77520c16be63d 100644 --- a/db/migrate/20240802203135_add_project_id_to_merge_request_diff_files99208b8fac.rb +++ b/db/migrate/20240802203135_add_project_id_to_merge_request_diff_files99208b8fac.rb @@ -4,7 +4,7 @@ class AddProjectIdToMergeRequestDiffFiles99208b8fac < Gitlab::Database::Migratio milestone '17.3' def up - add_column :merge_request_diff_files_99208b8fac, :project_id, :bigint # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + add_column :merge_request_diff_files_99208b8fac, :project_id, :bigint end def down diff --git a/db/migrate/20240805080941_add_organization_id_to_personal_access_tokens.rb b/db/migrate/20240805080941_add_organization_id_to_personal_access_tokens.rb index 495cbc2ae3301..e0fe35d7ad7fb 100644 --- a/db/migrate/20240805080941_add_organization_id_to_personal_access_tokens.rb +++ b/db/migrate/20240805080941_add_organization_id_to_personal_access_tokens.rb @@ -9,9 +9,7 @@ class AddOrganizationIdToPersonalAccessTokens < Gitlab::Database::Migration[2.2] def up with_lock_retries do - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :personal_access_tokens, :organization_id, :bigint, default: DEFAULT_ORGANIZATION_ID, null: false, - # rubocop:enable Migration/PreventAddingColumns if_not_exists: true end # rubocop:disable Migration/PreventIndexCreation -- Legacy migration diff --git a/db/migrate/20240805081832_add_reachability_column_to_sbom_occurances_table.rb b/db/migrate/20240805081832_add_reachability_column_to_sbom_occurances_table.rb index d0b413f5059b6..7648f1da32dd5 100644 --- a/db/migrate/20240805081832_add_reachability_column_to_sbom_occurances_table.rb +++ b/db/migrate/20240805081832_add_reachability_column_to_sbom_occurances_table.rb @@ -4,7 +4,7 @@ class AddReachabilityColumnToSbomOccurancesTable < Gitlab::Database::Migration[2 milestone '17.4' def up with_lock_retries do - add_column :sbom_occurrences, :reachability, :smallint, default: 0 # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + add_column :sbom_occurrences, :reachability, :smallint, default: 0 # -- Legacy migration end end diff --git a/db/migrate/20240822195511_add_notification_cols_to_personal_access_tokens.rb b/db/migrate/20240822195511_add_notification_cols_to_personal_access_tokens.rb index 0df734bcbf095..e934da182fd1a 100644 --- a/db/migrate/20240822195511_add_notification_cols_to_personal_access_tokens.rb +++ b/db/migrate/20240822195511_add_notification_cols_to_personal_access_tokens.rb @@ -4,15 +4,9 @@ class AddNotificationColsToPersonalAccessTokens < Gitlab::Database::Migration[2. milestone '17.4' def up - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :personal_access_tokens, :seven_days_notification_sent_at, :datetime_with_timezone - # rubocop:enable Migration/PreventAddingColumns - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :personal_access_tokens, :thirty_days_notification_sent_at, :datetime_with_timezone - # rubocop:enable Migration/PreventAddingColumns - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :personal_access_tokens, :sixty_days_notification_sent_at, :datetime_with_timezone - # rubocop:enable Migration/PreventAddingColumns end def down diff --git a/db/migrate/20241014081022_add_project_id_to_ci_pipeline_messages.rb b/db/migrate/20241014081022_add_project_id_to_ci_pipeline_messages.rb index 08a283122caaf..804ada9dcfb49 100644 --- a/db/migrate/20241014081022_add_project_id_to_ci_pipeline_messages.rb +++ b/db/migrate/20241014081022_add_project_id_to_ci_pipeline_messages.rb @@ -4,6 +4,6 @@ class AddProjectIdToCiPipelineMessages < Gitlab::Database::Migration[2.2] milestone '17.6' def change - add_column(:ci_pipeline_messages, :project_id, :bigint) # rubocop:disable Migration/PreventAddingColumns -- Legacy migration + add_column(:ci_pipeline_messages, :project_id, :bigint) end end diff --git a/db/migrate/20241021141853_add_auto_resolved_to_vulnerabilities.rb b/db/migrate/20241021141853_add_auto_resolved_to_vulnerabilities.rb index e026853857df9..e94c532cff61e 100644 --- a/db/migrate/20241021141853_add_auto_resolved_to_vulnerabilities.rb +++ b/db/migrate/20241021141853_add_auto_resolved_to_vulnerabilities.rb @@ -4,8 +4,6 @@ class AddAutoResolvedToVulnerabilities < Gitlab::Database::Migration[2.2] milestone '17.6' def change - # rubocop:disable Migration/PreventAddingColumns -- Legacy migration add_column :vulnerabilities, :auto_resolved, :boolean, null: false, default: false, if_not_exists: true - # rubocop:enable Migration/PreventAddingColumns end end diff --git a/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb b/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb index 7cb1ed3e8f13b..1c783b922ae86 100644 --- a/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb +++ b/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb @@ -6,11 +6,9 @@ class AddMergeRequestDiffsProjectIdIndexAsync < Gitlab::Database::Migration[2.2] INDEX_NAME = 'index_merge_request_diffs_on_project_id' - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up prepare_async_index :merge_request_diffs, :project_id, name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down unprepare_async_index :merge_request_diffs, :project_id, name: INDEX_NAME diff --git a/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb b/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb index 29171cc501cbc..5576e9d534e8f 100644 --- a/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb +++ b/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb @@ -6,11 +6,9 @@ class AddMergeRequestDiffsProjectIdIndex < Gitlab::Database::Migration[2.2] INDEX_NAME = 'index_merge_request_diffs_on_project_id' - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up add_concurrent_index :merge_request_diffs, :project_id, name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name :merge_request_diffs, name: INDEX_NAME diff --git a/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb b/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb index ea6149612e0b7..a0149a79f83f9 100644 --- a/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb +++ b/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb @@ -6,11 +6,9 @@ class PrepareIidNamespaceUniqueIndexInIssues < Gitlab::Database::Migration[2.2] milestone '16.8' # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/435856 - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up prepare_async_index :issues, [:namespace_id, :iid], unique: true, name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down unprepare_async_index :issues, [:namespace_id, :iid], unique: true, name: INDEX_NAME diff --git a/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb b/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb index 6fb51f02d4f9c..4c2439f33ea77 100644 --- a/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb +++ b/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb @@ -7,11 +7,9 @@ class AddIidNamespaceUniqueIndexToIssues < Gitlab::Database::Migration[2.2] milestone '16.8' - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up add_concurrent_index :issues, [:namespace_id, :iid], name: INDEX_NAME, unique: true end - # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name :issues, INDEX_NAME diff --git a/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb b/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb index 09864109e9571..1e3658aa69741 100644 --- a/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb +++ b/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb @@ -6,11 +6,9 @@ class ScheduleIndexToEventsAuthorGroupActionTargetTypeCreatedAt < Gitlab::Databa INDEX_NAME = 'index_events_author_id_group_id_action_target_type_created_at' COLUMNS = [:author_id, :group_id, :action, :target_type, :created_at] - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up prepare_async_index :events, COLUMNS, name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down unprepare_async_index :events, COLUMNS, name: INDEX_NAME diff --git a/db/post_migrate/20231218074237_add_index_to_ci_job_artifact_states.rb b/db/post_migrate/20231218074237_add_index_to_ci_job_artifact_states.rb index bd0a46f14ba22..7179607fda4b7 100644 --- a/db/post_migrate/20231218074237_add_index_to_ci_job_artifact_states.rb +++ b/db/post_migrate/20231218074237_add_index_to_ci_job_artifact_states.rb @@ -7,7 +7,9 @@ class AddIndexToCiJobArtifactStates < Gitlab::Database::Migration[2.2] TABLE_NAME = :ci_job_artifact_states def up + # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index(TABLE_NAME, [:job_artifact_id, :partition_id], name: INDEX_NAME) + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20231218074508_add_index_to_ci_build_trace_metadata.rb b/db/post_migrate/20231218074508_add_index_to_ci_build_trace_metadata.rb index e3d324716075d..574c71034feb7 100644 --- a/db/post_migrate/20231218074508_add_index_to_ci_build_trace_metadata.rb +++ b/db/post_migrate/20231218074508_add_index_to_ci_build_trace_metadata.rb @@ -7,9 +7,7 @@ class AddIndexToCiBuildTraceMetadata < Gitlab::Database::Migration[2.2] TABLE_NAME = :ci_build_trace_metadata def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index(TABLE_NAME, [:trace_artifact_id, :partition_id], name: INDEX_NAME) - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb b/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb index 7af57a7f40082..99a2dccc8f54d 100644 --- a/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb +++ b/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb @@ -8,9 +8,7 @@ class AddIndexOwaspTop10WithProjectIdOnVulnerabilityReads < Gitlab::Database::Mi INDEX_NAME = 'index_vuln_reads_on_project_id_owasp_top_10' def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index :vulnerability_reads, [:project_id, :owasp_top_10], name: INDEX_NAME - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb b/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb index 36b75d0e7d834..88e5f95ef68fe 100644 --- a/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb +++ b/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb @@ -8,11 +8,9 @@ class AddIndexToEventsAuthorGroupActionTargetType < Gitlab::Database::Migration[ INDEX_NAME = 'index_events_author_id_group_id_action_target_type_created_at' COLUMNS = [:author_id, :group_id, :action, :target_type, :created_at] - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up add_concurrent_index :events, COLUMNS, name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name :events, INDEX_NAME diff --git a/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb b/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb index 32d33fe9e8167..76e8323973b9c 100644 --- a/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb +++ b/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb @@ -6,11 +6,9 @@ class AddIndexOnIssuesTableTmpEpicIdColumn < Gitlab::Database::Migration[2.2] INDEX_NAME = "tmp_index_issues_on_tmp_epic_id" - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up add_concurrent_index :issues, :tmp_epic_id, unique: true, name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name :issues, name: INDEX_NAME diff --git a/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb b/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb index bf1f60c809fac..e7b1fbe68a48e 100644 --- a/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb +++ b/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb @@ -6,11 +6,9 @@ class ScheduleIndexMergeRequestsOnUnmergedStateId < Gitlab::Database::Migration[ INDEX_NAME = :idx_merge_requests_on_unmerged_state_id TABLE_NAME = :merge_requests - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up prepare_async_index(TABLE_NAME, :id, name: INDEX_NAME, where: "state_id <> 3") end - # rubocop:enable Migration/PreventIndexCreation def down unprepare_async_index(TABLE_NAME, :id, name: INDEX_NAME) diff --git a/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb b/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb index 4af2eb942f34c..800dc23e7e562 100644 --- a/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb +++ b/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb @@ -8,11 +8,9 @@ class AddIndexMergeRequestsOnUnmergedStateId < Gitlab::Database::Migration[2.2] INDEX_NAME = :idx_merge_requests_on_unmerged_state_id TABLE_NAME = :merge_requests - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up add_concurrent_index(TABLE_NAME, :id, name: INDEX_NAME, where: "state_id <> 3") end - # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) diff --git a/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb b/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb index 599612f72019b..6b750eb3fe018 100644 --- a/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb +++ b/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb @@ -8,9 +8,7 @@ class IndexVulnerabilityReadsOnStateReportTypeSeverityTraversalIdsArchived < Git COLUMNS = %i[resolved_on_default_branch state report_type severity traversal_ids vulnerability_id].freeze def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index :vulnerability_reads, COLUMNS, name: INDEX_NAME, where: 'archived = false' - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb b/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb index 5f3ab47f2c2d8..7f1eb48e627dd 100644 --- a/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb +++ b/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb @@ -8,9 +8,7 @@ class IndexVulnerabilityReadsForCommonGroupLevelQuery < Gitlab::Database::Migrat milestone '17.0' def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index :vulnerability_reads, COLUMNS, name: INDEX_NAME, where: 'archived = false' - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240514121644_replace_issues_milestone_index.rb b/db/post_migrate/20240514121644_replace_issues_milestone_index.rb index a1d07d06bf5c4..eb3d67ae8dfa4 100644 --- a/db/post_migrate/20240514121644_replace_issues_milestone_index.rb +++ b/db/post_migrate/20240514121644_replace_issues_milestone_index.rb @@ -6,11 +6,9 @@ class ReplaceIssuesMilestoneIndex < Gitlab::Database::Migration[2.2] INDEX_NAME = 'index_issues_on_milestone_id_and_id' # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/461627 - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration def up prepare_async_index :issues, %i[milestone_id id], name: INDEX_NAME end - # rubocop:enable Migration/PreventIndexCreation def down unprepare_async_index :issues, %i[milestone_id id], name: INDEX_NAME diff --git a/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb b/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb index f044d91cb6b84..94f234f67b912 100644 --- a/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb +++ b/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb @@ -7,11 +7,9 @@ class AddIssuesMilestoneAndIdIndexConcurrently < Gitlab::Database::Migration[2.2 disable_ddl_transaction! - # rubocop: disable Migration/PreventIndexCreation -- Replacing an existing index def up add_concurrent_index :issues, %i[milestone_id id], name: INDEX_NAME end - # rubocop: enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name :issues, INDEX_NAME diff --git a/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb b/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb index 26b91086a0c6e..e1ca68e1f4046 100644 --- a/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb +++ b/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb @@ -7,14 +7,13 @@ class CreateIdxVulnerabilityOccurencesOnPrimIdenId < Gitlab::Database::Migration NEW_INDEX_NAME = 'index_vulnerability_occurrences_prim_iden_id_and_vuln_id' TABLE_NAME = :vulnerability_occurrences - # rubocop:disable Migration/PreventIndexCreation -- This index was created async previously, check https://gitlab.com/gitlab-org/gitlab/-/merge_requests/131647 + # -- This index was created async previously, check https://gitlab.com/gitlab-org/gitlab/-/merge_requests/131647 def up add_concurrent_index( TABLE_NAME, [:primary_identifier_id, :vulnerability_id], name: NEW_INDEX_NAME ) end - # rubocop:enable Migration/PreventIndexCreation def down remove_concurrent_index_by_name TABLE_NAME, NEW_INDEX_NAME diff --git a/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb b/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb index 4b205d9364fab..a2631fe43db0a 100644 --- a/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb +++ b/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb @@ -6,13 +6,12 @@ class AddIndexOwaspTop10ForGroupLevelReports < Gitlab::Database::Migration[2.2] INDEX_NAME = 'index_for_owasp_top_10_group_level_reports' + # -- Legacy migration def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index :vulnerability_reads, [:owasp_top_10, :state, :report_type, :severity, :traversal_ids, :vulnerability_id, :resolved_on_default_branch], where: 'archived = false', name: INDEX_NAME - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb b/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb index ba2556dcaf88f..c7117461ac575 100644 --- a/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb +++ b/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb @@ -11,10 +11,9 @@ class TmpIndexOnVulnerabilityReads < Gitlab::Database::Migration[2.2] INDEX_NAME = 'tmp_index_vulnerability_reads_where_state_is_detected' TABLE_NAME = :vulnerability_reads + # -- Legacy migration def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index TABLE_NAME, :id, name: INDEX_NAME, where: "state = 1" - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb b/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb index 95bb399285a53..145fb53ad9480 100644 --- a/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb +++ b/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb @@ -6,10 +6,9 @@ class PrepareIndexVulnerabilityFindingLinksOnProjectId < Gitlab::Database::Migra INDEX_NAME = 'index_vulnerability_finding_links_on_project_id' + # -- Legacy migration def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration prepare_async_index :vulnerability_finding_links, :project_id, name: INDEX_NAME - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240730172816_prepare_index_vulnerability_occurrence_pipelines_on_project_id.rb b/db/post_migrate/20240730172816_prepare_index_vulnerability_occurrence_pipelines_on_project_id.rb index c204bea56287f..78294f0eb0fbf 100644 --- a/db/post_migrate/20240730172816_prepare_index_vulnerability_occurrence_pipelines_on_project_id.rb +++ b/db/post_migrate/20240730172816_prepare_index_vulnerability_occurrence_pipelines_on_project_id.rb @@ -6,10 +6,9 @@ class PrepareIndexVulnerabilityOccurrencePipelinesOnProjectId < Gitlab::Database INDEX_NAME = 'index_vulnerability_occurrence_pipelines_on_project_id' + # -- Legacy migration def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration prepare_async_index :vulnerability_occurrence_pipelines, :project_id, name: INDEX_NAME - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb b/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb index c79e98178f84e..3158fc7a8e918 100644 --- a/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb +++ b/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb @@ -8,10 +8,9 @@ class TmpIndexForOwaspOnVulnerabilityReads < Gitlab::Database::Migration[2.2] COLUMNS = %i[vulnerability_id].freeze WHERE_CLAUSE = 'owasp_top_10 IS NULL' + # -- Legacy migration def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index :vulnerability_reads, COLUMNS, name: INDEX_NAME, where: WHERE_CLAUSE - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb b/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb index 7333acfad1f30..7074e911f7b7f 100644 --- a/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb +++ b/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb @@ -9,13 +9,12 @@ class AddRevisedIdxOwaspTop10ForGroupLevelReports < Gitlab::Database::Migration[ INDEX_NAME = 'revised_idx_for_owasp_top_10_group_level_reports' + # -- Legacy migration def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index :vulnerability_reads, [:owasp_top_10, :state, :report_type, :resolved_on_default_branch, :severity, :traversal_ids, :vulnerability_id], where: 'archived = false', name: INDEX_NAME - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb b/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb index 34b55998ad611..7d1d9648d156b 100644 --- a/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb +++ b/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb @@ -5,14 +5,13 @@ class AsyncAddIndexOnEventsPersonalNamespaceId2 < Gitlab::Database::Migration[2. INDEX_NAME = 'index_events_on_personal_namespace_id' - # rubocop:disable Migration/PreventIndexCreation -- https://gitlab.com/gitlab-org/gitlab/-/issues/462801#note_2081632603 + # -- https://gitlab.com/gitlab-org/gitlab/-/issues/462801#note_2081632603 def up return unless Gitlab.com_except_jh? prepare_async_index :events, :personal_namespace_id, name: INDEX_NAME, where: 'personal_namespace_id IS NOT NULL' end - # rubocop:enable Migration/PreventIndexCreation def down return unless Gitlab.com_except_jh? diff --git a/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb b/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb index bdb2a75f62ec4..a36498752de5d 100644 --- a/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb +++ b/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb @@ -7,7 +7,7 @@ class AddIndexOnEventsPersonalNamespaceIdSelfManaged < Gitlab::Database::Migrati INDEX = 'index_events_on_personal_namespace_id' - # rubocop:disable Migration/PreventIndexCreation -- https://gitlab.com/gitlab-org/gitlab/-/issues/462801#note_2081632603 + # -- https://gitlab.com/gitlab-org/gitlab/-/issues/462801#note_2081632603 def up return if Gitlab.com_except_jh? @@ -16,7 +16,6 @@ def up where: 'personal_namespace_id IS NOT NULL', name: INDEX end - # rubocop:enable Migration/PreventIndexCreation def down return if Gitlab.com_except_jh? diff --git a/db/post_migrate/20240912122438_prepare_index_ci_job_artifact_states_on_project_id.rb b/db/post_migrate/20240912122438_prepare_index_ci_job_artifact_states_on_project_id.rb index b9cacd0b850d9..4954335338aa9 100644 --- a/db/post_migrate/20240912122438_prepare_index_ci_job_artifact_states_on_project_id.rb +++ b/db/post_migrate/20240912122438_prepare_index_ci_job_artifact_states_on_project_id.rb @@ -7,7 +7,9 @@ class PrepareIndexCiJobArtifactStatesOnProjectId < Gitlab::Database::Migration[2 INDEX_NAME = 'index_ci_job_artifact_states_on_project_id' def up + # rubocop:disable Migration/PreventIndexCreation -- Legacy migration prepare_async_index :ci_job_artifact_states, :project_id, name: INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb b/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb index 5b0fdc4aeb1b0..1d3e5f10a62b6 100644 --- a/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb +++ b/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb @@ -7,10 +7,9 @@ class AddIndexOnVulnerabilityReadsForFilteredRemoval < Gitlab::Database::Migrati milestone '17.5' + # -- Legacy migration def up - # rubocop:disable Migration/PreventIndexCreation -- Legacy migration add_concurrent_index :vulnerability_reads, %i[project_id resolved_on_default_branch], name: INDEX_NAME - # rubocop:enable Migration/PreventIndexCreation end def down diff --git a/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb b/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb index 742bdba756f63..2f08cec6b0215 100644 --- a/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb +++ b/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb @@ -8,7 +8,7 @@ class PrepareAsyncIndexOnIssuesByProjectCorrectTypeWhereClosed < Gitlab::Databas def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005 - prepare_async_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + prepare_async_index :issues, # -- Tmp index needed to fix work item type ids [:project_id, :correct_work_item_type_id, :closed_at], where: 'state_id = 2', name: INDEX_NAME diff --git a/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb b/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb index f95f4634dbc93..4c20d1fe744a7 100644 --- a/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb +++ b/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb @@ -9,7 +9,7 @@ class PrepareAsyncIndexOnIssuesProjectHealthIdDescStateCorrectType < Gitlab::Dat def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005 - prepare_async_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + prepare_async_index :issues, # -- Tmp index needed to fix work item type ids [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id], order: { health_status: 'DESC NULLS LAST', id: :desc }, name: INDEX_NAME diff --git a/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb b/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb index 5afcaa4cf6d70..a32e782a7ddd8 100644 --- a/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb +++ b/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb @@ -9,7 +9,7 @@ class PrepareAsyncIndexOnIssuesProjectHealthIdAscStateCorrectType < Gitlab::Data def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005 - prepare_async_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + prepare_async_index :issues, # -- Tmp index needed to fix work item type ids [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id], order: { health_status: 'ASC NULLS LAST', id: :desc }, name: INDEX_NAME diff --git a/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb b/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb index 15214d865d2d2..3103ceebc8daf 100644 --- a/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb +++ b/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb @@ -9,7 +9,7 @@ class PrepareAsyncIndexOnIssuesCorrectTypeProjectCreatedAtState < Gitlab::Databa def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005 - prepare_async_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + prepare_async_index :issues, # -- Tmp index needed to fix work item type ids [:correct_work_item_type_id, :project_id, :created_at, :state_id], name: INDEX_NAME end diff --git a/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb b/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb index dcec3980862f7..17a47df2d91e2 100644 --- a/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb +++ b/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb @@ -8,7 +8,7 @@ class CreateTmpIndexOnIssuesByProjectCorrectTypeWhereClosed < Gitlab::Database:: def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 - add_concurrent_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids [:project_id, :correct_work_item_type_id, :closed_at], where: 'state_id = 2', name: INDEX_NAME diff --git a/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb b/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb index 630ba61252666..c6e1e462b2be8 100644 --- a/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb +++ b/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb @@ -8,7 +8,7 @@ class CreateTmpIndexOnIssuesProjectHealthIdDescStateCorrectType < Gitlab::Databa def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 - add_concurrent_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id], order: { health_status: 'DESC NULLS LAST', id: :desc }, name: INDEX_NAME diff --git a/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb b/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb index 2628d272ef947..a4091559d2ced 100644 --- a/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb +++ b/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb @@ -8,7 +8,7 @@ class CreateTmpIndexOnIssuesProjectHealthIdAscStateCorrectType < Gitlab::Databas def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 - add_concurrent_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id], order: { health_status: 'ASC NULLS LAST', id: :desc }, name: INDEX_NAME diff --git a/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb b/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb index f345fa9ae9f25..33dd943726253 100644 --- a/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb +++ b/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb @@ -8,7 +8,7 @@ class CreateTmpIndexOnIssuesCorrectTypeProjectCreatedAtState < Gitlab::Database: def up # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165 - add_concurrent_index :issues, # rubocop:disable Migration/PreventIndexCreation -- Tmp index needed to fix work item type ids + add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids [:correct_work_item_type_id, :project_id, :created_at, :state_id], name: INDEX_NAME end diff --git a/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb b/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb index 3cfb203d1f0f3..dc4e4232d6aa6 100644 --- a/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb +++ b/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop: disable Migration/PreventIndexCreation -- update an existing index +# -- update an existing index class UpdateSentNotificationsIndexOnNoteable < Gitlab::Database::Migration[2.2] milestone '17.6' @@ -22,4 +22,3 @@ def down unprepare_async_index :sent_notifications, COLUMN_NAMES, name: INDEX_NAME end end -# rubocop: enable Migration/PreventIndexCreation diff --git a/rubocop/cop/migration/prevent_adding_columns.rb b/rubocop/cop/migration/prevent_adding_columns.rb index b99ee21db14b0..004e356c6e1d4 100644 --- a/rubocop/cop/migration/prevent_adding_columns.rb +++ b/rubocop/cop/migration/prevent_adding_columns.rb @@ -10,7 +10,7 @@ class PreventAddingColumns < RuboCop::Cop::Base include MigrationHelpers MSG = <<~MSG - `%s` is a large table with several columns, adding more should be avoided unless absolutely necessary. + `%s` is over the limit authorized, adding more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one. The list of large tables is defined in rubocop/rubocop-migrations.yml. See https://docs.gitlab.com/ee/development/database/large_tables_limitations.html @@ -52,11 +52,11 @@ def table_matches?(table_name) return false unless valid_table_node?(table_name) table_value = table_name.value - wide_or_large_table?(table_value) + wide_or_over_limit_table?(table_value) end - def wide_or_large_table?(table_value) - WIDE_TABLES.include?(table_value) || large_tables.include?(table_value) + def wide_or_over_limit_table?(table_value) + WIDE_TABLES.include?(table_value) || over_limit_tables.include?(table_value) end def valid_table_node?(table_name) diff --git a/rubocop/migration_helpers.rb b/rubocop/migration_helpers.rb index 4344ed91c82b1..eb4d5491ff658 100644 --- a/rubocop/migration_helpers.rb +++ b/rubocop/migration_helpers.rb @@ -28,6 +28,10 @@ def high_traffic_tables @high_traffic_tables ||= rubocop_migrations_config.dig('Migration/UpdateLargeTable', 'HighTrafficTables') end + def over_limit_tables + @over_limit_table ||= rubocop_migrations_config.dig('Migration/UpdateLargeTable', 'OverLimitTables') + end + def large_tables @large_tables ||= rubocop_migrations_config.dig('Migration/UpdateLargeTable', 'LargeTables') end diff --git a/rubocop/rubocop-migrations.yml b/rubocop/rubocop-migrations.yml index 112a01892c33b..67e205e02f5a7 100644 --- a/rubocop/rubocop-migrations.yml +++ b/rubocop/rubocop-migrations.yml @@ -1,55 +1,66 @@ # Make sure to update the docs if this file moves. Docs URL: https://docs.gitlab.com/ee/development/migration_style_guide.html#when-to-use-the-helper-method Migration/UpdateLargeTable: Enabled: true - LargeTables: # all tables classified as large, or over_limit - - :approval_merge_request_rules_users - - :audit_events - - :ci_build_needs - - :ci_build_report_results - - :ci_build_trace_metadata - - :ci_builds + OverLimitTables: - :ci_builds_metadata - - :ci_job_artifacts - - :ci_job_variables - - :ci_pipeline_messages - - :ci_pipeline_variables + - :ci_builds_metadata_102 + - :ci_builds_metadata_101 + - :ci_builds - :ci_pipelines - - :ci_pipelines_config + - :ci_builds_102 + - :ci_builds_101 + - :taggings + - :ci_job_artifacts + - :ci_build_needs - :ci_stages + - :ci_pipeline_variables + - :ci_build_tags_100 + - :ci_job_artifacts_102 + - :ci_build_names_102 + - :ci_pipeline_variables_102 + - :ci_build_tags_102 + - :ci_build_tags_101 + - :ci_build_report_results + - :ci_job_variables + - :ci_stages_102 - :deployments - :description_versions - :events - :issues - :merge_request_diff_commits - - :merge_request_diff_commits_b5377a7a34 + - :merge_request_diff_commits_b5377a7a34_1000000001 + - :merge_request_diff_commits_b5377a7a34_800000001 - :merge_request_diff_files - - :merge_request_diff_files_99208b8fac + - :merge_request_diff_files_99208b8fac_1000000001 - :merge_request_diffs - :merge_request_metrics - :merge_requests - :note_diff_files - :notes - :oauth_access_tokens - - :packages_package_files - - :personal_access_tokens - :project_authorizations - - :projects - :push_event_payloads - :resource_label_events - - :sbom_occurrences - :security_findings - - :security_scans - :sent_notifications - :system_note_metadata - - :taggings - :todos - - :vulnerabilities - :vulnerability_finding_links - - :vulnerability_occurrence_pipelines - :vulnerability_occurrences - :vulnerability_reads - :web_hook_logs - HighTrafficTables: &high_traffic_tables # size in GB (>= 10 GB on GitLab.com as of 06/2022) and/or number of records + LargeTables: + - :ci_job_artifact_states + - :ci_pipeline_messages + - :approval_merge_request_rules_users + - :audit_events + - :packages_package_files + - :personal_access_tokens + - :projects + - :sbom_occurrences + - :security_scans + - :vulnerabilities + HighTrafficTables: - :alert_management_alerts - :approvals - :approval_merge_request_rules_users diff --git a/spec/rubocop/cop/migration/prevent_adding_columns_spec.rb b/spec/rubocop/cop/migration/prevent_adding_columns_spec.rb index 6b2ca1901880d..b2f019c30f08e 100644 --- a/spec/rubocop/cop/migration/prevent_adding_columns_spec.rb +++ b/spec/rubocop/cop/migration/prevent_adding_columns_spec.rb @@ -21,7 +21,7 @@ def up context 'with wide tables' do it 'registers an offense when adding a column to a wide table' do - offense = '`projects` is a large table with several columns, [...]' + offense = '`projects` is over the limit authorized, [...]' expect_offense(<<~RUBY) def up @@ -32,7 +32,7 @@ def up end it 'registers an offense when adding a column with default to a wide table' do - offense = '`users` is a large table with several columns, [...]' + offense = '`users` is over the limit authorized, [...]' expect_offense(<<~RUBY) def up @@ -43,7 +43,7 @@ def up end it 'registers an offense when adding a reference' do - offense = '`ci_builds` is a large table with several columns, [...]' + offense = '`ci_builds` is over the limit authorized, [...]' expect_offense(<<~RUBY) def up @@ -54,7 +54,7 @@ def up end it 'registers an offense when adding timestamps' do - offense = '`projects` is a large table with several columns, [...]' + offense = '`projects` is over the limit authorized, [...]' expect_offense(<<~RUBY) def up @@ -83,13 +83,13 @@ def up end end - context 'when targeting a large table' do - it 'registers an offense for audit_events' do - offense = '`audit_events` is a large table with several columns, [...]' + context 'when targeting an over limit table' do + it 'registers an offense for issues' do + offense = '`issues` is over the limit authorized, [...]' expect_offense(<<~RUBY) def up - add_column(:audit_events, :another_column, :boolean, default: false) + add_column(:issues, :another_column, :boolean, default: false) ^^^^^^^^^^ #{offense} end RUBY diff --git a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb index 2daab714cadaf..3a3409b67db87 100644 --- a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb +++ b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb @@ -3,30 +3,11 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/prevent_index_creation' -RSpec.describe RuboCop::Cop::Migration::PreventIndexCreation do +RSpec.describe RuboCop::Cop::Migration::PreventIndexCreation, feature_category: :database do + include RuboCop::MigrationHelpers + let(:forbidden_tables) do - %w[ - ci_builds - namespaces - projects - users - merge_requests - merge_request_metrics - merge_request_diffs - merge_request_diff_commits - notes - web_hook_logs - events - project_statistics - sent_notifications - issues - issue_search_data - packages_packages - vulnerability_occurrences - sbom_occurrences - security_findings - deployments - ].freeze + described_class::FORBIDDEN_TABLES + large_tables end context 'when in migration' do @@ -121,7 +102,7 @@ def change it "registers an offense when add_concurrent_index is used", :aggregate_failures do expect_offense(<<~RUBY) INDEX_NAME = "index_name" - TABLE_NAME = :ci_builds + TABLE_NAME = :projects disable_ddl_transaction! def change @@ -134,7 +115,7 @@ def change it "registers an offense when prepare_async_index is used", :aggregate_failures do expect_offense(<<~RUBY) INDEX_NAME = "index_name" - TABLE_NAME = :ci_builds + TABLE_NAME = :projects disable_ddl_transaction! def change -- GitLab