Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20211202145237_add_todos_project_and_id_index.rb32
-rw-r--r--db/post_migrate/20211203091642_add_index_to_projects_on_marked_for_deletion_at.rb15
-rw-r--r--db/post_migrate/20211206073851_create_calendar_events_index_synchronously.rb15
-rw-r--r--db/post_migrate/20211206074547_remove_old_calendar_events_index.rb18
-rw-r--r--db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb28
-rw-r--r--db/post_migrate/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb15
-rw-r--r--db/post_migrate/20211207090503_cleanup_first_mentioned_in_commit_jobs.rb22
-rw-r--r--db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb16
-rw-r--r--db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb28
-rw-r--r--db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb57
-rw-r--r--db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb71
-rw-r--r--db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb11
-rw-r--r--db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb11
-rw-r--r--db/post_migrate/20211208171402_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb27
-rw-r--r--db/post_migrate/20211209093636_track_ci_job_artifacts_deletes.rb15
-rw-r--r--db/post_migrate/20211209093828_track_users_deletes.rb15
-rw-r--r--db/post_migrate/20211209093923_track_external_pull_requests_deletes.rb15
-rw-r--r--db/post_migrate/20211209094222_track_merge_requests_deletes.rb15
-rw-r--r--db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb41
-rw-r--r--db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb16
-rw-r--r--db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb25
-rw-r--r--db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb15
-rw-r--r--db/post_migrate/20211210140629_encrypt_static_object_token.rb22
-rw-r--r--db/post_migrate/20211210173137_remove_vulnerability_finding_links_again.rb14
-rw-r--r--db/post_migrate/20211213064821_add_agent_id_location_index_to_vulnerability_occurrences.rb18
-rw-r--r--db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb15
-rw-r--r--db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb9
-rw-r--r--db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb23
-rw-r--r--db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb41
-rw-r--r--db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb14
-rw-r--r--db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb20
-rw-r--r--db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb28
-rw-r--r--db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb15
-rw-r--r--db/post_migrate/20211220123956_update_invalid_member_states.rb21
-rw-r--r--db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb15
-rw-r--r--db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb17
-rw-r--r--db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb15
-rw-r--r--db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb17
-rw-r--r--db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb17
-rw-r--r--db/post_migrate/20220106185033_remove_finding_evidence_summary.rb15
-rw-r--r--db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb17
-rw-r--r--db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb17
-rw-r--r--db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb17
-rw-r--r--db/post_migrate/20220107064845_populate_vulnerability_reads.rb25
-rw-r--r--db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb17
-rw-r--r--db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb23
-rw-r--r--db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb15
-rw-r--r--db/post_migrate/20220111093534_remove_index_on_auto_stop_in.rb17
-rw-r--r--db/post_migrate/20220111101421_remove_index_on_merge_request_id.rb17
-rw-r--r--db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb14
-rw-r--r--db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb15
-rw-r--r--db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb17
-rw-r--r--db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb23
-rw-r--r--db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb16
-rw-r--r--db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb15
-rw-r--r--db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb15
-rw-r--r--db/post_migrate/20220113111440_schedule_fix_incorrect_max_seats_used.rb20
-rw-r--r--db/post_migrate/20220114105525_add_index_on_projects_path.rb17
-rw-r--r--db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb16
-rw-r--r--db/post_migrate/20220117034056_remove_index_cluster_agent_tokens_on_agent_id_and_last_used_at.rb15
-rw-r--r--db/post_migrate/20220118204039_self_managed_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb29
-rw-r--r--db/post_migrate/20220119094503_populate_audit_event_streaming_verification_token.rb19
-rw-r--r--db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb17
-rw-r--r--db/post_migrate/20220119143130_remove_projects_ci_sources_pipelines_source_project_id_fk.rb17
-rw-r--r--db/post_migrate/20220119144458_remove_users_ci_triggers_owner_id_fk.rb17
-rw-r--r--db/post_migrate/20220119151221_remove_merge_requests_ci_pipelines_merge_request_id_fk.rb19
-rw-r--r--db/post_migrate/20220119153706_remove_ci_pipelines_merge_trains_pipeline_id_fk.rb17
-rw-r--r--db/post_migrate/20220119154442_remove_ci_pipelines_merge_requests_head_pipeline_id_fk.rb17
-rw-r--r--db/post_migrate/20220119193130_remove_ci_pipelines_dast_profiles_pipelines_ci_pipeline_id_fk.rb17
-rw-r--r--db/post_migrate/20220119201340_remove_ci_pipelines_vulnerability_statistics_latest_pipeline_id_fk.rb17
-rw-r--r--db/post_migrate/20220119203119_remove_ci_pipelines_vulnerability_occurrence_pipelines_pipeline_id_fk.rb17
-rw-r--r--db/post_migrate/20220120094340_drop_position_from_security_findings.rb9
-rw-r--r--db/post_migrate/20220120123700_add_tmp_index_routes_id_for_namespaces.rb17
-rw-r--r--db/post_migrate/20220120123800_backfill_namespace_id_for_namespace_routes.rb27
-rw-r--r--db/post_migrate/20220120211832_backfill_member_namespace_id_for_group_members.rb27
-rw-r--r--db/post_migrate/20220121214752_remove_projects_ci_stages_project_id_fk.rb20
-rw-r--r--db/post_migrate/20220121214753_re_remove_projects_ci_stages_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220121221651_remove_projects_ci_variables_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124130028_dedup_runner_projects.rb71
-rw-r--r--db/post_migrate/20220124145019_remove_projects_external_pull_requests_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124151456_remove_projects_ci_triggers_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124151949_remove_projects_ci_runner_projects_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124152824_remove_projects_ci_subscriptions_projects_downstream_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124153233_remove_projects_ci_job_artifacts_project_id_fk.rb20
-rw-r--r--db/post_migrate/20220124153234_re_remove_projects_ci_job_artifacts_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124180704_remove_projects_ci_builds_metadata_project_id_fk.rb20
-rw-r--r--db/post_migrate/20220124180705_re_remove_projects_ci_builds_metadata_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124184338_remove_projects_ci_subscriptions_projects_upstream_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124204046_remove_projects_ci_sources_pipelines_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124214131_remove_projects_ci_refs_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124215857_remove_projects_ci_job_token_project_scope_links_source_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220124221521_remove_projects_ci_project_monthly_usages_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220125083520_remove_ci_pipelines_dast_site_profiles_pipelines_ci_pipeline_id_fk.rb19
-rw-r--r--db/post_migrate/20220125084348_remove_ci_pipelines_vulnerability_feedback_pipeline_id_fk.rb19
-rw-r--r--db/post_migrate/20220125122640_schedule_populate_topics_non_private_projects_count.rb23
-rw-r--r--db/post_migrate/20220126201752_remove_projects_ci_job_token_project_scope_links_target_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220126202654_remove_projects_ci_sources_projects_source_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220126203421_remove_projects_ci_pipeline_schedules_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220126210021_remove_projects_ci_builds_project_id_fk.rb20
-rw-r--r--db/post_migrate/20220126210022_re_remove_projects_ci_builds_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220126210657_remove_projects_ci_pipelines_project_id_fk.rb19
-rw-r--r--db/post_migrate/20220127112243_add_index_to_merge_request_assignees_state.rb15
-rw-r--r--db/post_migrate/20220127112412_add_index_to_merge_request_reviewers_state.rb15
-rw-r--r--db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb11
-rw-r--r--db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb11
-rw-r--r--db/post_migrate/20220128155251_remove_dangling_running_builds.rb25
-rw-r--r--db/post_migrate/20220128155814_fix_approval_rules_code_owners_rule_type_index.rb23
-rw-r--r--db/post_migrate/20220131000000_index_job_artifacts_on_trace_type_and_expire_at.rb16
-rw-r--r--db/post_migrate/20220131000001_schedule_trace_expiry_removal.rb55
-rw-r--r--db/post_migrate/20220201034731_remove_index_clusters_kubernetes_namespaces_on_cluster_id.rb15
-rw-r--r--db/post_migrate/20220201141705_cleanup_background_migration_populate_test_reports_issue_id.rb15
-rw-r--r--db/post_migrate/20220201173212_add_user_details_provisioning_index.rb18
-rw-r--r--db/post_migrate/20220201193033_add_unique_index_to_vulnerability_finding_links_with_truncate.rb20
-rw-r--r--db/post_migrate/20220202105733_delete_service_template_records.rb16
-rw-r--r--db/post_migrate/20220204053655_remove_index_epic_issues_on_epic_id.rb15
-rw-r--r--db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb25
-rw-r--r--db/post_migrate/20220204110725_backfill_cycle_analytics_aggregations.rb33
-rw-r--r--db/post_migrate/20220204194347_encrypt_integration_properties.rb22
-rw-r--r--db/post_migrate/20220207080758_update_api_indexes_for_projects.rb48
-rw-r--r--db/post_migrate/20220208080921_schedule_migrate_personal_namespace_project_maintainer_to_owner.rb25
-rw-r--r--db/post_migrate/20220208115439_start_backfill_ci_queuing_tables.rb24
-rw-r--r--db/post_migrate/20220209111007_add_partial_index_for_batching_active_cluster_image_scanning_vulnerabilities.rb16
-rw-r--r--db/post_migrate/20220212120735_schedule_fix_incorrect_max_seats_used2.rb20
-rw-r--r--db/post_migrate/20220213104531_create_indexes_on_integration_type_new.rb60
-rw-r--r--db/post_migrate/20220215190020_rerun_convert_stringified_raw_metadata_hash_to_json.rb27
-rw-r--r--db/post_migrate/20220216201949_remove_package_files_limit_from_application_settings.rb18
-rw-r--r--db/post_migrate/20220217135229_validate_not_null_constraint_on_security_findings_uuid.rb13
-rw-r--r--db/post_migrate/20220221214928_remove_show_diff_preview_in_email_column.rb13
-rw-r--r--db/post_migrate/20220222191845_remove_not_null_constraint_for_security_scan_succeeded.rb11
-rw-r--r--db/post_migrate/20220222192524_create_not_null_constraint_releases_tag.rb13
-rw-r--r--db/post_migrate/20220222192525_remove_null_releases.rb24
-rw-r--r--db/post_migrate/20220223112304_schedule_nullify_orphan_runner_id_on_ci_builds.rb27
-rw-r--r--db/post_migrate/20220223124428_schedule_merge_topics_with_same_name.rb23
-rw-r--r--db/post_migrate/20220224000000_async_build_trace_expire_at_index.rb14
-rw-r--r--db/post_migrate/20220224204415_recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb31
-rw-r--r--db/post_migrate/20220225133705_cleanup_backfill_ci_queuing_tables.rb15
-rw-r--r--db/post_migrate/20220301093434_backfill_all_project_namespaces.rb29
-rw-r--r--db/post_migrate/20220302114046_backfill_group_features.rb27
-rw-r--r--db/post_migrate/20220302203410_create_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb28
-rw-r--r--db/post_migrate/20220304165107_drop_partitioned_foreign_keys.rb19
-rw-r--r--db/post_migrate/20220304201847_add_unique_index_on_security_training_providers.rb15
-rw-r--r--db/post_migrate/20220305223212_add_security_training_providers.rb40
-rw-r--r--db/post_migrate/20220307192534_create_index_for_remove_duplicate_project_tag_releases.rb17
-rw-r--r--db/post_migrate/20220307192610_remove_duplicate_project_tag_releases.rb26
-rw-r--r--db/post_migrate/20220307192645_remove_index_for_remove_duplicate_project_tag_releases.rb17
-rw-r--r--db/post_migrate/20220307192725_create_unique_index_release_tag_project.rb23
-rw-r--r--db/post_migrate/20220307203459_rename_user_email_lookup_limit_setting_to_search_settings_cleanup.rb15
-rw-r--r--db/post_migrate/20220308000205_drop_old_index_security_ci_builds_on_name_and_id_parser_features.rb26
-rw-r--r--db/post_migrate/20220308115219_schedule_reset_duplicate_ci_runners_token_encrypted_values_on_projects.rb27
-rw-r--r--db/post_migrate/20220308115502_schedule_reset_duplicate_ci_runners_token_values_on_projects.rb27
-rw-r--r--db/post_migrate/20220309084838_remove_external_pull_request_tracking.rb15
-rw-r--r--db/post_migrate/20220309084954_remove_leftover_external_pull_request_deletions.rb30
-rw-r--r--db/post_migrate/20220309154855_add_index_on_issues_closed_incidents.rb15
-rw-r--r--db/post_migrate/20220310095341_add_async_index_ci_job_artifacts_project_id_created_at.rb16
-rw-r--r--db/post_migrate/20220310134207_add_index_project_id_and_released_at_and_id_on_releases.rb16
-rw-r--r--db/post_migrate/20220310141349_remove_dependency_list_usage_data_from_redis.rb13
-rw-r--r--db/post_migrate/20220311010352_create_scan_id_and_id_index_on_security_findings.rb15
-rw-r--r--db/post_migrate/20220314162342_add_index_ci_job_artifacts_project_id_created_at.rb15
-rw-r--r--db/post_migrate/20220315171027_add_tmp_index_to_support_leaky_regex_cleanup.rb19
-rw-r--r--db/post_migrate/20220315171129_cleanup_draft_data_from_faulty_regex.rb42
-rw-r--r--db/post_migrate/20220315181130_add_temporary_issue_type_index_for_work_item_types.rb15
-rw-r--r--db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb13
-rw-r--r--db/post_migrate/20220315211043_add_index_to_vulnerability_reads.rb23
-rw-r--r--db/post_migrate/20220316102900_add_index_to_deploy_tokens_on_creator_id.rb15
-rw-r--r--db/post_migrate/20220316102902_add_user_foreign_key_to_deploy_tokens.rb15
-rw-r--r--db/post_migrate/20220316112118_update_organizations_name_index_add_id.rb20
-rw-r--r--db/post_migrate/20220316112206_add_contacts_index_on_group_email_and_id.rb15
-rw-r--r--db/post_migrate/20220316165539_add_index_to_vulnerabilities.rb22
-rw-r--r--db/post_migrate/20220316202640_populate_container_repositories_migration_plan.rb23
-rw-r--r--db/post_migrate/20220317161914_remove_ci_runners_ci_builds_runner_id_fk.rb19
-rw-r--r--db/post_migrate/20220318111040_add_indexes_for_primary_email_second_cleanup_migration.rb28
-rw-r--r--db/post_migrate/20220318111729_cleanup_after_fixing_issue_when_admin_changed_primary_email.rb55
-rw-r--r--db/post_migrate/20220318111949_drop_temporary_indexes_for_primary_email_migration_second_cleanup.rb28
-rw-r--r--db/post_migrate/20220321025720_alter_constraint_remote_import_url.rb14
-rw-r--r--db/post_migrate/20220321201912_remove_user_email_lookup_limit.rb13
-rw-r--r--db/post_migrate/20220322023800_add_tmp_index_routes_id_for_project_namespaces.rb17
-rw-r--r--db/post_migrate/20220322035654_add_migration_plan_index_to_container_repositories.rb17
-rw-r--r--db/post_migrate/20220322071127_finalize_project_namespaces_backfill.rb23
-rw-r--r--db/post_migrate/20220322094410_remove_wiki_notes.rb20
-rw-r--r--db/post_migrate/20220322132242_update_pages_onboarding_state.rb32
-rw-r--r--db/post_migrate/20220322205008_change_search_rate_limit_values.rb18
-rw-r--r--db/post_migrate/20220323023800_backfill_namespace_id_for_project_routes.rb27
-rw-r--r--db/post_migrate/20220323130000_add_temp_index_on_null_project_namespace_ids.rb15
-rw-r--r--db/post_migrate/20220323152202_add_index_on_visible_deployments.rb19
-rw-r--r--db/post_migrate/20220324032250_migrate_shimo_confluence_service_category.rb21
-rw-r--r--db/post_migrate/20220324081709_fix_and_backfill_project_namespaces_for_projects_with_duplicate_name.rb27
-rw-r--r--db/post_migrate/20220324110247_untrack_deletions_on_ci_job_artifacts.rb15
-rw-r--r--db/post_migrate/20220324180717_remove_project_pages_metadata_artifacts_archive_id_column.rb21
-rw-r--r--db/post_migrate/20220325000000_prepare_index_for_ci_job_artifacts_unlocked_with_expire_at.rb15
-rw-r--r--db/post_migrate/20220325000001_finalize_index_for_ci_job_artifacts_unlocked_with_expire_at.rb17
-rw-r--r--db/post_migrate/20220325050642_drop_integrations_template_column.rb9
-rw-r--r--db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb11
-rw-r--r--db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb15
-rw-r--r--db/post_migrate/20220326161803_add_cascade_delete_fk_on_project_namespace_id.rb41
-rw-r--r--db/post_migrate/20220326163653_add_not_null_contraint_to_project_namespace_id.rb13
-rw-r--r--db/post_migrate/20220329175119_remove_leftover_ci_job_artifact_deletions.rb30
-rw-r--r--db/post_migrate/20220331074722_add_notes_null_discussion_id_temp_index_async.rb14
-rw-r--r--db/post_migrate/20220401045621_remove_state_index_on_merge_request_assignees.rb15
-rw-r--r--db/post_migrate/20220401045642_remove_state_index_on_merge_request_reviewers.rb15
-rw-r--r--db/post_migrate/20220404183350_add_forbidden_state_index_to_users.rb17
-rw-r--r--db/post_migrate/20220404184814_drop_broader_expired_artifact_index.rb16
-rw-r--r--db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb13
-rw-r--r--db/post_migrate/20220409160628_add_async_index_for_events_followed_users.rb13
-rw-r--r--db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb14
-rw-r--r--db/post_migrate/20220412143551_add_partial_index_on_unencrypted_integrations.rb18
-rw-r--r--db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb23
-rw-r--r--db/post_migrate/20220413011328_remove_partial_index_on_unencrypted_integrations.rb19
-rw-r--r--db/post_migrate/20221027203951_drop_experiment_users_table.rb2
-rw-r--r--db/post_migrate/20221114142602_drop_experiment_subjects_table.rb2
-rw-r--r--db/post_migrate/20221114142616_drop_experiments_table.rb2
-rw-r--r--db/post_migrate/20221115184525_remove_namespaces_tmp_project_id_column.rb4
-rw-r--r--db/post_migrate/20221207135755_finalize_add_namespaces_emails_enabled_column_data.rb22
-rw-r--r--db/post_migrate/20221207135831_finalize_add_projects_emails_enabled_column_data.rb22
-rw-r--r--db/post_migrate/20230104103748_remove_new_amount_used_column.rb4
-rw-r--r--db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb4
-rw-r--r--db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb2
-rw-r--r--db/post_migrate/20230202211434_migrate_redis_slot_keys.rb102
-rw-r--r--db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb82
-rw-r--r--db/post_migrate/20230310020356_swap_merge_request_user_mentions_note_id_to_bigint_2.rb93
-rw-r--r--db/post_migrate/20230316185746_drop_packages_events_table.rb2
-rw-r--r--db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb89
-rw-r--r--db/post_migrate/20230323131521_remove_machine_id_from_builds_metadata.rb2
-rw-r--r--db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb99
-rw-r--r--db/post_migrate/20230412141541_reschedule_links_avoiding_duplication.rb16
-rw-r--r--db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb6
-rw-r--r--db/post_migrate/20230425114355_remove_application_settings_clickhouse_connection_string.rb2
-rw-r--r--db/post_migrate/20230426030342_index_system_note_metadata_on_id_for_relate_and_unrelate_actions.rb19
-rw-r--r--db/post_migrate/20230426085615_queue_backfill_resource_link_events.rb43
-rw-r--r--db/post_migrate/20230501180958_drop_clusters_applications_cert_managers.rb2
-rw-r--r--db/post_migrate/20230502102833_add_index_to_members_on_source_and_type_and_access_level.rb15
-rw-r--r--db/post_migrate/20230502120022_add_index_to_project_authorizations_on_project_user_access_level.rb15
-rw-r--r--db/post_migrate/20230502134532_drop_clusters_applications_cilium.rb2
-rw-r--r--db/post_migrate/20230502182754_drop_clusters_applications_crossplane.rb2
-rw-r--r--db/post_migrate/20230502193525_drop_clusters_applications_helm.rb2
-rw-r--r--db/post_migrate/20230502201251_drop_clusters_applications_ingress.rb2
-rw-r--r--db/post_migrate/20230503115918_drop_clusters_applications_jupyter.rb2
-rw-r--r--db/post_migrate/20230503152349_drop_clusters_applications_knative.rb2
-rw-r--r--db/post_migrate/20230503173101_drop_clusters_applications_prometheus.rb2
-rw-r--r--db/post_migrate/20230503175406_drop_clusters_applications_runners.rb2
-rw-r--r--db/post_migrate/20230503181808_drop_serverless_domain_cluster.rb2
-rw-r--r--db/post_migrate/20230508175057_backfill_corrected_secure_files_expirations.rb25
-rw-r--r--db/post_migrate/20230510013754_cleanup_notes_bigint_preparation.rb51
-rw-r--r--db/post_migrate/20230510062503_queue_cleanup_personal_access_tokens_with_nil_expires_at.rb30
-rw-r--r--db/post_migrate/20230510130050_remove_ci_triggers_ref_column.rb2
-rw-r--r--db/post_migrate/20230510152153_remove_mr_state_id_temp_index_with_right_column.rb15
-rw-r--r--db/post_migrate/20230511132140_create_component_id_index.rb17
-rw-r--r--db/post_migrate/20230512104238_add_audit_events_group_index.rb19
-rw-r--r--db/post_migrate/20230512143000_remove_dependency_list_exports_project_id_not_null_constraint.rb11
-rw-r--r--db/post_migrate/20230515101208_index_group_id_on_dependency_list_exports.rb15
-rw-r--r--db/post_migrate/20230515102353_add_foreign_key_to_group_id_on_dependency_list_exports.rb17
-rw-r--r--db/post_migrate/20230515142300_add_unique_index_for_ml_model_packages.rb19
-rw-r--r--db/post_migrate/20230515153600_finalize_back_fill_prepared_at_merge_requests.rb25
-rw-r--r--db/post_migrate/20230516032545_add_unique_notes_id_convert_to_bigint_for_gitlab_com.rb34
-rw-r--r--db/post_migrate/20230516033729_add_referencing_bigint_fks_for_notes_on_gitlab_com.rb74
-rw-r--r--db/post_migrate/20230516123202_create_routing_table_for_ci_builds.rb93
-rw-r--r--db/post_migrate/20230516172446_prepare_issues_work_item_type_id_project_id_index.rb14
-rw-r--r--db/post_migrate/20230516192543_add_issues_work_item_type_id_project_id_index.rb15
-rw-r--r--db/post_migrate/20230517001535_prepare_async_index_for_ci_pipeline_variables_bigint_id.rb15
-rw-r--r--db/post_migrate/20230517005523_ensure_backfill_bigint_id_is_completed.rb23
-rw-r--r--db/post_migrate/20230517163300_queue_backfill_root_storage_statistics_fork_storage_sizes.rb25
-rw-r--r--db/post_migrate/20230518005523_add_concurrent_index_for_ci_pipeline_variables_bigint_id.rb18
-rw-r--r--db/post_migrate/20230518071251_queue_backfill_code_suggestions_namespace_settings.rb23
-rw-r--r--db/post_migrate/20230518121320_remove_time_format_in_24h_column.rb13
-rw-r--r--db/post_migrate/20230519011151_schedule_to_remove_invalid_deploy_access_level_groups.rb23
-rw-r--r--db/post_migrate/20230519023720_swap_ci_pipeline_variables_pk_with_bigint.rb75
-rw-r--r--db/post_migrate/20230521521419_drop_merge_request_state_id_temp_index.rb16
-rw-r--r--db/post_migrate/20230522073230_add_not_null_constraint_to_personal_access_tokens_expires_at.rb13
-rw-r--r--db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb32
-rw-r--r--db/post_migrate/20230522220709_ensure_incident_work_item_type_backfill_is_finished.rb37
-rw-r--r--db/post_migrate/20230522225610_remove_tmp_index_issues_on_issue_type_and_id_only_incidents.rb16
-rw-r--r--db/post_migrate/20230523125245_remove_project_ci_cd_setting_opt_in_jwt_column.rb13
-rw-r--r--db/post_migrate/20230523131914_recreate_index_on_vulnerability_reads.rb34
-rw-r--r--db/post_migrate/20230523132647_recreate_index_on_vulnerability_reads2.rb34
-rw-r--r--db/post_migrate/20230523210653_remove_file_md5_from_debian_project_component_files.rb9
-rw-r--r--db/post_migrate/20230523210758_remove_file_md5_from_debian_group_component_files.rb9
-rw-r--r--db/post_migrate/20230524093249_add_async_index_to_vsa_issues.rb39
-rw-r--r--db/post_migrate/20230524093355_add_async_index_to_vsa_mrs.rb39
-rw-r--r--db/post_migrate/20230524120241_add_temp_index_to_packages_on_project_id_when_npm_and_not_pending_destruction.rb23
-rw-r--r--db/post_migrate/20230524135543_replace_ci_build_pending_states_foreign_key.rb23
-rw-r--r--db/post_migrate/20230524135555_replace_ci_build_trace_chunks_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135607_replace_ci_unit_test_failures_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135620_replace_ci_sources_pipelines_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135632_replace_ci_resources_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135645_replace_ci_build_report_results_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135658_replace_ci_build_needs_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135711_replace_ci_builds_runner_session_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135724_replace_ci_pending_builds_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135737_replace_ci_build_trace_metadata_foreign_key.rb24
-rw-r--r--db/post_migrate/20230524135750_replace_ci_job_artifacts_foreign_key.rb13
-rw-r--r--db/post_migrate/20230524135803_replace_ci_running_builds_foreign_key.rb13
-rw-r--r--db/post_migrate/20230524135815_replace_ci_job_variables_foreign_key.rb13
-rw-r--r--db/post_migrate/20230524135828_replace_p_ci_builds_metadata_foreign_key.rb13
-rw-r--r--db/post_migrate/20230524135840_replace_p_ci_runner_machine_builds_foreign_key.rb13
-rw-r--r--db/post_migrate/20230524150232_remove_index_user_details_on_user_id_for_enterprise_users_without_date.rb19
-rw-r--r--db/post_migrate/20230524150438_remove_index_user_details_on_user_id_for_enterprise_users_with_date.rb19
-rw-r--r--db/post_migrate/20230524201454_queue_mark_duplicate_npm_packages_for_destruction.rb29
-rw-r--r--db/post_migrate/20230525180605_add_index_work_item_types_on_base_type_id.rb15
-rw-r--r--db/post_migrate/20230529183648_remove_temporary_billable_index.rb18
-rw-r--r--db/post_migrate/20230529185110_cleanup_temporary_activity_index.rb17
-rw-r--r--db/post_migrate/20230530003634_cleanup_tofa_settings.rb23
-rw-r--r--db/post_migrate/20230530015535_swap_notes_id_to_bigint_for_gitlab_dot_com.rb195
-rw-r--r--db/post_migrate/20230530100400_change_user_type_null.rb13
-rw-r--r--db/post_migrate/20230530114845_cleanup_organizations_with_null_path.rb18
-rw-r--r--db/post_migrate/20230530115830_remove_default_on_organization_path.rb11
-rw-r--r--db/post_migrate/20230530140456_validate_fk_ci_build_pending_states_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140509_validate_fk_ci_build_trace_chunks_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140521_validate_fk_ci_unit_test_failures_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140534_validate_fk_ci_sources_pipelines_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140546_validate_fk_ci_resources_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140558_validate_fk_ci_build_report_results_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140611_validate_fk_ci_build_needs_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140623_validate_fk_ci_builds_runner_session_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140634_validate_fk_ci_pending_builds_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230530140646_validate_fk_ci_build_trace_metadata_p_ci_builds.rb11
-rw-r--r--db/post_migrate/20230531165731_drop_index_issues_on_work_item_type_id.rb (renamed from db/post_migrate/20220315181125_remove_issues_work_item_type_id_index.rb)8
-rw-r--r--db/post_migrate/20230601184234_drop_unnecessary_async_index_from_events.rb13
-rw-r--r--db/post_migrate/20230602063059_remove_broadcast_messages_namespace_id_column.rb17
-rw-r--r--db/post_migrate/20230602112904_change_user_preferences_defaults.rb11
-rw-r--r--db/post_migrate/20230602131429_change_notified_of_own_activity_default.rb9
-rw-r--r--db/post_migrate/20230605085936_add_new_index_to_vsa_issue_stage_events.rb19
-rw-r--r--db/post_migrate/20230605085957_add_new_index_to_vsa_mr_stage_events.rb19
-rw-r--r--db/post_migrate/20230605093005_add_index_for_sbom_occurrences_on_project_id_source_id.rb15
-rw-r--r--db/post_migrate/20230605192000_drop_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb18
-rw-r--r--db/post_migrate/20230606183327_add_index_user_details_on_enterprise_group_id.rb21
-rw-r--r--db/post_migrate/20230606193037_create_index_alert_management_alerts_on_created_at_project_id_with_issue.rb17
-rw-r--r--db/post_migrate/20230607093222_remove_webauthn_registrations_u2f_registration_id_column.rb21
-rw-r--r--db/post_migrate/20230607165632_remove_fk_on_project_id_on_project_wiki_repository_states.rb20
-rw-r--r--db/post_migrate/20230607165718_drop_project_wiki_repository_states.rb57
-rw-r--r--db/post_migrate/20230608071301_requeue_cleanup_personal_access_tokens_with_nil_expires_at.rb25
-rw-r--r--db/post_migrate/20230608081257_delete_index_members_on_source_id_and_source_type.rb15
-rw-r--r--db/post_migrate/20230608081924_delete_index_unique_project_authorizations_on_project_id_user_id.rb15
-rw-r--r--db/post_migrate/20230608101503_add_ci_job_annotations_foreign_key.rb22
-rw-r--r--db/post_migrate/20230608231452_cleanup_bigint_conversion_for_todos_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230608232452_cleanup_bigint_conversion_for_system_note_metadata_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230608233452_cleanup_bigint_conversion_for_epic_user_mentions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230608234452_cleanup_bigint_conversion_for_suggestions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230608235452_cleanup_bigint_conversion_for_issue_user_mentions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609000452_cleanup_bigint_conversion_for_note_diff_files_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609001452_cleanup_bigint_conversion_for_snippet_user_mentions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609002452_cleanup_bigint_conversion_for_design_user_mentions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609003452_cleanup_bigint_conversion_for_vulnerability_user_mentions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609004452_cleanup_bigint_conversion_for_commit_user_mentions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609005452_cleanup_bigint_conversion_for_merge_request_user_mentions_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609010452_cleanup_bigint_conversion_for_timelogs_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230609011452_cleanup_bigint_conversion_for_award_emoji_for_gitlab_com.rb28
-rw-r--r--db/post_migrate/20230612075608_replace_ci_job_artifacts_foreign_key_v2.rb36
-rw-r--r--db/post_migrate/20230612083337_replace_ci_running_builds_foreign_key_v2.rb36
-rw-r--r--db/post_migrate/20230612083655_replace_ci_job_variables_foreign_key_v2.rb36
-rw-r--r--db/post_migrate/20230612083810_replace_p_ci_builds_metadata_foreign_key_v2.rb40
-rw-r--r--db/post_migrate/20230612084013_replace_p_ci_runner_machine_builds_foreign_key_v2.rb40
-rw-r--r--db/post_migrate/20230612162643_pm_checkpoints_remove_advisory_entries.rb18
-rw-r--r--db/post_migrate/20230614073136_restore_index_for_contribution_analytics_events.rb15
-rw-r--r--db/post_migrate/20230614181637_add_idx_issues_on_work_item_type_project_closed_at_where_closed.rb15
-rw-r--r--db/post_migrate/20230615083713_replace_old_fk_ci_build_pending_states_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083715_replace_old_fk_ci_build_trace_chunks_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083720_replace_old_fk_ci_unit_test_failures_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083725_replace_old_fk_ci_sources_pipelines_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083730_replace_old_fk_ci_resources_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083734_replace_old_fk_ci_build_report_results_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083738_replace_old_fk_ci_build_needs_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083741_replace_old_fk_ci_builds_runner_session_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083744_replace_old_fk_ci_pending_builds_to_builds.rb45
-rw-r--r--db/post_migrate/20230615083748_replace_old_fk_ci_build_trace_metadata_to_builds.rb45
-rw-r--r--db/post_migrate/20230615202125_prepare_index_issues_on_project_health_status_asc_work_item_type.rb16
-rw-r--r--db/post_migrate/20230615202511_prepare_index_issues_on_project_health_status_desc_work_item_type.rb16
373 files changed, 3605 insertions, 4682 deletions
diff --git a/db/post_migrate/20211202145237_add_todos_project_and_id_index.rb b/db/post_migrate/20211202145237_add_todos_project_and_id_index.rb
deleted file mode 100644
index 69f7822c057..00000000000
--- a/db/post_migrate/20211202145237_add_todos_project_and_id_index.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-# See https://docs.gitlab.com/ee/development/migration_style_guide.html
-# for more information on how to write migrations for GitLab.
-
-class AddTodosProjectAndIdIndex < Gitlab::Database::Migration[1.0]
- # When using the methods "add_concurrent_index" or "remove_concurrent_index"
- # you must disable the use of transactions
- # as these methods can not run in an existing transaction.
- # When using "add_concurrent_index" or "remove_concurrent_index" methods make sure
- # that either of them is the _only_ method called in the migration,
- # any other changes should go in a separate migration.
- # This ensures that upon failure _only_ the index creation or removing fails
- # and can be retried or reverted easily.
- #
- # To disable transactions uncomment the following line and remove these
- # comments:
- disable_ddl_transaction!
-
- NEW_INDEX_NAME = 'index_todos_on_project_id_and_id'
- OLD_INDEX_NAME = 'index_todos_on_project_id'
-
- def up
- add_concurrent_index :todos, [:project_id, :id], name: NEW_INDEX_NAME
- remove_concurrent_index_by_name :todos, OLD_INDEX_NAME
- end
-
- def down
- add_concurrent_index :todos, :project_id, name: OLD_INDEX_NAME
- remove_concurrent_index_by_name :todos, NEW_INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211203091642_add_index_to_projects_on_marked_for_deletion_at.rb b/db/post_migrate/20211203091642_add_index_to_projects_on_marked_for_deletion_at.rb
deleted file mode 100644
index 56b0df1f393..00000000000
--- a/db/post_migrate/20211203091642_add_index_to_projects_on_marked_for_deletion_at.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToProjectsOnMarkedForDeletionAt < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_projects_not_aimed_for_deletion'
-
- def up
- add_concurrent_index :projects, :id, where: 'marked_for_deletion_at IS NULL', name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index :projects, :id, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211206073851_create_calendar_events_index_synchronously.rb b/db/post_migrate/20211206073851_create_calendar_events_index_synchronously.rb
deleted file mode 100644
index 020dceac004..00000000000
--- a/db/post_migrate/20211206073851_create_calendar_events_index_synchronously.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class CreateCalendarEventsIndexSynchronously < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_events_author_id_project_id_action_target_type_created_at'
-
- def up
- add_concurrent_index :events, [:author_id, :project_id, :action, :target_type, :created_at], name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :events, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211206074547_remove_old_calendar_events_index.rb b/db/post_migrate/20211206074547_remove_old_calendar_events_index.rb
deleted file mode 100644
index 51460a9dc95..00000000000
--- a/db/post_migrate/20211206074547_remove_old_calendar_events_index.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-# See https://docs.gitlab.com/ee/development/migration_style_guide.html
-# for more information on how to write migrations for GitLab.
-
-class RemoveOldCalendarEventsIndex < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- OLD_INDEX_NAME = 'index_events_on_author_id_and_project_id'
-
- def up
- remove_concurrent_index_by_name :events, OLD_INDEX_NAME
- end
-
- def down
- add_concurrent_index :events, [:author_id, :project_id], name: OLD_INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb b/db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb
deleted file mode 100644
index 0e370dfc5f8..00000000000
--- a/db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexesForPrimaryEmailCleanupMigration < Gitlab::Database::Migration[1.0]
- USERS_INDEX = :index_users_on_id_for_primary_email_migration
- EMAIL_INDEX = :index_emails_on_email_user_id
-
- disable_ddl_transaction!
-
- def up
- unless index_exists_by_name?(:users, USERS_INDEX)
-
- disable_statement_timeout do
- execute <<~SQL
- CREATE INDEX CONCURRENTLY #{USERS_INDEX}
- ON users (id) INCLUDE (email, confirmed_at)
- WHERE confirmed_at IS NOT NULL
- SQL
- end
- end
-
- add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX
- end
-
- def down
- remove_concurrent_index_by_name :users, USERS_INDEX
- remove_concurrent_index_by_name :emails, EMAIL_INDEX
- end
-end
diff --git a/db/post_migrate/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb b/db/post_migrate/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb
deleted file mode 100644
index 959bf61a6cc..00000000000
--- a/db/post_migrate/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexCiJobArtifactsProjectIdFileType < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_ci_job_artifacts_on_id_project_id_and_file_type'
-
- def up
- add_concurrent_index :ci_job_artifacts, [:project_id, :file_type, :id], name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211207090503_cleanup_first_mentioned_in_commit_jobs.rb b/db/post_migrate/20211207090503_cleanup_first_mentioned_in_commit_jobs.rb
deleted file mode 100644
index 3788a680fb6..00000000000
--- a/db/post_migrate/20211207090503_cleanup_first_mentioned_in_commit_jobs.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupFirstMentionedInCommitJobs < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'FixFirstMentionedInCommitAt'
- INDEX_NAME = 'index_issue_metrics_first_mentioned_in_commit'
-
- def up
- finalize_background_migration(MIGRATION)
-
- remove_concurrent_index_by_name :issue_metrics, name: INDEX_NAME
- end
-
- def down
- # Handles reported schema inconsistencies (column with or without timezone)
- # We did the same in db/post_migrate/20211004110500_add_temporary_index_to_issue_metrics.rb
- condition = Gitlab::BackgroundMigration::FixFirstMentionedInCommitAt::TmpIssueMetrics
- .first_mentioned_in_commit_at_condition
- add_concurrent_index :issue_metrics, :issue_id, where: condition, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb b/db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
deleted file mode 100644
index cc37f2dc65d..00000000000
--- a/db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveJobsForRecalculateVulnerabilitiesOccurrencesUuid < Gitlab::Database::Migration[1.0]
- MIGRATION_NAME = 'RecalculateVulnerabilitiesOccurrencesUuid'
-
- def up
- delete_job_tracking(
- MIGRATION_NAME,
- status: %w[pending succeeded]
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb b/db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb
deleted file mode 100644
index 13abf8b5540..00000000000
--- a/db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleRecalculateUuidOnVulnerabilitiesOccurrences4 < Gitlab::Database::Migration[1.0]
- MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 2_500
-
- disable_ddl_transaction!
-
- def up
- # Make sure the migration removing Findings with attributes for which UUID would be identical
- # has finished
- # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74008
- Gitlab::BackgroundMigration.steal('RemoveOccurrencePipelinesAndDuplicateVulnerabilitiesFindings')
-
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('vulnerability_occurrences'),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb b/db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb
deleted file mode 100644
index eaf07abe29d..00000000000
--- a/db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveExtraFindingEvidenceTablesForeignKeys < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key :vulnerability_finding_evidence_assets, :vulnerability_finding_evidences
- remove_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_requests
- remove_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_responses
- remove_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidences
- remove_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidence_supporting_messages
- remove_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidences
- remove_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidence_supporting_messages
- remove_foreign_key :vulnerability_finding_evidence_sources, :vulnerability_finding_evidences
- remove_foreign_key :vulnerability_finding_evidence_supporting_messages, :vulnerability_finding_evidences
- end
- end
-
- def down
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_assets, :vulnerability_finding_evidences, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_requests, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_responses, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidences, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidence_supporting_messages, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidences, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidence_supporting_messages, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_sources, :vulnerability_finding_evidences, on_delete: :cascade
- end
-
- with_lock_retries do
- add_foreign_key :vulnerability_finding_evidence_supporting_messages, :vulnerability_finding_evidences, on_delete: :cascade
- end
- end
-end
diff --git a/db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb b/db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb
deleted file mode 100644
index 9a246a8c707..00000000000
--- a/db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveExtraFindingEvidenceTables < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- drop_table :vulnerability_finding_evidence_assets, if_exists: true
- drop_table :vulnerability_finding_evidence_headers, if_exists: true
- drop_table :vulnerability_finding_evidence_requests, if_exists: true
- drop_table :vulnerability_finding_evidence_responses, if_exists: true
- drop_table :vulnerability_finding_evidence_sources, if_exists: true
- drop_table :vulnerability_finding_evidence_supporting_messages, if_exists: true
- end
- end
-
- def down
- create_table :vulnerability_finding_evidence_assets, if_not_exists: true do |t|
- t.timestamps_with_timezone null: false
-
- t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_assets_on_finding_evidence_id' }, null: false
- t.text :type, limit: 2048
- t.text :name, limit: 2048
- t.text :url, limit: 2048
- end
-
- create_table :vulnerability_finding_evidence_sources, if_not_exists: true do |t|
- t.timestamps_with_timezone null: false
-
- t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_sources_on_finding_evidence_id' }, null: false
- t.text :name, limit: 2048
- t.text :url, limit: 2048
- end
-
- create_table :vulnerability_finding_evidence_supporting_messages, if_not_exists: true do |t|
- t.timestamps_with_timezone null: false
-
- t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_supporting_messages_on_finding_evidence_id' }, null: false
- t.text :name, limit: 2048
- end
-
- create_table :vulnerability_finding_evidence_requests, if_not_exists: true do |t|
- t.timestamps_with_timezone null: false
-
- t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_requests_on_finding_evidence_id' }, null: true
- t.text :method, limit: 32
- t.text :url, limit: 2048
- t.text :body, limit: 2048
- t.references :vulnerability_finding_evidence_supporting_message, index: { name: 'finding_evidence_requests_on_supporting_evidence_id' }, null: true
- end
-
- create_table :vulnerability_finding_evidence_responses, if_not_exists: true do |t|
- t.timestamps_with_timezone null: false
-
- t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_responses_on_finding_evidences_id' }, null: true
- t.integer :status_code
- t.text :reason_phrase, limit: 2048
- t.text :body, limit: 2048
- t.references :vulnerability_finding_evidence_supporting_message, index: { name: 'finding_evidence_responses_on_supporting_evidence_id' }, null: true
- end
-
- create_table :vulnerability_finding_evidence_headers, if_not_exists: true do |t|
- t.timestamps_with_timezone null: false
-
- t.references :vulnerability_finding_evidence_request, index: { name: 'finding_evidence_header_on_finding_evidence_request_id' }, null: true
- t.references :vulnerability_finding_evidence_response, index: { name: 'finding_evidence_header_on_finding_evidence_response_id' }, null: true
- t.text :name, null: false, limit: 255
- t.text :value, null: false, limit: 8192
- end
- end
-end
diff --git a/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb b/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb
deleted file mode 100644
index e42b74748d7..00000000000
--- a/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleBackfillCiNamespaceMirrors < Gitlab::Database::Migration[1.0]
- def up
- # no-op
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb b/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb
deleted file mode 100644
index 2a58eda040e..00000000000
--- a/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleBackfillCiProjectMirrors < Gitlab::Database::Migration[1.0]
- def up
- # no-op
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211208171402_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb b/db/post_migrate/20211208171402_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb
deleted file mode 100644
index 8eee082809b..00000000000
--- a/db/post_migrate/20211208171402_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class RescheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Database::Migration[1.0]
- MIGRATION = 'RecalculateVulnerabilityFindingSignaturesForFindings'
- BATCH_SIZE = 1_000
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
- # Due to production incident previous migration was orphaned and must be rescheduled,
- # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72919#note_741188600
- def up
- return unless Gitlab.ee?
-
- delete_queued_jobs(MIGRATION)
-
- requeue_background_migration_jobs_by_range_at_intervals(
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211209093636_track_ci_job_artifacts_deletes.rb b/db/post_migrate/20211209093636_track_ci_job_artifacts_deletes.rb
deleted file mode 100644
index 8c95c76d1fe..00000000000
--- a/db/post_migrate/20211209093636_track_ci_job_artifacts_deletes.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class TrackCiJobArtifactsDeletes < Gitlab::Database::Migration[1.0]
- include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
-
- enable_lock_retries!
-
- def up
- track_record_deletions(:ci_job_artifacts)
- end
-
- def down
- untrack_record_deletions(:ci_job_artifacts)
- end
-end
diff --git a/db/post_migrate/20211209093828_track_users_deletes.rb b/db/post_migrate/20211209093828_track_users_deletes.rb
deleted file mode 100644
index e25a8a36cb2..00000000000
--- a/db/post_migrate/20211209093828_track_users_deletes.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class TrackUsersDeletes < Gitlab::Database::Migration[1.0]
- include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
-
- enable_lock_retries!
-
- def up
- track_record_deletions(:users)
- end
-
- def down
- untrack_record_deletions(:users)
- end
-end
diff --git a/db/post_migrate/20211209093923_track_external_pull_requests_deletes.rb b/db/post_migrate/20211209093923_track_external_pull_requests_deletes.rb
deleted file mode 100644
index cd8a6baf407..00000000000
--- a/db/post_migrate/20211209093923_track_external_pull_requests_deletes.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class TrackExternalPullRequestsDeletes < Gitlab::Database::Migration[1.0]
- include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
-
- enable_lock_retries!
-
- def up
- track_record_deletions(:external_pull_requests)
- end
-
- def down
- untrack_record_deletions(:external_pull_requests)
- end
-end
diff --git a/db/post_migrate/20211209094222_track_merge_requests_deletes.rb b/db/post_migrate/20211209094222_track_merge_requests_deletes.rb
deleted file mode 100644
index 51007082e9e..00000000000
--- a/db/post_migrate/20211209094222_track_merge_requests_deletes.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class TrackMergeRequestsDeletes < Gitlab::Database::Migration[1.0]
- include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
-
- enable_lock_retries!
-
- def up
- track_record_deletions(:merge_requests)
- end
-
- def down
- untrack_record_deletions(:merge_requests)
- end
-end
diff --git a/db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb b/db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb
deleted file mode 100644
index 44dffc798d3..00000000000
--- a/db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillProjectNamespacesForGroup < Gitlab::Database::Migration[1.0]
- MIGRATION = 'ProjectNamespaces::BackfillProjectNamespaces'
- DELAY_INTERVAL = 2.minutes
- GROUP_ID = 9970 # picking gitlab-org group.
-
- disable_ddl_transaction!
-
- def up
- return unless Gitlab.com? || Gitlab.staging?
-
- projects_table = ::Gitlab::BackgroundMigration::ProjectNamespaces::Models::Project.arel_table
- hierarchy_cte_sql = Arel.sql(::Gitlab::BackgroundMigration::ProjectNamespaces::BackfillProjectNamespaces.hierarchy_cte(GROUP_ID))
- group_projects = ::Gitlab::BackgroundMigration::ProjectNamespaces::Models::Project.where(projects_table[:namespace_id].in(hierarchy_cte_sql))
-
- min_id = group_projects.minimum(:id)
- max_id = group_projects.maximum(:id)
-
- return if min_id.blank? || max_id.blank?
-
- queue_batched_background_migration(
- MIGRATION,
- :projects,
- :id,
- GROUP_ID,
- 'up',
- job_interval: DELAY_INTERVAL,
- batch_min_value: min_id,
- batch_max_value: max_id,
- sub_batch_size: 25,
- batch_class_name: 'BackfillProjectNamespacePerGroupBatchingStrategy'
- )
- end
-
- def down
- return unless Gitlab.com? || Gitlab.staging?
-
- delete_batched_background_migration(MIGRATION, :projects, :id, [GROUP_ID, 'up'])
- end
-end
diff --git a/db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb b/db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb
deleted file mode 100644
index 07a2c079511..00000000000
--- a/db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-class AddTmpIndexOnReportType < Gitlab::Database::Migration[1.0]
- # Temporary index to perform migration fixing invalid vulnerability_occurrences.raw_metadata rows
- # Will be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/349605
- INDEX_NAME = 'tmp_idx_vulnerability_occurrences_on_id_where_report_type_7_99'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :vulnerability_occurrences, :id, where: 'report_type IN (7, 99)', name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb b/db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb
deleted file mode 100644
index 757cbf60d4d..00000000000
--- a/db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-class ConvertStringifiedRawMetadataHashToJson < Gitlab::Database::Migration[1.0]
- MIGRATION_CLASS = Gitlab::BackgroundMigration::FixVulnerabilityOccurrencesWithHashesAsRawMetadata
- MODEL_CLASS = MIGRATION_CLASS::Finding
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 500
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- MODEL_CLASS.by_api_report_types,
- MIGRATION_CLASS,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
-
- # up fixes invalid data by updating columns in-place.
- # It is a backwards-compatible change, and reversing it in a downgrade would not be desirable.
- end
-end
diff --git a/db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb b/db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb
deleted file mode 100644
index 54997dc4cc4..00000000000
--- a/db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddTemporaryStaticObjectTokenIndex < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_users_with_static_object_token'
-
- def up
- add_concurrent_index :users, :id, where: "static_object_token IS NOT NULL AND static_object_token_encrypted IS NULL", name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index :users, :id, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211210140629_encrypt_static_object_token.rb b/db/post_migrate/20211210140629_encrypt_static_object_token.rb
deleted file mode 100644
index fe4db9fc14c..00000000000
--- a/db/post_migrate/20211210140629_encrypt_static_object_token.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class EncryptStaticObjectToken < Gitlab::Database::Migration[1.0]
- BATCH_SIZE = 10_000
- MIGRATION = 'EncryptStaticObjectToken'
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('users').where.not(static_object_token: nil).where(static_object_token_encrypted: nil),
- MIGRATION,
- 2.minutes,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no ops
- end
-end
diff --git a/db/post_migrate/20211210173137_remove_vulnerability_finding_links_again.rb b/db/post_migrate/20211210173137_remove_vulnerability_finding_links_again.rb
deleted file mode 100644
index ffe8bf0d794..00000000000
--- a/db/post_migrate/20211210173137_remove_vulnerability_finding_links_again.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveVulnerabilityFindingLinksAgain < Gitlab::Database::Migration[1.0]
- # This migration has been moved to a TRUNCATE in db/post_migrate/20220201193033_add_unique_index_to_vulnerability_finding_links_with_truncate.rb
- # Previously, this was causing an bug where there was a conflict between the table cleanup and the index creation.
-
- def up
- # no op
- end
-
- def down
- # no op
- end
-end
diff --git a/db/post_migrate/20211213064821_add_agent_id_location_index_to_vulnerability_occurrences.rb b/db/post_migrate/20211213064821_add_agent_id_location_index_to_vulnerability_occurrences.rb
deleted file mode 100644
index 92b5a1b085c..00000000000
--- a/db/post_migrate/20211213064821_add_agent_id_location_index_to_vulnerability_occurrences.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class AddAgentIdLocationIndexToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_vulnerability_occurrences_on_location_agent_id'
-
- def up
- add_concurrent_index :vulnerability_occurrences, "(location -> 'agent_id')",
- using: 'GIN',
- where: 'report_type = 7',
- name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb b/db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb
deleted file mode 100644
index 49f498c911d..00000000000
--- a/db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class DropCiPipelinesMrMetricsFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:merge_request_metrics, :ci_pipelines, name: "fk_rails_33ae169d48")
- end
- end
-
- def down
- add_concurrent_foreign_key(:merge_request_metrics, :ci_pipelines, name: "fk_rails_33ae169d48", column: :pipeline_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb b/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb
deleted file mode 100644
index f8239b6e0cd..00000000000
--- a/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillIncidentIssueEscalationStatuses < Gitlab::Database::Migration[1.0]
- # Removed in favor of creating records for existing incidents
- # as-needed. See db/migrate/20220321234317_remove_all_issuable_escalation_statuses.rb.
- def change
- # no-op
- end
-end
diff --git a/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb b/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb
deleted file mode 100644
index 5876d3f8a9a..00000000000
--- a/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleUpdateTimelogsNullSpentAt < Gitlab::Database::Migration[1.0]
- DOWNTIME = false
- BATCH_SIZE = 5_000
- DELAY_INTERVAL = 2.minutes
- MIGRATION = 'UpdateTimelogsNullSpentAt'
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('timelogs').where(spent_at: nil),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb b/db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb
deleted file mode 100644
index 310a49a667e..00000000000
--- a/db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-class ModifyKubernetesResourceLocationIndexToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- OLD_CLUSTER_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_cluster_id'
- OLD_AGENT_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_agent_id'
-
- NEW_CLUSTER_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_k8s_cluster_id'
- NEW_AGENT_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_k8s_agent_id'
-
- def up
- add_concurrent_index :vulnerability_occurrences, "(location -> 'kubernetes_resource' -> 'cluster_id')",
- using: 'GIN',
- where: 'report_type = 7',
- name: NEW_CLUSTER_ID_INDEX_NAME
-
- add_concurrent_index :vulnerability_occurrences, "(location -> 'kubernetes_resource' -> 'agent_id')",
- using: 'GIN',
- where: 'report_type = 7',
- name: NEW_AGENT_ID_INDEX_NAME
-
- remove_concurrent_index_by_name :vulnerability_occurrences, OLD_CLUSTER_ID_INDEX_NAME
- remove_concurrent_index_by_name :vulnerability_occurrences, OLD_AGENT_ID_INDEX_NAME
- end
-
- def down
- add_concurrent_index :vulnerability_occurrences, "(location -> 'cluster_id')",
- using: 'GIN',
- where: 'report_type = 7',
- name: OLD_CLUSTER_ID_INDEX_NAME
-
- add_concurrent_index :vulnerability_occurrences, "(location -> 'agent_id')",
- using: 'GIN',
- where: 'report_type = 7',
- name: OLD_AGENT_ID_INDEX_NAME
-
- remove_concurrent_index_by_name :vulnerability_occurrences, NEW_CLUSTER_ID_INDEX_NAME
- remove_concurrent_index_by_name :vulnerability_occurrences, NEW_AGENT_ID_INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb b/db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb
deleted file mode 100644
index a05d68279c3..00000000000
--- a/db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToEventsOnAuthorIdAndActionAndId < Gitlab::Database::Migration[1.0]
- # no-op
- # see: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77436
-
- def up
- # no-op
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb b/db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb
deleted file mode 100644
index 316209ae1f4..00000000000
--- a/db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class MarkRecalculateFindingSignaturesAsCompleted < Gitlab::Database::Migration[1.0]
- MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid'
-
- def up
- # Only run migration for Gitlab.com
- return unless ::Gitlab.com?
-
- # In previous migration marking jobs as successful was missed
- Gitlab::Database::BackgroundMigrationJob
- .for_migration_class(MIGRATION)
- .pending
- .update_all(status: :succeeded)
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb b/db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb
deleted file mode 100644
index 1d61aec401e..00000000000
--- a/db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class DropTemporaryIndexesForPrimaryEmailMigration < Gitlab::Database::Migration[1.0]
- USERS_INDEX = :index_users_on_id_for_primary_email_migration
- EMAIL_INDEX = :index_emails_on_email_user_id
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index_by_name :users, USERS_INDEX
- remove_concurrent_index_by_name :emails, EMAIL_INDEX
- end
-
- def down
- unless index_exists_by_name?(:users, USERS_INDEX)
-
- disable_statement_timeout do
- execute <<~SQL
- CREATE INDEX CONCURRENTLY #{USERS_INDEX}
- ON users (id) INCLUDE (email, confirmed_at)
- WHERE confirmed_at IS NOT NULL
- SQL
- end
- end
-
- add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX
- end
-end
diff --git a/db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb b/db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb
deleted file mode 100644
index c98d3d05f2f..00000000000
--- a/db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexOnCiPipelinesUserIdIdFailureReason < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_ci_pipelines_on_user_id_and_id_desc_and_user_not_verified'
-
- def up
- add_concurrent_index :ci_pipelines, [:user_id, :id], order: { id: :desc }, where: 'failure_reason = 3', name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :ci_pipelines, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211220123956_update_invalid_member_states.rb b/db/post_migrate/20211220123956_update_invalid_member_states.rb
deleted file mode 100644
index 5da100f0ec2..00000000000
--- a/db/post_migrate/20211220123956_update_invalid_member_states.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-class UpdateInvalidMemberStates < Gitlab::Database::Migration[1.0]
- class Member < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'members'
-
- scope :in_invalid_state, -> { where(state: 2) }
- end
-
- def up
- Member.in_invalid_state.each_batch do |relation|
- relation.update_all(state: 0)
- end
- end
-
- def down
- # no-op as we don't need to revert any changed records
- end
-end
diff --git a/db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb b/db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb
deleted file mode 100644
index 5338cab3871..00000000000
--- a/db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddAsyncIndexCiJobArtifactsProjectIdFileType < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_ci_job_artifacts_on_id_project_id_and_file_type'
-
- def up
- prepare_async_index :ci_job_artifacts, [:project_id, :file_type, :id], name: INDEX_NAME
- end
-
- def down
- unprepare_async_index_by_name :ci_job_artifacts, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb b/db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb
deleted file mode 100644
index 2215a49e286..00000000000
--- a/db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveIndexEventsOnAuthorIdAndActionAndId < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_events_on_author_id_and_action_and_id'
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index_by_name :events, name: INDEX_NAME
- end
-
- def down
- # no-op
- # The index had been added in the same milestone.
- # Adding back the index takes a long time and should not be needed.
- end
-end
diff --git a/db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb b/db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb
deleted file mode 100644
index e4cdc9add39..00000000000
--- a/db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToEventsOnAuthorIdAndId < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_events_on_author_id_and_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :events, [:author_id, :id], name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :events, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb b/db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb
deleted file mode 100644
index 9be81e00b50..00000000000
--- a/db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveForeignKeyCiGroupVariablesGroupId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_33ae4d58d8'
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_group_variables, :namespaces, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key :ci_group_variables, :namespaces, column: :group_id, on_delete: :cascade, name: CONSTRAINT_NAME
- end
-end
diff --git a/db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb b/db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb
deleted file mode 100644
index b072d5616f5..00000000000
--- a/db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiMinutesAdditionalPacksNamespaceIdForeignKeyConstraint < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_rails_e0e0c4e4b1'
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_minutes_additional_packs, :namespaces, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key :ci_minutes_additional_packs, :namespaces, column: :namespace_id, on_delete: :cascade, name: CONSTRAINT_NAME
- end
-end
diff --git a/db/post_migrate/20220106185033_remove_finding_evidence_summary.rb b/db/post_migrate/20220106185033_remove_finding_evidence_summary.rb
deleted file mode 100644
index d28e8bb81f6..00000000000
--- a/db/post_migrate/20220106185033_remove_finding_evidence_summary.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveFindingEvidenceSummary < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- remove_column :vulnerability_finding_evidences, :summary, :text
- end
-
- def down
- add_column :vulnerability_finding_evidences, :summary, :text
-
- add_text_limit :vulnerability_finding_evidences, :summary, 8_000_000
- end
-end
diff --git a/db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb b/db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb
deleted file mode 100644
index ece20f8095d..00000000000
--- a/db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveForeignKeyCiDailyBuildGroupReportResultsGroupId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_fd1858fefd'
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_daily_build_group_report_results, :namespaces, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key :ci_daily_build_group_report_results, :namespaces, column: :group_id, on_delete: :cascade, name: CONSTRAINT_NAME
- end
-end
diff --git a/db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb b/db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb
deleted file mode 100644
index 1304f19708e..00000000000
--- a/db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveForeignKeyCiPendingBuildsNamespaceId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_fdc0137e4a'
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_pending_builds, :namespaces, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key :ci_pending_builds, :namespaces, column: :namespace_id, on_delete: :cascade, name: CONSTRAINT_NAME
- end
-end
diff --git a/db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb b/db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb
deleted file mode 100644
index 61ca066401e..00000000000
--- a/db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveForeignKeyCiRunnerNamespacesNamespaceId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_rails_f9d9ed3308'
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_runner_namespaces, :namespaces, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key :ci_runner_namespaces, :namespaces, column: :namespace_id, on_delete: :cascade, name: CONSTRAINT_NAME
- end
-end
diff --git a/db/post_migrate/20220107064845_populate_vulnerability_reads.rb b/db/post_migrate/20220107064845_populate_vulnerability_reads.rb
deleted file mode 100644
index 58826c5f929..00000000000
--- a/db/post_migrate/20220107064845_populate_vulnerability_reads.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class PopulateVulnerabilityReads < Gitlab::Database::Migration[1.0]
- BATCH_SIZE = 10_000
- DELAY_INTERVAL = 2.minutes
- MIGRATION_NAME = 'PopulateVulnerabilityReads'
- SUB_BATCH_SIZE = 1_000
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('vulnerabilities'),
- MIGRATION_NAME,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true,
- other_job_arguments: [SUB_BATCH_SIZE]
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb b/db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb
deleted file mode 100644
index 06be8edd707..00000000000
--- a/db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddIdxVulnerabilityOccurrencesDedupAgain < Gitlab::Database::Migration[1.0]
- TABLE = :vulnerability_occurrences
- INDEX_NAME = 'index_vulnerability_occurrences_deduplication'
- COLUMNS = %i[project_id report_type project_fingerprint]
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index TABLE, COLUMNS, name: INDEX_NAME
- end
-
- def down
- # nothing to do here
- end
-end
diff --git a/db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb b/db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb
deleted file mode 100644
index dae93e1636d..00000000000
--- a/db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class SchedulePopulateTestReportsIssueId < Gitlab::Database::Migration[1.0]
- MIGRATION = 'PopulateTestReportsIssueId'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 30
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('requirements_management_test_reports').where(issue_id: nil),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb b/db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb
deleted file mode 100644
index d91cd3b43ef..00000000000
--- a/db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveDastScannerProfilesBuildsCiBuildIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_e4c49200f8'
-
- def up
- with_lock_retries do
- execute('LOCK ci_builds, dast_scanner_profiles_builds IN ACCESS EXCLUSIVE MODE')
- remove_foreign_key_if_exists(:dast_scanner_profiles_builds, :ci_builds, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key(:dast_scanner_profiles_builds, :ci_builds, column: :ci_build_id, on_delete: :cascade, name: CONSTRAINT_NAME)
- end
-end
diff --git a/db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb b/db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb
deleted file mode 100644
index dd8c6de4aaf..00000000000
--- a/db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveRequirementsManagementTestReportsBuildIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_rails_e67d085910'
-
- def up
- with_lock_retries do
- execute('LOCK ci_builds, requirements_management_test_reports IN ACCESS EXCLUSIVE MODE')
- remove_foreign_key_if_exists(:requirements_management_test_reports, :ci_builds, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key(:requirements_management_test_reports, :ci_builds, column: :build_id, on_delete: :nullify, name: CONSTRAINT_NAME)
- end
-end
diff --git a/db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb b/db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb
deleted file mode 100644
index 00d8a39216b..00000000000
--- a/db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveDastSiteProfilesBuildsCiBuildIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_a325505e99'
-
- def up
- with_lock_retries do
- execute('LOCK ci_builds, dast_site_profiles_builds IN ACCESS EXCLUSIVE MODE')
- remove_foreign_key_if_exists(:dast_site_profiles_builds, :ci_builds, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key(:dast_site_profiles_builds, :ci_builds, column: :ci_build_id, on_delete: :cascade, name: CONSTRAINT_NAME)
- end
-end
diff --git a/db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb b/db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb
deleted file mode 100644
index 20782664f63..00000000000
--- a/db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveSecurityScansBuildIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- CONSTRAINT_NAME = 'fk_rails_4ef1e6b4c6'
-
- def up
- with_lock_retries do
- execute('LOCK ci_builds, security_scans IN ACCESS EXCLUSIVE MODE')
- remove_foreign_key_if_exists(:security_scans, :ci_builds, name: CONSTRAINT_NAME)
- end
- end
-
- def down
- add_concurrent_foreign_key(:security_scans, :ci_builds, column: :build_id, on_delete: :cascade, name: CONSTRAINT_NAME)
- end
-end
diff --git a/db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb b/db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb
deleted file mode 100644
index 6de0f9424e8..00000000000
--- a/db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class IndexClusterAgentTokensOnStatus < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_cluster_agent_tokens_on_agent_id_status_last_used_at'
-
- def up
- add_concurrent_index :cluster_agent_tokens, 'agent_id, status, last_used_at DESC NULLS LAST', name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :cluster_agent_tokens, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220111093534_remove_index_on_auto_stop_in.rb b/db/post_migrate/20220111093534_remove_index_on_auto_stop_in.rb
deleted file mode 100644
index bcb78b28376..00000000000
--- a/db/post_migrate/20220111093534_remove_index_on_auto_stop_in.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveIndexOnAutoStopIn < Gitlab::Database::Migration[1.0]
- TABLE = :environments
- INDEX_NAME = 'index_environments_on_auto_stop_at'
- COLUMN = :auto_stop_at
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index TABLE, COLUMN, where: 'auto_stop_at IS NOT NULL', name: INDEX_NAME
- end
-
- def down
- add_concurrent_index TABLE, COLUMN, where: 'auto_stop_at IS NOT NULL', name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220111101421_remove_index_on_merge_request_id.rb b/db/post_migrate/20220111101421_remove_index_on_merge_request_id.rb
deleted file mode 100644
index 38cc259312d..00000000000
--- a/db/post_migrate/20220111101421_remove_index_on_merge_request_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveIndexOnMergeRequestId < Gitlab::Database::Migration[1.0]
- TABLE = :merge_request_context_commits
- INDEX_NAME = 'index_merge_request_context_commits_on_merge_request_id'
- COLUMN = :merge_request_id
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index TABLE, COLUMN, name: INDEX_NAME
- end
-
- def down
- add_concurrent_index TABLE, COLUMN, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb b/db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb
deleted file mode 100644
index 795ec24f3bd..00000000000
--- a/db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class TruncateCiMirrorTables < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- execute('TRUNCATE TABLE ci_namespace_mirrors')
- execute('TRUNCATE TABLE ci_project_mirrors')
- end
-
- def down
- # noop
- end
-end
diff --git a/db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb b/db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb
deleted file mode 100644
index bc17c125ba7..00000000000
--- a/db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiPendingBuildsFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_pending_builds, :projects, name: "fk_rails_480669c3b3")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_pending_builds, :projects, name: "fk_rails_480669c3b3", column: :project_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb b/db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb
deleted file mode 100644
index 79d864e2c2a..00000000000
--- a/db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiRunningBuildsFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK projects, ci_running_builds IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:ci_running_builds, :projects, name: "fk_rails_dc1d0801e8")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_running_builds, :projects, name: "fk_rails_dc1d0801e8", column: :project_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb b/db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb
deleted file mode 100644
index d786c9d846a..00000000000
--- a/db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCascadeDeleteFromProjectNamespaceForeignKey < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- TARGET_COLUMN = :project_namespace_id
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
- end
-
- add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :nullify)
- end
-
- def down
- with_lock_retries do
- remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
- end
-
- add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb b/db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb
deleted file mode 100644
index 9ad90a3a7a0..00000000000
--- a/db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiUnitTestsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_unit_tests, :projects, name: "fk_7a8fabf0a8")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_unit_tests, :projects, name: "fk_7a8fabf0a8", column: :project_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb b/db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb
deleted file mode 100644
index ad7cf2a20c9..00000000000
--- a/db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiDailyBuildGroupReportResultsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK projects, ci_daily_build_group_report_results IN ACCESS EXCLUSIVE MODE')
- remove_foreign_key_if_exists(:ci_daily_build_group_report_results, :projects, name: "fk_rails_0667f7608c")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_daily_build_group_report_results, :projects, name: "fk_rails_0667f7608c", column: :project_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb b/db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb
deleted file mode 100644
index 13cfacdc223..00000000000
--- a/db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiFreezePeriodsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_freeze_periods, :projects, name: "fk_2e02bbd1a6")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_freeze_periods, :projects, name: "fk_2e02bbd1a6", column: :project_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb b/db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb
deleted file mode 100644
index e86dd015493..00000000000
--- a/db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiResourceGroupsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_resource_groups, :projects, name: "fk_774722d144")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_resource_groups, :projects, name: "fk_774722d144", column: :project_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb b/db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb
deleted file mode 100644
index 3d2753bf9bf..00000000000
--- a/db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiBuildReportResultsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_build_report_results, :projects, name: "fk_rails_056d298d48")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_build_report_results, :projects, name: "fk_rails_056d298d48", column: :project_id, target_column: :id, on_delete: "cascade")
- end
-end
diff --git a/db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb b/db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb
deleted file mode 100644
index 966286a6730..00000000000
--- a/db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveUsersCiJobTokenProjectScopeLinksAddedByIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_job_token_project_scope_links, :users, name: "fk_rails_35f7f506ce")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_job_token_project_scope_links, :users, name: "fk_rails_35f7f506ce", column: :added_by_id, target_column: :id, on_delete: :nullify)
- end
-end
diff --git a/db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb b/db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb
deleted file mode 100644
index 2e5d4cfd22e..00000000000
--- a/db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveUsersCiPipelineSchedulesOwnerIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:ci_pipeline_schedules, :users, name: "fk_9ea99f58d2")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_pipeline_schedules, :users, name: "fk_9ea99f58d2", column: :owner_id, target_column: :id, on_delete: :nullify)
- end
-end
diff --git a/db/post_migrate/20220113111440_schedule_fix_incorrect_max_seats_used.rb b/db/post_migrate/20220113111440_schedule_fix_incorrect_max_seats_used.rb
deleted file mode 100644
index f39b026bd77..00000000000
--- a/db/post_migrate/20220113111440_schedule_fix_incorrect_max_seats_used.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleFixIncorrectMaxSeatsUsed < Gitlab::Database::Migration[1.0]
- DOWNTIME = false
- TMP_IDX_NAME = 'tmp_gitlab_subscriptions_max_seats_used_migration'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :gitlab_subscriptions, :id, where: "start_date >= '2021-08-02' AND start_date <= '2021-11-20' AND max_seats_used != 0 AND max_seats_used > seats_in_use AND max_seats_used > seats", name: TMP_IDX_NAME
-
- return unless Gitlab.com?
-
- migrate_in(1.hour, 'FixIncorrectMaxSeatsUsed')
- end
-
- def down
- remove_concurrent_index_by_name :gitlab_subscriptions, TMP_IDX_NAME
- end
-end
diff --git a/db/post_migrate/20220114105525_add_index_on_projects_path.rb b/db/post_migrate/20220114105525_add_index_on_projects_path.rb
deleted file mode 100644
index cef38f91b21..00000000000
--- a/db/post_migrate/20220114105525_add_index_on_projects_path.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexOnProjectsPath < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- TABLE = :projects
- INDEX_NAME = 'index_on_projects_path'
- COLUMN = :path
-
- def up
- add_concurrent_index TABLE, COLUMN, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index TABLE, COLUMN, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb b/db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb
deleted file mode 100644
index 1ea89609926..00000000000
--- a/db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class AddAuthorIndexToDesignManagementVersions < Gitlab::Database::Migration[1.0]
- TABLE = :design_management_versions
- INDEX_NAME = 'index_design_management_versions_on_author_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index TABLE, :author_id, where: 'author_id IS NOT NULL', name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index TABLE, :author_id, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220117034056_remove_index_cluster_agent_tokens_on_agent_id_and_last_used_at.rb b/db/post_migrate/20220117034056_remove_index_cluster_agent_tokens_on_agent_id_and_last_used_at.rb
deleted file mode 100644
index 5e306be016a..00000000000
--- a/db/post_migrate/20220117034056_remove_index_cluster_agent_tokens_on_agent_id_and_last_used_at.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveIndexClusterAgentTokensOnAgentIdAndLastUsedAt < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX = 'index_cluster_agent_tokens_on_agent_id_and_last_used_at'
-
- def up
- remove_concurrent_index_by_name :cluster_agent_tokens, name: INDEX
- end
-
- def down
- add_concurrent_index :cluster_agent_tokens, 'agent_id, last_used_at DESC NULLS LAST', name: INDEX
- end
-end
diff --git a/db/post_migrate/20220118204039_self_managed_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb b/db/post_migrate/20220118204039_self_managed_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb
deleted file mode 100644
index 18f68150e45..00000000000
--- a/db/post_migrate/20220118204039_self_managed_reschedule_recalculate_vulnerability_finding_signatures_for_findings.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class SelfManagedRescheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Database::Migration[1.0]
- MIGRATION = 'RecalculateVulnerabilityFindingSignaturesForFindings'
- BATCH_SIZE = 1_000
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
- def up
- # Only run migration for self-managed
- return if ::Gitlab.com?
-
- # Vulnerability Finding Signatures is an EE only feature
- return unless Gitlab.ee?
-
- delete_queued_jobs(MIGRATION)
-
- requeue_background_migration_jobs_by_range_at_intervals(
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220119094503_populate_audit_event_streaming_verification_token.rb b/db/post_migrate/20220119094503_populate_audit_event_streaming_verification_token.rb
deleted file mode 100644
index 482f873739a..00000000000
--- a/db/post_migrate/20220119094503_populate_audit_event_streaming_verification_token.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class PopulateAuditEventStreamingVerificationToken < Gitlab::Database::Migration[1.0]
- class ExternalAuditEventDestination < ActiveRecord::Base
- self.table_name = 'audit_events_external_audit_event_destinations'
-
- def regenerate_verification_token
- update!(verification_token: SecureRandom.base58(24))
- end
- end
-
- def up
- ExternalAuditEventDestination.all.each { |destination| destination.regenerate_verification_token }
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb b/db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb
deleted file mode 100644
index 59a003c8f8d..00000000000
--- a/db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiPipelineArtifactsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK projects, ci_pipeline_artifacts IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:ci_pipeline_artifacts, :projects, name: "fk_rails_4a70390ca6")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_pipeline_artifacts, :projects, name: "fk_rails_4a70390ca6", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220119143130_remove_projects_ci_sources_pipelines_source_project_id_fk.rb b/db/post_migrate/20220119143130_remove_projects_ci_sources_pipelines_source_project_id_fk.rb
deleted file mode 100644
index 7fe9f1c856b..00000000000
--- a/db/post_migrate/20220119143130_remove_projects_ci_sources_pipelines_source_project_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiSourcesPipelinesSourceProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK projects, ci_sources_pipelines IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:ci_sources_pipelines, :projects, name: "fk_acd9737679")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_sources_pipelines, :projects, name: "fk_acd9737679", column: :source_project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220119144458_remove_users_ci_triggers_owner_id_fk.rb b/db/post_migrate/20220119144458_remove_users_ci_triggers_owner_id_fk.rb
deleted file mode 100644
index 9acf53a6ea2..00000000000
--- a/db/post_migrate/20220119144458_remove_users_ci_triggers_owner_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveUsersCiTriggersOwnerIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK users, ci_triggers IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:ci_triggers, :users, name: "fk_e8e10d1964")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_triggers, :users, name: "fk_e8e10d1964", column: :owner_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220119151221_remove_merge_requests_ci_pipelines_merge_request_id_fk.rb b/db/post_migrate/20220119151221_remove_merge_requests_ci_pipelines_merge_request_id_fk.rb
deleted file mode 100644
index c7ced0ae3b7..00000000000
--- a/db/post_migrate/20220119151221_remove_merge_requests_ci_pipelines_merge_request_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveMergeRequestsCiPipelinesMergeRequestIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_pipelines, :merge_requests, name: "fk_a23be95014")
-
- with_lock_retries do
- execute('LOCK merge_requests, ci_pipelines IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_pipelines, :merge_requests, name: "fk_a23be95014")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_pipelines, :merge_requests, name: "fk_a23be95014", column: :merge_request_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220119153706_remove_ci_pipelines_merge_trains_pipeline_id_fk.rb b/db/post_migrate/20220119153706_remove_ci_pipelines_merge_trains_pipeline_id_fk.rb
deleted file mode 100644
index 92d68ff4fbb..00000000000
--- a/db/post_migrate/20220119153706_remove_ci_pipelines_merge_trains_pipeline_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiPipelinesMergeTrainsPipelineIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK ci_pipelines, merge_trains IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:merge_trains, :ci_pipelines, name: "fk_rails_f90820cb08")
- end
- end
-
- def down
- add_concurrent_foreign_key(:merge_trains, :ci_pipelines, name: "fk_rails_f90820cb08", column: :pipeline_id, target_column: :id, on_delete: :nullify)
- end
-end
diff --git a/db/post_migrate/20220119154442_remove_ci_pipelines_merge_requests_head_pipeline_id_fk.rb b/db/post_migrate/20220119154442_remove_ci_pipelines_merge_requests_head_pipeline_id_fk.rb
deleted file mode 100644
index 6a978ce2ab1..00000000000
--- a/db/post_migrate/20220119154442_remove_ci_pipelines_merge_requests_head_pipeline_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiPipelinesMergeRequestsHeadPipelineIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK ci_pipelines, merge_requests IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:merge_requests, :ci_pipelines, name: "fk_fd82eae0b9")
- end
- end
-
- def down
- add_concurrent_foreign_key(:merge_requests, :ci_pipelines, name: "fk_fd82eae0b9", column: :head_pipeline_id, target_column: :id, on_delete: :nullify)
- end
-end
diff --git a/db/post_migrate/20220119193130_remove_ci_pipelines_dast_profiles_pipelines_ci_pipeline_id_fk.rb b/db/post_migrate/20220119193130_remove_ci_pipelines_dast_profiles_pipelines_ci_pipeline_id_fk.rb
deleted file mode 100644
index f4eedd0fa70..00000000000
--- a/db/post_migrate/20220119193130_remove_ci_pipelines_dast_profiles_pipelines_ci_pipeline_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiPipelinesDastProfilesPipelinesCiPipelineIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK ci_pipelines, dast_profiles_pipelines IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:dast_profiles_pipelines, :ci_pipelines, name: "fk_a60cad829d")
- end
- end
-
- def down
- add_concurrent_foreign_key(:dast_profiles_pipelines, :ci_pipelines, name: "fk_a60cad829d", column: :ci_pipeline_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220119201340_remove_ci_pipelines_vulnerability_statistics_latest_pipeline_id_fk.rb b/db/post_migrate/20220119201340_remove_ci_pipelines_vulnerability_statistics_latest_pipeline_id_fk.rb
deleted file mode 100644
index bd80767cf6a..00000000000
--- a/db/post_migrate/20220119201340_remove_ci_pipelines_vulnerability_statistics_latest_pipeline_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiPipelinesVulnerabilityStatisticsLatestPipelineIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK ci_pipelines, vulnerability_statistics IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:vulnerability_statistics, :ci_pipelines, name: "fk_e8b13c928f")
- end
- end
-
- def down
- add_concurrent_foreign_key(:vulnerability_statistics, :ci_pipelines, name: "fk_e8b13c928f", column: :latest_pipeline_id, target_column: :id, on_delete: :nullify)
- end
-end
diff --git a/db/post_migrate/20220119203119_remove_ci_pipelines_vulnerability_occurrence_pipelines_pipeline_id_fk.rb b/db/post_migrate/20220119203119_remove_ci_pipelines_vulnerability_occurrence_pipelines_pipeline_id_fk.rb
deleted file mode 100644
index b6397486dd0..00000000000
--- a/db/post_migrate/20220119203119_remove_ci_pipelines_vulnerability_occurrence_pipelines_pipeline_id_fk.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiPipelinesVulnerabilityOccurrencePipelinesPipelineIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute('LOCK ci_pipelines, vulnerability_occurrence_pipelines IN ACCESS EXCLUSIVE MODE')
-
- remove_foreign_key_if_exists(:vulnerability_occurrence_pipelines, :ci_pipelines, name: "fk_rails_6421e35d7d")
- end
- end
-
- def down
- add_concurrent_foreign_key(:vulnerability_occurrence_pipelines, :ci_pipelines, name: "fk_rails_6421e35d7d", column: :pipeline_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220120094340_drop_position_from_security_findings.rb b/db/post_migrate/20220120094340_drop_position_from_security_findings.rb
deleted file mode 100644
index 56af346ad1b..00000000000
--- a/db/post_migrate/20220120094340_drop_position_from_security_findings.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-class DropPositionFromSecurityFindings < Gitlab::Database::Migration[1.0]
- enable_lock_retries!
-
- def change
- remove_column :security_findings, :position, :integer
- end
-end
diff --git a/db/post_migrate/20220120123700_add_tmp_index_routes_id_for_namespaces.rb b/db/post_migrate/20220120123700_add_tmp_index_routes_id_for_namespaces.rb
deleted file mode 100644
index 2b8cecd0e57..00000000000
--- a/db/post_migrate/20220120123700_add_tmp_index_routes_id_for_namespaces.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddTmpIndexRoutesIdForNamespaces < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'tmp_index_for_namespace_id_migration_on_routes'
-
- disable_ddl_transaction!
-
- def up
- # Temporary index to be removed in 14.9
- # https://gitlab.com/gitlab-org/gitlab/-/issues/352353
- add_concurrent_index :routes, :id, where: "routes.namespace_id is null and routes.source_type = 'Namespace'", name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :routes, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220120123800_backfill_namespace_id_for_namespace_routes.rb b/db/post_migrate/20220120123800_backfill_namespace_id_for_namespace_routes.rb
deleted file mode 100644
index 68279456ddd..00000000000
--- a/db/post_migrate/20220120123800_backfill_namespace_id_for_namespace_routes.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillNamespaceIdForNamespaceRoutes < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'BackfillNamespaceIdForNamespaceRoute'
- INTERVAL = 2.minutes
- BATCH_SIZE = 1_000
- MAX_BATCH_SIZE = 10_000
- SUB_BATCH_SIZE = 200
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :routes,
- :id,
- job_interval: INTERVAL,
- batch_size: BATCH_SIZE,
- max_batch_size: MAX_BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
- end
-
- def down
- delete_batched_background_migration(MIGRATION, :routes, :id, [])
- end
-end
diff --git a/db/post_migrate/20220120211832_backfill_member_namespace_id_for_group_members.rb b/db/post_migrate/20220120211832_backfill_member_namespace_id_for_group_members.rb
deleted file mode 100644
index 279084e0fc5..00000000000
--- a/db/post_migrate/20220120211832_backfill_member_namespace_id_for_group_members.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillMemberNamespaceIdForGroupMembers < Gitlab::Database::Migration[1.0]
- MIGRATION = 'BackfillMemberNamespaceForGroupMembers'
- INTERVAL = 2.minutes
- BATCH_SIZE = 1_000
- MAX_BATCH_SIZE = 2_000
- SUB_BATCH_SIZE = 100
-
- disable_ddl_transaction!
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :members,
- :id,
- job_interval: INTERVAL,
- batch_size: BATCH_SIZE,
- max_batch_size: MAX_BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
- end
-
- def down
- delete_batched_background_migration(MIGRATION, :members, :id, [])
- end
-end
diff --git a/db/post_migrate/20220121214752_remove_projects_ci_stages_project_id_fk.rb b/db/post_migrate/20220121214752_remove_projects_ci_stages_project_id_fk.rb
deleted file mode 100644
index 93f0b30571a..00000000000
--- a/db/post_migrate/20220121214752_remove_projects_ci_stages_project_id_fk.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiStagesProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return if Gitlab.com? # unsafe migration, skip on GitLab.com due to https://gitlab.com/groups/gitlab-org/-/epics/7249#note_819625526
- return unless foreign_key_exists?(:ci_stages, :projects, name: "fk_2360681d1d")
-
- with_lock_retries do
- execute('LOCK projects, ci_stages IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_stages, :projects, name: "fk_2360681d1d")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_stages, :projects, name: "fk_2360681d1d", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220121214753_re_remove_projects_ci_stages_project_id_fk.rb b/db/post_migrate/20220121214753_re_remove_projects_ci_stages_project_id_fk.rb
deleted file mode 100644
index 45dec15a5a7..00000000000
--- a/db/post_migrate/20220121214753_re_remove_projects_ci_stages_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class ReRemoveProjectsCiStagesProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_stages, :projects, name: "fk_2360681d1d")
-
- with_lock_retries do
- execute('LOCK projects, ci_stages IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_stages, :projects, name: "fk_2360681d1d")
- end
- end
-
- def down
- # no-op, since the FK will be added via rollback by prior-migration
- end
-end
diff --git a/db/post_migrate/20220121221651_remove_projects_ci_variables_project_id_fk.rb b/db/post_migrate/20220121221651_remove_projects_ci_variables_project_id_fk.rb
deleted file mode 100644
index f647d4376ac..00000000000
--- a/db/post_migrate/20220121221651_remove_projects_ci_variables_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiVariablesProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_variables, :projects, name: "fk_ada5eb64b3")
-
- with_lock_retries do
- execute('LOCK projects, ci_variables IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_variables, :projects, name: "fk_ada5eb64b3")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_variables, :projects, name: "fk_ada5eb64b3", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124130028_dedup_runner_projects.rb b/db/post_migrate/20220124130028_dedup_runner_projects.rb
deleted file mode 100644
index 1a4c895f1c4..00000000000
--- a/db/post_migrate/20220124130028_dedup_runner_projects.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-# frozen_string_literal: true
-
-class DedupRunnerProjects < Gitlab::Database::Migration[1.0]
- TABLE_NAME = :ci_runner_projects
- TMP_INDEX_NAME = 'tmp_unique_ci_runner_projects_by_runner_id_and_project_id'
- OLD_INDEX_NAME = 'index_ci_runner_projects_on_runner_id_and_project_id'
- INDEX_NAME = 'index_unique_ci_runner_projects_on_runner_id_and_project_id'
- BATCH_SIZE = 5000
-
- disable_ddl_transaction!
-
- module Ci
- class RunnerProject < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'ci_runner_projects'
- end
- end
-
- def up
- last_runner_project_record_id = Ci::RunnerProject.maximum(:id) || 0
-
- # This index will disallow further duplicates while we're deduplicating the data.
- add_concurrent_index(TABLE_NAME, [:runner_id, :project_id], where: "id > #{Integer(last_runner_project_record_id)}", unique: true, name: TMP_INDEX_NAME)
-
- Ci::RunnerProject.each_batch(of: BATCH_SIZE) do |relation|
- duplicated_runner_projects = Ci::RunnerProject
- .select('COUNT(*)', :runner_id, :project_id)
- .where('(runner_id, project_id) IN (?)', relation.select(:runner_id, :project_id))
- .group(:runner_id, :project_id)
- .having('COUNT(*) > 1')
-
- duplicated_runner_projects.each do |runner_project|
- deduplicate_item(runner_project)
- end
- end
-
- add_concurrent_index(TABLE_NAME, [:runner_id, :project_id], unique: true, name: INDEX_NAME)
- remove_concurrent_index_by_name(TABLE_NAME, TMP_INDEX_NAME)
- remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME)
- end
-
- def down
- add_concurrent_index(TABLE_NAME, [:runner_id, :project_id], name: OLD_INDEX_NAME)
- remove_concurrent_index_by_name(TABLE_NAME, TMP_INDEX_NAME)
- remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
- end
-
- private
-
- def deduplicate_item(runner_project)
- runner_projects_records = Ci::RunnerProject
- .where(project_id: runner_project.project_id, runner_id: runner_project.runner_id)
- .order(updated_at: :asc)
- .to_a
-
- attributes = {}
- runner_projects_records.each do |runner_projects_record|
- params = runner_projects_record.attributes.except('id')
- attributes.merge!(params.compact)
- end
-
- ApplicationRecord.transaction do
- record_to_keep = runner_projects_records.pop
- records_to_delete = runner_projects_records
-
- Ci::RunnerProject.where(id: records_to_delete.map(&:id)).delete_all
- record_to_keep.update!(attributes)
- end
- end
-end
diff --git a/db/post_migrate/20220124145019_remove_projects_external_pull_requests_project_id_fk.rb b/db/post_migrate/20220124145019_remove_projects_external_pull_requests_project_id_fk.rb
deleted file mode 100644
index b16234fc812..00000000000
--- a/db/post_migrate/20220124145019_remove_projects_external_pull_requests_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsExternalPullRequestsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:external_pull_requests, :projects, name: "fk_rails_bcae9b5c7b")
-
- with_lock_retries do
- execute('LOCK projects, external_pull_requests IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:external_pull_requests, :projects, name: "fk_rails_bcae9b5c7b")
- end
- end
-
- def down
- add_concurrent_foreign_key(:external_pull_requests, :projects, name: "fk_rails_bcae9b5c7b", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124151456_remove_projects_ci_triggers_project_id_fk.rb b/db/post_migrate/20220124151456_remove_projects_ci_triggers_project_id_fk.rb
deleted file mode 100644
index 684d363eb96..00000000000
--- a/db/post_migrate/20220124151456_remove_projects_ci_triggers_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiTriggersProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_triggers, :projects, name: "fk_e3e63f966e")
-
- with_lock_retries do
- execute('LOCK projects, ci_triggers IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_triggers, :projects, name: "fk_e3e63f966e")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_triggers, :projects, name: "fk_e3e63f966e", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124151949_remove_projects_ci_runner_projects_project_id_fk.rb b/db/post_migrate/20220124151949_remove_projects_ci_runner_projects_project_id_fk.rb
deleted file mode 100644
index de8feb96a06..00000000000
--- a/db/post_migrate/20220124151949_remove_projects_ci_runner_projects_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiRunnerProjectsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_runner_projects, :projects, name: "fk_4478a6f1e4")
-
- with_lock_retries do
- execute('LOCK projects, ci_runner_projects IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_runner_projects, :projects, name: "fk_4478a6f1e4")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_runner_projects, :projects, name: "fk_4478a6f1e4", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124152824_remove_projects_ci_subscriptions_projects_downstream_project_id_fk.rb b/db/post_migrate/20220124152824_remove_projects_ci_subscriptions_projects_downstream_project_id_fk.rb
deleted file mode 100644
index 8596b1f14ba..00000000000
--- a/db/post_migrate/20220124152824_remove_projects_ci_subscriptions_projects_downstream_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiSubscriptionsProjectsDownstreamProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_subscriptions_projects, :projects, name: "fk_rails_0818751483")
-
- with_lock_retries do
- execute('LOCK projects, ci_subscriptions_projects IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_subscriptions_projects, :projects, name: "fk_rails_0818751483")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_subscriptions_projects, :projects, name: "fk_rails_0818751483", column: :downstream_project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124153233_remove_projects_ci_job_artifacts_project_id_fk.rb b/db/post_migrate/20220124153233_remove_projects_ci_job_artifacts_project_id_fk.rb
deleted file mode 100644
index 1948a78916d..00000000000
--- a/db/post_migrate/20220124153233_remove_projects_ci_job_artifacts_project_id_fk.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiJobArtifactsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return if Gitlab.com? # unsafe migration, skip on GitLab.com due to https://gitlab.com/groups/gitlab-org/-/epics/7249#note_819625526
- return unless foreign_key_exists?(:ci_job_artifacts, :projects, name: "fk_rails_9862d392f9")
-
- with_lock_retries do
- execute('LOCK projects, ci_job_artifacts IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_job_artifacts, :projects, name: "fk_rails_9862d392f9")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_job_artifacts, :projects, name: "fk_rails_9862d392f9", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124153234_re_remove_projects_ci_job_artifacts_project_id_fk.rb b/db/post_migrate/20220124153234_re_remove_projects_ci_job_artifacts_project_id_fk.rb
deleted file mode 100644
index bb59134b927..00000000000
--- a/db/post_migrate/20220124153234_re_remove_projects_ci_job_artifacts_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class ReRemoveProjectsCiJobArtifactsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_job_artifacts, :projects, name: "fk_rails_9862d392f9")
-
- with_lock_retries do
- execute('LOCK projects, ci_job_artifacts IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_job_artifacts, :projects, name: "fk_rails_9862d392f9")
- end
- end
-
- def down
- # no-op, since the FK will be added via rollback by prior-migration
- end
-end
diff --git a/db/post_migrate/20220124180704_remove_projects_ci_builds_metadata_project_id_fk.rb b/db/post_migrate/20220124180704_remove_projects_ci_builds_metadata_project_id_fk.rb
deleted file mode 100644
index fc9dc2cc6dc..00000000000
--- a/db/post_migrate/20220124180704_remove_projects_ci_builds_metadata_project_id_fk.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiBuildsMetadataProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return if Gitlab.com? # unsafe migration, skip on GitLab.com due to https://gitlab.com/groups/gitlab-org/-/epics/7249#note_819625526
- return unless foreign_key_exists?(:ci_builds_metadata, :projects, name: "fk_rails_ffcf702a02")
-
- with_lock_retries do
- execute('LOCK projects, ci_builds_metadata IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_builds_metadata, :projects, name: "fk_rails_ffcf702a02")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_builds_metadata, :projects, name: "fk_rails_ffcf702a02", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124180705_re_remove_projects_ci_builds_metadata_project_id_fk.rb b/db/post_migrate/20220124180705_re_remove_projects_ci_builds_metadata_project_id_fk.rb
deleted file mode 100644
index 6483b8e0643..00000000000
--- a/db/post_migrate/20220124180705_re_remove_projects_ci_builds_metadata_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class ReRemoveProjectsCiBuildsMetadataProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_builds_metadata, :projects, name: "fk_rails_ffcf702a02")
-
- with_lock_retries do
- execute('LOCK projects, ci_builds_metadata IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_builds_metadata, :projects, name: "fk_rails_ffcf702a02")
- end
- end
-
- def down
- # no-op, since the FK will be added via rollback by prior-migration
- end
-end
diff --git a/db/post_migrate/20220124184338_remove_projects_ci_subscriptions_projects_upstream_project_id_fk.rb b/db/post_migrate/20220124184338_remove_projects_ci_subscriptions_projects_upstream_project_id_fk.rb
deleted file mode 100644
index 50448f4a884..00000000000
--- a/db/post_migrate/20220124184338_remove_projects_ci_subscriptions_projects_upstream_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiSubscriptionsProjectsUpstreamProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_subscriptions_projects, :projects, name: "fk_rails_7871f9a97b")
-
- with_lock_retries do
- execute('LOCK projects, ci_subscriptions_projects IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_subscriptions_projects, :projects, name: "fk_rails_7871f9a97b")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_subscriptions_projects, :projects, name: "fk_rails_7871f9a97b", column: :upstream_project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124204046_remove_projects_ci_sources_pipelines_project_id_fk.rb b/db/post_migrate/20220124204046_remove_projects_ci_sources_pipelines_project_id_fk.rb
deleted file mode 100644
index e15d337045e..00000000000
--- a/db/post_migrate/20220124204046_remove_projects_ci_sources_pipelines_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiSourcesPipelinesProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_sources_pipelines, :projects, name: "fk_1e53c97c0a")
-
- with_lock_retries do
- execute('LOCK projects, ci_sources_pipelines IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_sources_pipelines, :projects, name: "fk_1e53c97c0a")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_sources_pipelines, :projects, name: "fk_1e53c97c0a", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124214131_remove_projects_ci_refs_project_id_fk.rb b/db/post_migrate/20220124214131_remove_projects_ci_refs_project_id_fk.rb
deleted file mode 100644
index f90d477673a..00000000000
--- a/db/post_migrate/20220124214131_remove_projects_ci_refs_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiRefsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_refs, :projects, name: "fk_rails_4249db8cc3")
-
- with_lock_retries do
- execute('LOCK projects, ci_refs IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_refs, :projects, name: "fk_rails_4249db8cc3")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_refs, :projects, name: "fk_rails_4249db8cc3", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124215857_remove_projects_ci_job_token_project_scope_links_source_project_id_fk.rb b/db/post_migrate/20220124215857_remove_projects_ci_job_token_project_scope_links_source_project_id_fk.rb
deleted file mode 100644
index 8bfe9586a50..00000000000
--- a/db/post_migrate/20220124215857_remove_projects_ci_job_token_project_scope_links_source_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiJobTokenProjectScopeLinksSourceProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_job_token_project_scope_links, :projects, name: "fk_rails_4b2ee3290b")
-
- with_lock_retries do
- execute('LOCK projects, ci_job_token_project_scope_links IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_job_token_project_scope_links, :projects, name: "fk_rails_4b2ee3290b")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_job_token_project_scope_links, :projects, name: "fk_rails_4b2ee3290b", column: :source_project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220124221521_remove_projects_ci_project_monthly_usages_project_id_fk.rb b/db/post_migrate/20220124221521_remove_projects_ci_project_monthly_usages_project_id_fk.rb
deleted file mode 100644
index cff78342d21..00000000000
--- a/db/post_migrate/20220124221521_remove_projects_ci_project_monthly_usages_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiProjectMonthlyUsagesProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_project_monthly_usages, :projects, name: "fk_rails_508bcd4aa6")
-
- with_lock_retries do
- execute('LOCK projects, ci_project_monthly_usages IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_project_monthly_usages, :projects, name: "fk_rails_508bcd4aa6")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_project_monthly_usages, :projects, name: "fk_rails_508bcd4aa6", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220125083520_remove_ci_pipelines_dast_site_profiles_pipelines_ci_pipeline_id_fk.rb b/db/post_migrate/20220125083520_remove_ci_pipelines_dast_site_profiles_pipelines_ci_pipeline_id_fk.rb
deleted file mode 100644
index b111b95fccf..00000000000
--- a/db/post_migrate/20220125083520_remove_ci_pipelines_dast_site_profiles_pipelines_ci_pipeline_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiPipelinesDastSiteProfilesPipelinesCiPipelineIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:dast_site_profiles_pipelines, :ci_pipelines, name: "fk_53849b0ad5")
-
- with_lock_retries do
- execute('LOCK ci_pipelines, dast_site_profiles_pipelines IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:dast_site_profiles_pipelines, :ci_pipelines, name: "fk_53849b0ad5")
- end
- end
-
- def down
- add_concurrent_foreign_key(:dast_site_profiles_pipelines, :ci_pipelines, name: "fk_53849b0ad5", column: :ci_pipeline_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220125084348_remove_ci_pipelines_vulnerability_feedback_pipeline_id_fk.rb b/db/post_migrate/20220125084348_remove_ci_pipelines_vulnerability_feedback_pipeline_id_fk.rb
deleted file mode 100644
index 1b932d084bb..00000000000
--- a/db/post_migrate/20220125084348_remove_ci_pipelines_vulnerability_feedback_pipeline_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiPipelinesVulnerabilityFeedbackPipelineIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:vulnerability_feedback, :ci_pipelines, name: "fk_rails_20976e6fd9")
-
- with_lock_retries do
- execute('LOCK ci_pipelines, vulnerability_feedback IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:vulnerability_feedback, :ci_pipelines, name: "fk_rails_20976e6fd9")
- end
- end
-
- def down
- add_concurrent_foreign_key(:vulnerability_feedback, :ci_pipelines, name: "fk_rails_20976e6fd9", column: :pipeline_id, target_column: :id, on_delete: :nullify)
- end
-end
diff --git a/db/post_migrate/20220125122640_schedule_populate_topics_non_private_projects_count.rb b/db/post_migrate/20220125122640_schedule_populate_topics_non_private_projects_count.rb
deleted file mode 100644
index dee86a70553..00000000000
--- a/db/post_migrate/20220125122640_schedule_populate_topics_non_private_projects_count.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class SchedulePopulateTopicsNonPrivateProjectsCount < Gitlab::Database::Migration[1.0]
- MIGRATION = 'PopulateTopicsNonPrivateProjectsCount'
- BATCH_SIZE = 10_000
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('topics'),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220126201752_remove_projects_ci_job_token_project_scope_links_target_project_id_fk.rb b/db/post_migrate/20220126201752_remove_projects_ci_job_token_project_scope_links_target_project_id_fk.rb
deleted file mode 100644
index a33e02f2408..00000000000
--- a/db/post_migrate/20220126201752_remove_projects_ci_job_token_project_scope_links_target_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiJobTokenProjectScopeLinksTargetProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_job_token_project_scope_links, :projects, name: "fk_rails_6904b38465")
-
- with_lock_retries do
- execute('LOCK projects, ci_job_token_project_scope_links IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_job_token_project_scope_links, :projects, name: "fk_rails_6904b38465")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_job_token_project_scope_links, :projects, name: "fk_rails_6904b38465", column: :target_project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220126202654_remove_projects_ci_sources_projects_source_project_id_fk.rb b/db/post_migrate/20220126202654_remove_projects_ci_sources_projects_source_project_id_fk.rb
deleted file mode 100644
index a69cd43b921..00000000000
--- a/db/post_migrate/20220126202654_remove_projects_ci_sources_projects_source_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiSourcesProjectsSourceProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_sources_projects, :projects, name: "fk_rails_64b6855cbc")
-
- with_lock_retries do
- execute('LOCK projects, ci_sources_projects IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_sources_projects, :projects, name: "fk_rails_64b6855cbc")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_sources_projects, :projects, name: "fk_rails_64b6855cbc", column: :source_project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220126203421_remove_projects_ci_pipeline_schedules_project_id_fk.rb b/db/post_migrate/20220126203421_remove_projects_ci_pipeline_schedules_project_id_fk.rb
deleted file mode 100644
index 870127ab168..00000000000
--- a/db/post_migrate/20220126203421_remove_projects_ci_pipeline_schedules_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiPipelineSchedulesProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_pipeline_schedules, :projects, name: "fk_8ead60fcc4")
-
- with_lock_retries do
- execute('LOCK projects, ci_pipeline_schedules IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_pipeline_schedules, :projects, name: "fk_8ead60fcc4")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_pipeline_schedules, :projects, name: "fk_8ead60fcc4", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220126210021_remove_projects_ci_builds_project_id_fk.rb b/db/post_migrate/20220126210021_remove_projects_ci_builds_project_id_fk.rb
deleted file mode 100644
index 8caa6db7507..00000000000
--- a/db/post_migrate/20220126210021_remove_projects_ci_builds_project_id_fk.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiBuildsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return if Gitlab.com? # unsafe migration, skip on GitLab.com due to https://gitlab.com/groups/gitlab-org/-/epics/7249#note_819625526
- return unless foreign_key_exists?(:ci_builds, :projects, name: "fk_befce0568a")
-
- with_lock_retries do
- execute('LOCK projects, ci_builds IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_builds, :projects, name: "fk_befce0568a")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_builds, :projects, name: "fk_befce0568a", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220126210022_re_remove_projects_ci_builds_project_id_fk.rb b/db/post_migrate/20220126210022_re_remove_projects_ci_builds_project_id_fk.rb
deleted file mode 100644
index 2a026388bbf..00000000000
--- a/db/post_migrate/20220126210022_re_remove_projects_ci_builds_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class ReRemoveProjectsCiBuildsProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_builds, :projects, name: "fk_befce0568a")
-
- with_lock_retries do
- execute('LOCK projects, ci_builds IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_builds, :projects, name: "fk_befce0568a")
- end
- end
-
- def down
- # no-op, since the FK will be added via rollback by prior-migration
- end
-end
diff --git a/db/post_migrate/20220126210657_remove_projects_ci_pipelines_project_id_fk.rb b/db/post_migrate/20220126210657_remove_projects_ci_pipelines_project_id_fk.rb
deleted file mode 100644
index 6867cf720f3..00000000000
--- a/db/post_migrate/20220126210657_remove_projects_ci_pipelines_project_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectsCiPipelinesProjectIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_pipelines, :projects, name: "fk_86635dbd80")
-
- with_lock_retries do
- execute('LOCK projects, ci_pipelines IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_pipelines, :projects, name: "fk_86635dbd80")
- end
- end
-
- def down
- add_concurrent_foreign_key(:ci_pipelines, :projects, name: "fk_86635dbd80", column: :project_id, target_column: :id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20220127112243_add_index_to_merge_request_assignees_state.rb b/db/post_migrate/20220127112243_add_index_to_merge_request_assignees_state.rb
deleted file mode 100644
index e6bb43af760..00000000000
--- a/db/post_migrate/20220127112243_add_index_to_merge_request_assignees_state.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToMergeRequestAssigneesState < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_on_merge_request_assignees_state'
-
- def up
- add_concurrent_index :merge_request_assignees, :state, where: 'state = 2', name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :merge_request_assignees, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220127112412_add_index_to_merge_request_reviewers_state.rb b/db/post_migrate/20220127112412_add_index_to_merge_request_reviewers_state.rb
deleted file mode 100644
index 13f4e05c15b..00000000000
--- a/db/post_migrate/20220127112412_add_index_to_merge_request_reviewers_state.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToMergeRequestReviewersState < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_on_merge_request_reviewers_state'
-
- def up
- add_concurrent_index :merge_request_reviewers, :state, where: 'state = 2', name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :merge_request_reviewers, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb b/db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb
deleted file mode 100644
index a6775251d42..00000000000
--- a/db/post_migrate/20220127132200_cleanup_backfill_ci_namespace_mirrors.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupBackfillCiNamespaceMirrors < Gitlab::Database::Migration[1.0]
- def up
- # no-op
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb b/db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb
deleted file mode 100644
index c0cdb74c595..00000000000
--- a/db/post_migrate/20220127132201_cleanup_backfill_ci_project_mirrors.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupBackfillCiProjectMirrors < Gitlab::Database::Migration[1.0]
- def up
- # no-op
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220128155251_remove_dangling_running_builds.rb b/db/post_migrate/20220128155251_remove_dangling_running_builds.rb
deleted file mode 100644
index f86a21ced00..00000000000
--- a/db/post_migrate/20220128155251_remove_dangling_running_builds.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveDanglingRunningBuilds < Gitlab::Database::Migration[1.0]
- BATCH_SIZE = 100
-
- disable_ddl_transaction!
-
- def up
- each_batch_range('ci_running_builds', of: BATCH_SIZE) do |min, max|
- execute <<~SQL
- DELETE FROM ci_running_builds
- USING ci_builds
- WHERE ci_builds.id = ci_running_builds.build_id
- AND ci_builds.status = 'failed'
- AND ci_builds.type = 'Ci::Build'
- AND ci_running_builds.id BETWEEN #{min} AND #{max}
- SQL
- end
- end
-
- def down
- # no-op
- # This migration deletes data and it can not be reversed
- end
-end
diff --git a/db/post_migrate/20220128155814_fix_approval_rules_code_owners_rule_type_index.rb b/db/post_migrate/20220128155814_fix_approval_rules_code_owners_rule_type_index.rb
deleted file mode 100644
index eccfab25126..00000000000
--- a/db/post_migrate/20220128155814_fix_approval_rules_code_owners_rule_type_index.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class FixApprovalRulesCodeOwnersRuleTypeIndex < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_approval_rules_code_owners_rule_type'
- OLD_INDEX_NAME = 'index_approval_rules_code_owners_rule_type_old'
- TABLE = :approval_merge_request_rules
- COLUMN = :merge_request_id
- WHERE_CONDITION = 'rule_type = 2'
-
- disable_ddl_transaction!
-
- def up
- rename_index TABLE, INDEX_NAME, OLD_INDEX_NAME if index_exists_by_name?(TABLE, INDEX_NAME) && !index_exists_by_name?(TABLE, OLD_INDEX_NAME)
-
- add_concurrent_index TABLE, COLUMN, where: WHERE_CONDITION, name: INDEX_NAME
-
- remove_concurrent_index_by_name TABLE, OLD_INDEX_NAME
- end
-
- def down
- # No-op
- end
-end
diff --git a/db/post_migrate/20220131000000_index_job_artifacts_on_trace_type_and_expire_at.rb b/db/post_migrate/20220131000000_index_job_artifacts_on_trace_type_and_expire_at.rb
deleted file mode 100644
index f47c04dd2ef..00000000000
--- a/db/post_migrate/20220131000000_index_job_artifacts_on_trace_type_and_expire_at.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class IndexJobArtifactsOnTraceTypeAndExpireAt < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'tmp_index_ci_job_artifacts_on_id_where_trace_and_expire_at'
- TIMESTAMPS = "'2021-04-22 00:00:00', '2021-05-22 00:00:00', '2021-06-22 00:00:00', '2022-01-22 00:00:00', '2022-02-22 00:00:00', '2022-03-22 00:00:00', '2022-04-22 00:00:00'"
-
- def up
- add_concurrent_index :ci_job_artifacts, :id, where: "file_type = 3 AND expire_at IN (#{TIMESTAMPS})", name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220131000001_schedule_trace_expiry_removal.rb b/db/post_migrate/20220131000001_schedule_trace_expiry_removal.rb
deleted file mode 100644
index 8e282a9b8c2..00000000000
--- a/db/post_migrate/20220131000001_schedule_trace_expiry_removal.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleTraceExpiryRemoval < Gitlab::Database::Migration[1.0]
- MIGRATION = 'RemoveAllTraceExpirationDates'
- BATCH_SIZE = 100_000
- DELAY_INTERVAL = 4.minutes
-
- disable_ddl_transaction!
-
- # Stubbed class to connect to the CI database
- # connects_to has to be called in abstract classes.
- class MultiDbAdaptableClass < ActiveRecord::Base
- self.abstract_class = true
-
- if Gitlab::Database.has_config?(:ci)
- connects_to database: { writing: :ci, reading: :ci }
- end
- end
-
- # Stubbed class to access the ci_job_artifacts table
- class JobArtifact < MultiDbAdaptableClass
- include EachBatch
-
- self.table_name = 'ci_job_artifacts'
-
- TARGET_TIMESTAMPS = [
- Date.new(2021, 04, 22).midnight.utc,
- Date.new(2021, 05, 22).midnight.utc,
- Date.new(2021, 06, 22).midnight.utc,
- Date.new(2022, 01, 22).midnight.utc,
- Date.new(2022, 02, 22).midnight.utc,
- Date.new(2022, 03, 22).midnight.utc,
- Date.new(2022, 04, 22).midnight.utc
- ].freeze
-
- scope :in_targeted_timestamps, -> { where(expire_at: TARGET_TIMESTAMPS) }
- scope :traces, -> { where(file_type: 3) }
- end
-
- def up
- return unless Gitlab.com?
-
- queue_background_migration_jobs_by_range_at_intervals(
- JobArtifact.traces.in_targeted_timestamps,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220201034731_remove_index_clusters_kubernetes_namespaces_on_cluster_id.rb b/db/post_migrate/20220201034731_remove_index_clusters_kubernetes_namespaces_on_cluster_id.rb
deleted file mode 100644
index 0e2ef3b3324..00000000000
--- a/db/post_migrate/20220201034731_remove_index_clusters_kubernetes_namespaces_on_cluster_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveIndexClustersKubernetesNamespacesOnClusterId < Gitlab::Database::Migration[1.0]
- INDEX = 'index_clusters_kubernetes_namespaces_on_cluster_id'
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index_by_name :clusters_kubernetes_namespaces, INDEX
- end
-
- def down
- add_concurrent_index :clusters_kubernetes_namespaces, :cluster_id, name: INDEX
- end
-end
diff --git a/db/post_migrate/20220201141705_cleanup_background_migration_populate_test_reports_issue_id.rb b/db/post_migrate/20220201141705_cleanup_background_migration_populate_test_reports_issue_id.rb
deleted file mode 100644
index 252b4a01d04..00000000000
--- a/db/post_migrate/20220201141705_cleanup_background_migration_populate_test_reports_issue_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupBackgroundMigrationPopulateTestReportsIssueId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'PopulateTestReportsIssueId'
-
- def up
- finalize_background_migration(MIGRATION)
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220201173212_add_user_details_provisioning_index.rb b/db/post_migrate/20220201173212_add_user_details_provisioning_index.rb
deleted file mode 100644
index a864ec7e395..00000000000
--- a/db/post_migrate/20220201173212_add_user_details_provisioning_index.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class AddUserDetailsProvisioningIndex < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'idx_user_details_on_provisioned_by_group_id_user_id'
- OLD_INDEX_NAME = 'index_user_details_on_provisioned_by_group_id'
-
- def up
- add_concurrent_index :user_details, [:provisioned_by_group_id, :user_id], name: INDEX_NAME
- remove_concurrent_index_by_name :user_details, OLD_INDEX_NAME
- end
-
- def down
- add_concurrent_index :user_details, :provisioned_by_group_id, name: OLD_INDEX_NAME
- remove_concurrent_index_by_name :user_details, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220201193033_add_unique_index_to_vulnerability_finding_links_with_truncate.rb b/db/post_migrate/20220201193033_add_unique_index_to_vulnerability_finding_links_with_truncate.rb
deleted file mode 100644
index cc9dabdf624..00000000000
--- a/db/post_migrate/20220201193033_add_unique_index_to_vulnerability_finding_links_with_truncate.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class AddUniqueIndexToVulnerabilityFindingLinksWithTruncate < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- NAME_URL_INDEX_NAME = 'finding_link_name_url_idx'
- URL_INDEX_NAME = 'finding_link_url_idx'
-
- def up
- execute('TRUNCATE TABLE vulnerability_finding_links')
-
- add_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :name, :url], unique: true, name: NAME_URL_INDEX_NAME
- add_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :url], unique: true, where: 'name is null', name: URL_INDEX_NAME
- end
-
- def down
- remove_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :name, :url], name: NAME_URL_INDEX_NAME
- remove_concurrent_index :vulnerability_finding_links, [:vulnerability_occurrence_id, :url], name: URL_INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220202105733_delete_service_template_records.rb b/db/post_migrate/20220202105733_delete_service_template_records.rb
deleted file mode 100644
index e1697f23588..00000000000
--- a/db/post_migrate/20220202105733_delete_service_template_records.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class DeleteServiceTemplateRecords < Gitlab::Database::Migration[1.0]
- class Integration < ActiveRecord::Base
- # Disable single-table inheritance
- self.inheritance_column = :_type_disabled
- end
-
- def up
- Integration.where(template: true).delete_all
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220204053655_remove_index_epic_issues_on_epic_id.rb b/db/post_migrate/20220204053655_remove_index_epic_issues_on_epic_id.rb
deleted file mode 100644
index 7815829d36a..00000000000
--- a/db/post_migrate/20220204053655_remove_index_epic_issues_on_epic_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveIndexEpicIssuesOnEpicId < Gitlab::Database::Migration[1.0]
- INDEX = 'index_epic_issues_on_epic_id'
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index_by_name :epic_issues, name: INDEX
- end
-
- def down
- add_concurrent_index :epic_issues, :epic_id, name: INDEX
- end
-end
diff --git a/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb b/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb
deleted file mode 100644
index 49c9efc497c..00000000000
--- a/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillNamespaceStatisticsWithDependencyProxySize < Gitlab::Database::Migration[1.0]
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 500
- MIGRATION = 'PopulateNamespaceStatistics'
-
- disable_ddl_transaction!
-
- def up
- groups = exec_query <<~SQL
- SELECT dependency_proxy_manifests.group_id FROM dependency_proxy_manifests
- UNION
- SELECT dependency_proxy_blobs.group_id from dependency_proxy_blobs
- SQL
-
- groups.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |group_ids, index|
- migrate_in(index * DELAY_INTERVAL, MIGRATION, [group_ids, [:dependency_proxy_size]])
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220204110725_backfill_cycle_analytics_aggregations.rb b/db/post_migrate/20220204110725_backfill_cycle_analytics_aggregations.rb
deleted file mode 100644
index 933ad747c5c..00000000000
--- a/db/post_migrate/20220204110725_backfill_cycle_analytics_aggregations.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCycleAnalyticsAggregations < Gitlab::Database::Migration[1.0]
- BATCH_SIZE = 50
-
- def up
- model = define_batchable_model('analytics_cycle_analytics_group_value_streams')
-
- model.each_batch(of: BATCH_SIZE) do |relation|
- execute <<~SQL
- WITH records_to_be_inserted AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} (
- SELECT root_ancestor.id AS group_id
- FROM (#{relation.select(:group_id).to_sql}) as value_streams,
- LATERAL (
- WITH RECURSIVE "base_and_ancestors" AS (
- (SELECT "namespaces"."id", "namespaces"."parent_id" FROM "namespaces" WHERE "namespaces"."id" = value_streams.group_id)
- UNION
- (SELECT "namespaces"."id", "namespaces"."parent_id" FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."id" = "base_and_ancestors"."parent_id")
- )
- SELECT "namespaces"."id" FROM "base_and_ancestors" as "namespaces" WHERE parent_id IS NULL LIMIT 1
- ) as root_ancestor
- )
- INSERT INTO "analytics_cycle_analytics_aggregations"
- SELECT * FROM "records_to_be_inserted"
- ON CONFLICT DO NOTHING
- SQL
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220204194347_encrypt_integration_properties.rb b/db/post_migrate/20220204194347_encrypt_integration_properties.rb
deleted file mode 100644
index 82dd3a05e1d..00000000000
--- a/db/post_migrate/20220204194347_encrypt_integration_properties.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class EncryptIntegrationProperties < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
- MIGRATION = 'EncryptIntegrationProperties'
- BATCH_SIZE = 1_000
- INTERVAL = 2.minutes.to_i
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('integrations').all,
- MIGRATION,
- INTERVAL,
- track_jobs: true,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # this migration is not reversible
- end
-end
diff --git a/db/post_migrate/20220207080758_update_api_indexes_for_projects.rb b/db/post_migrate/20220207080758_update_api_indexes_for_projects.rb
deleted file mode 100644
index 3275912b0ab..00000000000
--- a/db/post_migrate/20220207080758_update_api_indexes_for_projects.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# frozen_string_literal: true
-
-class UpdateApiIndexesForProjects < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- ARCHIVED_INDEX_NAME = 'idx_projects_api_created_at_id_for_archived'
- OLD_ARCHIVED_INDEX_NAME = 'index_projects_api_created_at_id_for_archived'
- PUBLIC_AND_ARCHIVED_INDEX_NAME = 'idx_projects_api_created_at_id_for_archived_vis20'
- OLD_PUBLIC_AND_ARCHIVED_INDEX_NAME = 'index_projects_api_created_at_id_for_archived_vis20'
- INTERNAL_PROJECTS_INDEX_NAME = 'idx_projects_api_created_at_id_for_vis10'
- OLD_INTERNAL_PROJECTS_INDEX_NAME = 'index_projects_api_created_at_id_for_vis10'
-
- def up
- add_concurrent_index :projects, [:created_at, :id],
- where: "archived = true AND pending_delete = false AND hidden = false",
- name: ARCHIVED_INDEX_NAME
-
- add_concurrent_index :projects, [:created_at, :id],
- where: "archived = true AND visibility_level = 20 AND pending_delete = false AND hidden = false",
- name: PUBLIC_AND_ARCHIVED_INDEX_NAME
-
- add_concurrent_index :projects, [:created_at, :id],
- where: "visibility_level = 10 AND pending_delete = false AND hidden = false",
- name: INTERNAL_PROJECTS_INDEX_NAME
-
- remove_concurrent_index_by_name :projects, OLD_ARCHIVED_INDEX_NAME
- remove_concurrent_index_by_name :projects, OLD_PUBLIC_AND_ARCHIVED_INDEX_NAME
- remove_concurrent_index_by_name :projects, OLD_INTERNAL_PROJECTS_INDEX_NAME
- end
-
- def down
- add_concurrent_index :projects, [:created_at, :id],
- where: "archived = true AND pending_delete = false",
- name: OLD_ARCHIVED_INDEX_NAME
-
- add_concurrent_index :projects, [:created_at, :id],
- where: "archived = true AND visibility_level = 20 AND pending_delete = false",
- name: OLD_PUBLIC_AND_ARCHIVED_INDEX_NAME
-
- add_concurrent_index :projects, [:created_at, :id],
- where: "visibility_level = 10 AND pending_delete = false",
- name: OLD_INTERNAL_PROJECTS_INDEX_NAME
-
- remove_concurrent_index_by_name :projects, ARCHIVED_INDEX_NAME
- remove_concurrent_index_by_name :projects, PUBLIC_AND_ARCHIVED_INDEX_NAME
- remove_concurrent_index_by_name :projects, INTERNAL_PROJECTS_INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220208080921_schedule_migrate_personal_namespace_project_maintainer_to_owner.rb b/db/post_migrate/20220208080921_schedule_migrate_personal_namespace_project_maintainer_to_owner.rb
deleted file mode 100644
index 633570aeaa0..00000000000
--- a/db/post_migrate/20220208080921_schedule_migrate_personal_namespace_project_maintainer_to_owner.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleMigratePersonalNamespaceProjectMaintainerToOwner < Gitlab::Database::Migration[1.0]
- MIGRATION = 'MigratePersonalNamespaceProjectMaintainerToOwner'
- INTERVAL = 2.minutes
- BATCH_SIZE = 1_000
- SUB_BATCH_SIZE = 200
-
- disable_ddl_transaction!
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :members,
- :id,
- job_interval: INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220208115439_start_backfill_ci_queuing_tables.rb b/db/post_migrate/20220208115439_start_backfill_ci_queuing_tables.rb
deleted file mode 100644
index 82e36174290..00000000000
--- a/db/post_migrate/20220208115439_start_backfill_ci_queuing_tables.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class StartBackfillCiQueuingTables < Gitlab::Database::Migration[1.0]
- MIGRATION = 'BackfillCiQueuingTables'
- BATCH_SIZE = 500
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
- def up
- return if Gitlab.com?
-
- queue_background_migration_jobs_by_range_at_intervals(
- Gitlab::BackgroundMigration::BackfillCiQueuingTables::Ci::Build.pending,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true)
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220209111007_add_partial_index_for_batching_active_cluster_image_scanning_vulnerabilities.rb b/db/post_migrate/20220209111007_add_partial_index_for_batching_active_cluster_image_scanning_vulnerabilities.rb
deleted file mode 100644
index d38509ed8c2..00000000000
--- a/db/post_migrate/20220209111007_add_partial_index_for_batching_active_cluster_image_scanning_vulnerabilities.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class AddPartialIndexForBatchingActiveClusterImageScanningVulnerabilities < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_vulnerabilities_on_project_id_and_id_active_cis'
- INDEX_FILTER_CONDITION = 'report_type = 7 AND state = ANY(ARRAY[1, 4])'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :vulnerabilities, [:project_id, :id], where: INDEX_FILTER_CONDITION, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index :vulnerabilities, [:project_id, :id], name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220212120735_schedule_fix_incorrect_max_seats_used2.rb b/db/post_migrate/20220212120735_schedule_fix_incorrect_max_seats_used2.rb
deleted file mode 100644
index c8a6bd0a15d..00000000000
--- a/db/post_migrate/20220212120735_schedule_fix_incorrect_max_seats_used2.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleFixIncorrectMaxSeatsUsed2 < Gitlab::Database::Migration[1.0]
- MIGRATION = 'FixIncorrectMaxSeatsUsed'
- TMP_IDX_NAME = 'tmp_gitlab_subscriptions_max_seats_used_migration_2'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :gitlab_subscriptions, :id, where: "start_date < '2021-08-02' AND max_seats_used != 0 AND max_seats_used > seats_in_use AND max_seats_used > seats", name: TMP_IDX_NAME
-
- return unless Gitlab.com?
-
- migrate_in(1.hour, MIGRATION, ['batch_2_for_start_date_before_02_aug_2021'])
- end
-
- def down
- remove_concurrent_index_by_name :gitlab_subscriptions, TMP_IDX_NAME
- end
-end
diff --git a/db/post_migrate/20220213104531_create_indexes_on_integration_type_new.rb b/db/post_migrate/20220213104531_create_indexes_on_integration_type_new.rb
deleted file mode 100644
index 3a9f48dec44..00000000000
--- a/db/post_migrate/20220213104531_create_indexes_on_integration_type_new.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-# frozen_string_literal: true
-
-# Reproduce the indices on integrations.type on integrations.type_new
-class CreateIndexesOnIntegrationTypeNew < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- TABLE_NAME = :integrations
- COLUMN = :type_new
-
- def indices
- [
- {
- name: "index_integrations_on_project_and_#{COLUMN}_where_inherit_null",
- columns: [:project_id, COLUMN],
- where: 'inherit_from_id IS NULL'
- },
- {
- name: "index_integrations_on_project_id_and_#{COLUMN}_unique",
- columns: [:project_id, COLUMN],
- unique: true
- },
- {
- name: "index_integrations_on_#{COLUMN}",
- columns: [COLUMN]
- },
- {
- name: "index_integrations_on_#{COLUMN}_and_instance_partial",
- columns: [COLUMN, :instance],
- where: 'instance = true'
- },
- {
- name: "index_integrations_on_#{COLUMN}_and_template_partial",
- columns: [COLUMN, :template],
- where: 'template = true'
- },
- {
- # column names are limited to 63 characters, so this one is re-worded for clarity
- name: "index_integrations_on_#{COLUMN}_id_when_active_and_has_project",
- columns: [COLUMN, :id],
- where: '((active = true) AND (project_id IS NOT NULL))'
- },
- {
- name: "index_integrations_on_unique_group_id_and_#{COLUMN}",
- columns: [:group_id, COLUMN]
- }
- ]
- end
-
- def up
- indices.each do |index|
- add_concurrent_index TABLE_NAME, index[:columns], index.except(:columns)
- end
- end
-
- def down
- indices.each do |index|
- remove_concurrent_index_by_name TABLE_NAME, index[:name]
- end
- end
-end
diff --git a/db/post_migrate/20220215190020_rerun_convert_stringified_raw_metadata_hash_to_json.rb b/db/post_migrate/20220215190020_rerun_convert_stringified_raw_metadata_hash_to_json.rb
deleted file mode 100644
index 1f36132c578..00000000000
--- a/db/post_migrate/20220215190020_rerun_convert_stringified_raw_metadata_hash_to_json.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class RerunConvertStringifiedRawMetadataHashToJson < Gitlab::Database::Migration[1.0]
- MIGRATION_CLASS = Gitlab::BackgroundMigration::FixVulnerabilityOccurrencesWithHashesAsRawMetadata
- MODEL_CLASS = MIGRATION_CLASS::Finding
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 500
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- MODEL_CLASS.by_api_report_types,
- MIGRATION_CLASS.name.demodulize,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no-op
-
- # up fixes invalid data by updating columns in-place.
- # It is a backwards-compatible change, and reversing it in a downgrade would not be desirable.
- end
-end
diff --git a/db/post_migrate/20220216201949_remove_package_files_limit_from_application_settings.rb b/db/post_migrate/20220216201949_remove_package_files_limit_from_application_settings.rb
deleted file mode 100644
index 589b75dd918..00000000000
--- a/db/post_migrate/20220216201949_remove_package_files_limit_from_application_settings.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class RemovePackageFilesLimitFromApplicationSettings < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless column_exists?(:application_settings, :max_package_files_for_package_destruction)
-
- remove_column :application_settings, :max_package_files_for_package_destruction, :smallint
- end
-
- def down
- add_column :application_settings, :max_package_files_for_package_destruction, :smallint, default: 100, null: false
- add_check_constraint :application_settings,
- 'max_package_files_for_package_destruction > 0',
- 'app_settings_max_package_files_for_package_destruction_positive'
- end
-end
diff --git a/db/post_migrate/20220217135229_validate_not_null_constraint_on_security_findings_uuid.rb b/db/post_migrate/20220217135229_validate_not_null_constraint_on_security_findings_uuid.rb
deleted file mode 100644
index 9cc04cef757..00000000000
--- a/db/post_migrate/20220217135229_validate_not_null_constraint_on_security_findings_uuid.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class ValidateNotNullConstraintOnSecurityFindingsUuid < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- validate_not_null_constraint(:security_findings, :uuid)
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220221214928_remove_show_diff_preview_in_email_column.rb b/db/post_migrate/20220221214928_remove_show_diff_preview_in_email_column.rb
deleted file mode 100644
index 41cd3446c7a..00000000000
--- a/db/post_migrate/20220221214928_remove_show_diff_preview_in_email_column.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveShowDiffPreviewInEmailColumn < Gitlab::Database::Migration[1.0]
- enable_lock_retries!
-
- def up
- remove_column :project_settings, :show_diff_preview_in_email, :boolean
- end
-
- def down
- add_column :project_settings, :show_diff_preview_in_email, :boolean, default: true, null: false
- end
-end
diff --git a/db/post_migrate/20220222191845_remove_not_null_constraint_for_security_scan_succeeded.rb b/db/post_migrate/20220222191845_remove_not_null_constraint_for_security_scan_succeeded.rb
deleted file mode 100644
index 4d4a20b83b3..00000000000
--- a/db/post_migrate/20220222191845_remove_not_null_constraint_for_security_scan_succeeded.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveNotNullConstraintForSecurityScanSucceeded < Gitlab::Database::Migration[1.0]
- def up
- change_column_null :analytics_devops_adoption_snapshots, :security_scan_succeeded, true
- end
-
- def down
- # There may now be nulls in the table, so we cannot re-add the constraint here.
- end
-end
diff --git a/db/post_migrate/20220222192524_create_not_null_constraint_releases_tag.rb b/db/post_migrate/20220222192524_create_not_null_constraint_releases_tag.rb
deleted file mode 100644
index 2bb5ba18743..00000000000
--- a/db/post_migrate/20220222192524_create_not_null_constraint_releases_tag.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class CreateNotNullConstraintReleasesTag < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- add_not_null_constraint :releases, :tag, constraint_name: 'releases_not_null_tag', validate: false
- end
-
- def down
- remove_not_null_constraint :releases, :tag, constraint_name: 'releases_not_null_tag'
- end
-end
diff --git a/db/post_migrate/20220222192525_remove_null_releases.rb b/db/post_migrate/20220222192525_remove_null_releases.rb
deleted file mode 100644
index 4efd5393122..00000000000
--- a/db/post_migrate/20220222192525_remove_null_releases.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveNullReleases < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- class Release < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'releases'
- end
-
- def up
- Release.all.each_batch(of: 25000) do |rel|
- rel.where(tag: nil).delete_all
- end
- end
-
- def down
- # no-op
- #
- # releases with the same tag within a project have been removed
- # and therefore the duplicate release data is no longer available
- end
-end
diff --git a/db/post_migrate/20220223112304_schedule_nullify_orphan_runner_id_on_ci_builds.rb b/db/post_migrate/20220223112304_schedule_nullify_orphan_runner_id_on_ci_builds.rb
deleted file mode 100644
index 10b6ab8204d..00000000000
--- a/db/post_migrate/20220223112304_schedule_nullify_orphan_runner_id_on_ci_builds.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleNullifyOrphanRunnerIdOnCiBuilds < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'NullifyOrphanRunnerIdOnCiBuilds'
- INTERVAL = 2.minutes
- BATCH_SIZE = 50_000
- MAX_BATCH_SIZE = 150_000
- SUB_BATCH_SIZE = 500
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :ci_builds,
- :id,
- job_interval: INTERVAL,
- batch_size: BATCH_SIZE,
- max_batch_size: MAX_BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
- end
-
- def down
- delete_batched_background_migration(MIGRATION, :ci_builds, :id, [])
- end
-end
diff --git a/db/post_migrate/20220223124428_schedule_merge_topics_with_same_name.rb b/db/post_migrate/20220223124428_schedule_merge_topics_with_same_name.rb
deleted file mode 100644
index 7e79c89203a..00000000000
--- a/db/post_migrate/20220223124428_schedule_merge_topics_with_same_name.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleMergeTopicsWithSameName < Gitlab::Database::Migration[1.0]
- MIGRATION = 'MergeTopicsWithSameName'
- BATCH_SIZE = 100
-
- disable_ddl_transaction!
-
- class Topic < ActiveRecord::Base
- self.table_name = 'topics'
- end
-
- def up
- Topic.select('LOWER(name) as name').group('LOWER(name)').having('COUNT(*) > 1').order('LOWER(name)')
- .in_groups_of(BATCH_SIZE, false).each_with_index do |group, i|
- migrate_in((i + 1) * 2.minutes, MIGRATION, [group.map(&:name)])
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220224000000_async_build_trace_expire_at_index.rb b/db/post_migrate/20220224000000_async_build_trace_expire_at_index.rb
deleted file mode 100644
index b22f3e7996f..00000000000
--- a/db/post_migrate/20220224000000_async_build_trace_expire_at_index.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class AsyncBuildTraceExpireAtIndex < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'tmp_index_ci_job_artifacts_on_id_where_trace_and_expire_at'
- TIMESTAMPS = "'2021-04-22 00:00:00', '2021-05-22 00:00:00', '2021-06-22 00:00:00', '2022-01-22 00:00:00', '2022-02-22 00:00:00', '2022-03-22 00:00:00', '2022-04-22 00:00:00'"
-
- def up
- prepare_async_index :ci_job_artifacts, :id, where: "file_type = 3 AND expire_at IN (#{TIMESTAMPS})", name: INDEX_NAME
- end
-
- def down
- unprepare_async_index :ci_builds, :id, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220224204415_recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb b/db/post_migrate/20220224204415_recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb
deleted file mode 100644
index feb0f2c83ab..00000000000
--- a/db/post_migrate/20220224204415_recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-class RecreateIndexSecurityCiBuildsOnNameAndIdParserWithNewFeatures < Gitlab::Database::Migration[1.0]
- TABLE = "ci_builds"
- OLD_INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features"
- NEW_INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features_old"
- COLUMNS = %i[name id]
- CONSTRAINTS = "(name::text = ANY (ARRAY['container_scanning'::character varying::text,
- 'dast'::character varying::text,
- 'dependency_scanning'::character varying::text,
- 'license_management'::character varying::text,
- 'sast'::character varying::text,
- 'secret_detection'::character varying::text,
- 'coverage_fuzzing'::character varying::text,
- 'license_scanning'::character varying::text,
- 'apifuzzer_fuzz'::character varying::text,
- 'apifuzzer_fuzz_dnd'::character varying::text])
- ) AND type::text = 'Ci::Build'::text"
-
- enable_lock_retries!
-
- def up
- rename_index(TABLE, OLD_INDEX_NAME, NEW_INDEX_NAME)
- prepare_async_index TABLE, COLUMNS, name: OLD_INDEX_NAME, where: CONSTRAINTS
- end
-
- def down
- unprepare_async_index TABLE, COLUMNS, name: OLD_INDEX_NAME
- rename_index(TABLE, NEW_INDEX_NAME, OLD_INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20220225133705_cleanup_backfill_ci_queuing_tables.rb b/db/post_migrate/20220225133705_cleanup_backfill_ci_queuing_tables.rb
deleted file mode 100644
index 4fcf8a28727..00000000000
--- a/db/post_migrate/20220225133705_cleanup_backfill_ci_queuing_tables.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupBackfillCiQueuingTables < Gitlab::Database::Migration[1.0]
- MIGRATION = 'BackfillCiQueuingTables'
-
- disable_ddl_transaction!
-
- def up
- finalize_background_migration(MIGRATION)
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220301093434_backfill_all_project_namespaces.rb b/db/post_migrate/20220301093434_backfill_all_project_namespaces.rb
deleted file mode 100644
index 607161004cf..00000000000
--- a/db/post_migrate/20220301093434_backfill_all_project_namespaces.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillAllProjectNamespaces < Gitlab::Database::Migration[1.0]
- MIGRATION = 'ProjectNamespaces::BackfillProjectNamespaces'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 1_000
- MAX_BATCH_SIZE = 5_000
- SUB_BATCH_SIZE = 10
-
- disable_ddl_transaction!
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :projects,
- :id,
- nil,
- 'up',
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- max_batch_size: MAX_BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
- end
-
- def down
- delete_batched_background_migration(MIGRATION, :projects, :id, [nil, 'up'])
- end
-end
diff --git a/db/post_migrate/20220302114046_backfill_group_features.rb b/db/post_migrate/20220302114046_backfill_group_features.rb
deleted file mode 100644
index 5e0ff9095a3..00000000000
--- a/db/post_migrate/20220302114046_backfill_group_features.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillGroupFeatures < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'BackfillGroupFeatures'
- INTERVAL = 2.minutes
- BATCH_SIZE = 10_000
- SUB_BATCH_SIZE = 1_000
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :namespaces,
- :id,
- BATCH_SIZE,
- job_interval: INTERVAL,
- batch_size: BATCH_SIZE,
- max_batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
- end
-
- def down
- delete_batched_background_migration(MIGRATION, :namespaces, :id, [BATCH_SIZE])
- end
-end
diff --git a/db/post_migrate/20220302203410_create_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb b/db/post_migrate/20220302203410_create_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb
deleted file mode 100644
index 5be6bb00269..00000000000
--- a/db/post_migrate/20220302203410_create_index_security_ci_builds_on_name_and_id_parser_with_new_features.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class CreateIndexSecurityCiBuildsOnNameAndIdParserWithNewFeatures < Gitlab::Database::Migration[1.0]
- TABLE = "ci_builds"
- COLUMNS = %i[name id]
- INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features"
- CONSTRAINTS = "(name::text = ANY (ARRAY['container_scanning'::character varying::text,
- 'dast'::character varying::text,
- 'dependency_scanning'::character varying::text,
- 'license_management'::character varying::text,
- 'sast'::character varying::text,
- 'secret_detection'::character varying::text,
- 'coverage_fuzzing'::character varying::text,
- 'license_scanning'::character varying::text,
- 'apifuzzer_fuzz'::character varying::text,
- 'apifuzzer_fuzz_dnd'::character varying::text])
- ) AND type::text = 'Ci::Build'::text"
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS)
- end
-
- def down
- remove_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS)
- end
-end
diff --git a/db/post_migrate/20220304165107_drop_partitioned_foreign_keys.rb b/db/post_migrate/20220304165107_drop_partitioned_foreign_keys.rb
deleted file mode 100644
index 43f89b05fa4..00000000000
--- a/db/post_migrate/20220304165107_drop_partitioned_foreign_keys.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class DropPartitionedForeignKeys < Gitlab::Database::Migration[1.0]
- def up
- drop_table :partitioned_foreign_keys
- end
-
- def down
- create_table :partitioned_foreign_keys do |t|
- t.boolean :cascade_delete, null: false, default: true
- t.text :from_table, null: false, limit: 63
- t.text :from_column, null: false, limit: 63
- t.text :to_table, null: false, limit: 63
- t.text :to_column, null: false, limit: 63
-
- t.index [:to_table, :from_table, :from_column], unique: true, name: :index_partitioned_foreign_keys_unique_index
- end
- end
-end
diff --git a/db/post_migrate/20220304201847_add_unique_index_on_security_training_providers.rb b/db/post_migrate/20220304201847_add_unique_index_on_security_training_providers.rb
deleted file mode 100644
index e78b8fd48ca..00000000000
--- a/db/post_migrate/20220304201847_add_unique_index_on_security_training_providers.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddUniqueIndexOnSecurityTrainingProviders < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_security_training_providers_on_unique_name'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :security_training_providers, :name, unique: true, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :security_training_providers, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220305223212_add_security_training_providers.rb b/db/post_migrate/20220305223212_add_security_training_providers.rb
deleted file mode 100644
index fbddee0ae99..00000000000
--- a/db/post_migrate/20220305223212_add_security_training_providers.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-class AddSecurityTrainingProviders < Gitlab::Database::Migration[1.0]
- KONTRA_DATA = {
- name: 'Kontra',
- description: "Kontra Application Security provides interactive developer security education that
- enables engineers to quickly learn security best practices
- and fix issues in their code by analysing real-world software security vulnerabilities.",
- url: "https://application.security/api/webhook/gitlab/exercises/search"
- }
-
- SCW_DATA = {
- name: 'Secure Code Warrior',
- description: "Resolve vulnerabilities faster and confidently with highly relevant and bite-sized secure coding learning.",
- url: "https://integration-api.securecodewarrior.com/api/v1/trial"
- }
-
- module Security
- class TrainingProvider < ActiveRecord::Base
- self.table_name = 'security_training_providers'
- end
- end
-
- def up
- current_time = Time.current
- timestamps = { created_at: current_time, updated_at: current_time }
-
- Security::TrainingProvider.reset_column_information
-
- # upsert providers
- Security::TrainingProvider.upsert_all([KONTRA_DATA.merge(timestamps), SCW_DATA.merge(timestamps)])
- end
-
- def down
- Security::TrainingProvider.reset_column_information
-
- Security::TrainingProvider.find_by(name: KONTRA_DATA[:name])&.destroy
- Security::TrainingProvider.find_by(name: SCW_DATA[:name])&.destroy
- end
-end
diff --git a/db/post_migrate/20220307192534_create_index_for_remove_duplicate_project_tag_releases.rb b/db/post_migrate/20220307192534_create_index_for_remove_duplicate_project_tag_releases.rb
deleted file mode 100644
index 3e580c013c3..00000000000
--- a/db/post_migrate/20220307192534_create_index_for_remove_duplicate_project_tag_releases.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class CreateIndexForRemoveDuplicateProjectTagReleases < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_releases_on_id_project_id_tag'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :releases,
- %i[project_id tag id],
- name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :releases, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220307192610_remove_duplicate_project_tag_releases.rb b/db/post_migrate/20220307192610_remove_duplicate_project_tag_releases.rb
deleted file mode 100644
index d8b99380825..00000000000
--- a/db/post_migrate/20220307192610_remove_duplicate_project_tag_releases.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveDuplicateProjectTagReleases < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- class Release < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'releases'
- end
-
- def up
- Release.each_batch(of: 5000) do |relation|
- relation
- .where('exists (select 1 from releases r2 where r2.project_id = releases.project_id and r2.tag = releases.tag and r2.id > releases.id)')
- .delete_all
- end
- end
-
- def down
- # no-op
- #
- # releases with the same tag within a project have been removed
- # and therefore the duplicate release data is no longer available
- end
-end
diff --git a/db/post_migrate/20220307192645_remove_index_for_remove_duplicate_project_tag_releases.rb b/db/post_migrate/20220307192645_remove_index_for_remove_duplicate_project_tag_releases.rb
deleted file mode 100644
index 8efb24daff9..00000000000
--- a/db/post_migrate/20220307192645_remove_index_for_remove_duplicate_project_tag_releases.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveIndexForRemoveDuplicateProjectTagReleases < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_releases_on_id_project_id_tag'
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index_by_name :releases, name: INDEX_NAME
- end
-
- def down
- add_concurrent_index :releases,
- %i[project_id tag id],
- name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220307192725_create_unique_index_release_tag_project.rb b/db/post_migrate/20220307192725_create_unique_index_release_tag_project.rb
deleted file mode 100644
index 8540f19f079..00000000000
--- a/db/post_migrate/20220307192725_create_unique_index_release_tag_project.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class CreateUniqueIndexReleaseTagProject < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_releases_on_project_tag_unique'
- OLD_INDEX_NAME = 'index_releases_on_project_id_and_tag'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :releases,
- %i[project_id tag],
- unique: true,
- name: INDEX_NAME
- remove_concurrent_index_by_name :releases, name: OLD_INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :releases, name: INDEX_NAME
- add_concurrent_index :releases,
- %i[project_id tag],
- name: OLD_INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220307203459_rename_user_email_lookup_limit_setting_to_search_settings_cleanup.rb b/db/post_migrate/20220307203459_rename_user_email_lookup_limit_setting_to_search_settings_cleanup.rb
deleted file mode 100644
index 2d01374780d..00000000000
--- a/db/post_migrate/20220307203459_rename_user_email_lookup_limit_setting_to_search_settings_cleanup.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RenameUserEmailLookupLimitSettingToSearchSettingsCleanup < Gitlab::Database::Migration[1.0]
- class ApplicationSetting < ActiveRecord::Base
- self.table_name = :application_settings
- end
-
- def up
- ApplicationSetting.update_all 'search_rate_limit=user_email_lookup_limit'
- end
-
- def down
- ApplicationSetting.update_all 'user_email_lookup_limit=search_rate_limit'
- end
-end
diff --git a/db/post_migrate/20220308000205_drop_old_index_security_ci_builds_on_name_and_id_parser_features.rb b/db/post_migrate/20220308000205_drop_old_index_security_ci_builds_on_name_and_id_parser_features.rb
deleted file mode 100644
index 4b895c291d8..00000000000
--- a/db/post_migrate/20220308000205_drop_old_index_security_ci_builds_on_name_and_id_parser_features.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-class DropOldIndexSecurityCiBuildsOnNameAndIdParserFeatures < Gitlab::Database::Migration[1.0]
- TABLE = "ci_builds"
- COLUMNS = %i[name id]
- INDEX_NAME = "index_security_ci_builds_on_name_and_id_parser_features_old"
- CONSTRAINTS = "(name::text = ANY (ARRAY['container_scanning'::character varying::text,
- 'dast'::character varying::text,
- 'dependency_scanning'::character varying::text,
- 'license_management'::character varying::text,
- 'sast'::character varying::text,
- 'secret_detection'::character varying::text,
- 'coverage_fuzzing'::character varying::text,
- 'license_scanning'::character varying::text])
- ) AND type::text = 'Ci::Build'::text"
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS)
- end
-
- def down
- add_concurrent_index(TABLE, COLUMNS, name: INDEX_NAME, where: CONSTRAINTS)
- end
-end
diff --git a/db/post_migrate/20220308115219_schedule_reset_duplicate_ci_runners_token_encrypted_values_on_projects.rb b/db/post_migrate/20220308115219_schedule_reset_duplicate_ci_runners_token_encrypted_values_on_projects.rb
deleted file mode 100644
index 27e7af9a550..00000000000
--- a/db/post_migrate/20220308115219_schedule_reset_duplicate_ci_runners_token_encrypted_values_on_projects.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleResetDuplicateCiRunnersTokenEncryptedValuesOnProjects < Gitlab::Database::Migration[1.0]
- MIGRATION = 'ResetDuplicateCiRunnersTokenEncryptedValuesOnProjects'
- TOKEN_COLUMN_NAME = :runners_token_encrypted
- TEMP_INDEX_NAME = "tmp_index_projects_on_id_and_#{TOKEN_COLUMN_NAME}"
- BATCH_SIZE = 10_000
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :projects, [:id, TOKEN_COLUMN_NAME], where: "#{TOKEN_COLUMN_NAME} IS NOT NULL", unique: false, name: TEMP_INDEX_NAME
-
- queue_background_migration_jobs_by_range_at_intervals(
- Gitlab::BackgroundMigration::ResetDuplicateCiRunnersTokenEncryptedValuesOnProjects::Project.base_query,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- remove_concurrent_index_by_name(:projects, name: TEMP_INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20220308115502_schedule_reset_duplicate_ci_runners_token_values_on_projects.rb b/db/post_migrate/20220308115502_schedule_reset_duplicate_ci_runners_token_values_on_projects.rb
deleted file mode 100644
index f076b0a740e..00000000000
--- a/db/post_migrate/20220308115502_schedule_reset_duplicate_ci_runners_token_values_on_projects.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleResetDuplicateCiRunnersTokenValuesOnProjects < Gitlab::Database::Migration[1.0]
- MIGRATION = 'ResetDuplicateCiRunnersTokenValuesOnProjects'
- TOKEN_COLUMN_NAME = :runners_token
- TEMP_INDEX_NAME = "tmp_index_projects_on_id_and_#{TOKEN_COLUMN_NAME}"
- BATCH_SIZE = 10_000
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :projects, [:id, TOKEN_COLUMN_NAME], where: "#{TOKEN_COLUMN_NAME} IS NOT NULL", unique: false, name: TEMP_INDEX_NAME
-
- queue_background_migration_jobs_by_range_at_intervals(
- Gitlab::BackgroundMigration::ResetDuplicateCiRunnersTokenValuesOnProjects::Project.base_query,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- remove_concurrent_index_by_name(:projects, name: TEMP_INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20220309084838_remove_external_pull_request_tracking.rb b/db/post_migrate/20220309084838_remove_external_pull_request_tracking.rb
deleted file mode 100644
index 6159f9d6822..00000000000
--- a/db/post_migrate/20220309084838_remove_external_pull_request_tracking.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveExternalPullRequestTracking < Gitlab::Database::Migration[1.0]
- include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
-
- enable_lock_retries!
-
- def up
- untrack_record_deletions(:external_pull_requests)
- end
-
- def down
- track_record_deletions(:external_pull_requests)
- end
-end
diff --git a/db/post_migrate/20220309084954_remove_leftover_external_pull_request_deletions.rb b/db/post_migrate/20220309084954_remove_leftover_external_pull_request_deletions.rb
deleted file mode 100644
index ea9fd6b28c2..00000000000
--- a/db/post_migrate/20220309084954_remove_leftover_external_pull_request_deletions.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveLeftoverExternalPullRequestDeletions < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- # Delete all pending record deletions in the public.external_pull_requests until
- # there are no more rows left.
- loop do
- result = execute <<~SQL
- DELETE FROM "loose_foreign_keys_deleted_records"
- WHERE
- ("loose_foreign_keys_deleted_records"."partition", "loose_foreign_keys_deleted_records"."id") IN (
- SELECT "loose_foreign_keys_deleted_records"."partition", "loose_foreign_keys_deleted_records"."id"
- FROM "loose_foreign_keys_deleted_records"
- WHERE
- "loose_foreign_keys_deleted_records"."fully_qualified_table_name" = 'public.external_pull_requests' AND
- "loose_foreign_keys_deleted_records"."status" = 1
- LIMIT 100
- )
- SQL
-
- break if result.cmd_tuples == 0
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220309154855_add_index_on_issues_closed_incidents.rb b/db/post_migrate/20220309154855_add_index_on_issues_closed_incidents.rb
deleted file mode 100644
index e9a2c1c85f2..00000000000
--- a/db/post_migrate/20220309154855_add_index_on_issues_closed_incidents.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexOnIssuesClosedIncidents < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_on_issues_closed_incidents_by_project_id_and_closed_at'
-
- def up
- add_concurrent_index :issues, [:project_id, :closed_at], where: "issue_type = 1 AND state_id = 2", name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :issues, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220310095341_add_async_index_ci_job_artifacts_project_id_created_at.rb b/db/post_migrate/20220310095341_add_async_index_ci_job_artifacts_project_id_created_at.rb
deleted file mode 100644
index 919e834a783..00000000000
--- a/db/post_migrate/20220310095341_add_async_index_ci_job_artifacts_project_id_created_at.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-# See https://docs.gitlab.com/ee/development/migration_style_guide.html
-# for more information on how to write migrations for GitLab.
-
-class AddAsyncIndexCiJobArtifactsProjectIdCreatedAt < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_ci_job_artifacts_on_id_project_id_and_created_at'
-
- def up
- prepare_async_index :ci_job_artifacts, [:project_id, :created_at, :id], name: INDEX_NAME
- end
-
- def down
- unprepare_async_index_by_name :ci_job_artifacts, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220310134207_add_index_project_id_and_released_at_and_id_on_releases.rb b/db/post_migrate/20220310134207_add_index_project_id_and_released_at_and_id_on_releases.rb
deleted file mode 100644
index da928f3ec8f..00000000000
--- a/db/post_migrate/20220310134207_add_index_project_id_and_released_at_and_id_on_releases.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexProjectIdAndReleasedAtAndIdOnReleases < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_releases_on_project_id_and_released_at_and_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :releases, [:project_id, :released_at, :id],
- name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :releases, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220310141349_remove_dependency_list_usage_data_from_redis.rb b/db/post_migrate/20220310141349_remove_dependency_list_usage_data_from_redis.rb
deleted file mode 100644
index 3c1e6714529..00000000000
--- a/db/post_migrate/20220310141349_remove_dependency_list_usage_data_from_redis.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveDependencyListUsageDataFromRedis < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- Gitlab::Redis::SharedState.with { |r| r.del("DEPENDENCY_LIST_USAGE_COUNTER") }
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220311010352_create_scan_id_and_id_index_on_security_findings.rb b/db/post_migrate/20220311010352_create_scan_id_and_id_index_on_security_findings.rb
deleted file mode 100644
index 1b72c4b0a78..00000000000
--- a/db/post_migrate/20220311010352_create_scan_id_and_id_index_on_security_findings.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class CreateScanIdAndIdIndexOnSecurityFindings < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_security_findings_on_scan_id_and_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :security_findings, [:scan_id, :id], name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :security_findings, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220314162342_add_index_ci_job_artifacts_project_id_created_at.rb b/db/post_migrate/20220314162342_add_index_ci_job_artifacts_project_id_created_at.rb
deleted file mode 100644
index 7241fd54cb3..00000000000
--- a/db/post_migrate/20220314162342_add_index_ci_job_artifacts_project_id_created_at.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexCiJobArtifactsProjectIdCreatedAt < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_ci_job_artifacts_on_id_project_id_and_created_at'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :ci_job_artifacts, [:project_id, :created_at, :id], name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220315171027_add_tmp_index_to_support_leaky_regex_cleanup.rb b/db/post_migrate/20220315171027_add_tmp_index_to_support_leaky_regex_cleanup.rb
deleted file mode 100644
index 6f4bd29337e..00000000000
--- a/db/post_migrate/20220315171027_add_tmp_index_to_support_leaky_regex_cleanup.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class AddTmpIndexToSupportLeakyRegexCleanup < Gitlab::Database::Migration[1.0]
- INDEX_NAME = "tmp_index_merge_requests_draft_and_status_leaky_regex"
- LEAKY_REGEXP_STR = "^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP"
- CORRECTED_REGEXP_STR = "^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)"
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :merge_requests, :id,
- where: "draft = true AND state_id = 1 AND ((title)::text ~* '#{LEAKY_REGEXP_STR}'::text) AND ((title)::text !~* '#{CORRECTED_REGEXP_STR}'::text)",
- name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :merge_requests, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220315171129_cleanup_draft_data_from_faulty_regex.rb b/db/post_migrate/20220315171129_cleanup_draft_data_from_faulty_regex.rb
deleted file mode 100644
index be81bf85f62..00000000000
--- a/db/post_migrate/20220315171129_cleanup_draft_data_from_faulty_regex.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupDraftDataFromFaultyRegex < Gitlab::Database::Migration[1.0]
- MIGRATION = 'CleanupDraftDataFromFaultyRegex'
- DELAY_INTERVAL = 5.minutes
- BATCH_SIZE = 20
-
- disable_ddl_transaction!
-
- class MergeRequest < ActiveRecord::Base
- LEAKY_REGEXP_STR = "^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP"
- CORRECTED_REGEXP_STR = "^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)"
-
- self.table_name = 'merge_requests'
-
- include ::EachBatch
-
- def self.eligible
- where(state_id: 1)
- .where(draft: true)
- .where("title ~* ?", LEAKY_REGEXP_STR)
- .where("title !~* ?", CORRECTED_REGEXP_STR)
- end
- end
-
- def up
- return unless Gitlab.com?
-
- queue_background_migration_jobs_by_range_at_intervals(
- MergeRequest.eligible,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # noop
- #
- end
-end
diff --git a/db/post_migrate/20220315181130_add_temporary_issue_type_index_for_work_item_types.rb b/db/post_migrate/20220315181130_add_temporary_issue_type_index_for_work_item_types.rb
deleted file mode 100644
index 52c525d81fb..00000000000
--- a/db/post_migrate/20220315181130_add_temporary_issue_type_index_for_work_item_types.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddTemporaryIssueTypeIndexForWorkItemTypes < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'tmp_index_issues_on_issue_type_and_id'
-
- def up
- add_concurrent_index :issues, [:issue_type, :id], name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :issues, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb b/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb
deleted file mode 100644
index 2249413b1e4..00000000000
--- a/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillWorkItemTypeIdOnIssues < Gitlab::Database::Migration[1.0]
- def up
- # no-op
- # This migration will be rescheduled as described in
- # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85212
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220315211043_add_index_to_vulnerability_reads.rb b/db/post_migrate/20220315211043_add_index_to_vulnerability_reads.rb
deleted file mode 100644
index 9fe78fb0a4e..00000000000
--- a/db/post_migrate/20220315211043_add_index_to_vulnerability_reads.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToVulnerabilityReads < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_vulnerability_reads_common_finder_query'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index(
- :vulnerability_reads,
- %i[project_id state report_type severity vulnerability_id],
- name: INDEX_NAME,
- order: { vulnerability_id: :desc }
- )
- end
-
- def down
- remove_concurrent_index_by_name(
- :vulnerability_reads,
- INDEX_NAME
- )
- end
-end
diff --git a/db/post_migrate/20220316102900_add_index_to_deploy_tokens_on_creator_id.rb b/db/post_migrate/20220316102900_add_index_to_deploy_tokens_on_creator_id.rb
deleted file mode 100644
index 7cc942c813b..00000000000
--- a/db/post_migrate/20220316102900_add_index_to_deploy_tokens_on_creator_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToDeployTokensOnCreatorId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_deploy_tokens_on_creator_id'
-
- def up
- add_concurrent_index :deploy_tokens, :creator_id, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index :deploy_tokens, :creator_id, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220316102902_add_user_foreign_key_to_deploy_tokens.rb b/db/post_migrate/20220316102902_add_user_foreign_key_to_deploy_tokens.rb
deleted file mode 100644
index 57379e4c752..00000000000
--- a/db/post_migrate/20220316102902_add_user_foreign_key_to_deploy_tokens.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddUserForeignKeyToDeployTokens < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- add_concurrent_foreign_key :deploy_tokens, :users, column: :creator_id, on_delete: :nullify, reverse_lock_order: true
- end
-
- def down
- with_lock_retries do
- remove_foreign_key :deploy_tokens, column: :creator_id
- end
- end
-end
diff --git a/db/post_migrate/20220316112118_update_organizations_name_index_add_id.rb b/db/post_migrate/20220316112118_update_organizations_name_index_add_id.rb
deleted file mode 100644
index 4d78e78e9db..00000000000
--- a/db/post_migrate/20220316112118_update_organizations_name_index_add_id.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class UpdateOrganizationsNameIndexAddId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- OLD_INDEX = 'index_customer_relations_organizations_on_unique_name_per_group'
- NEW_INDEX = 'index_organizations_on_unique_name_per_group'
-
- def up
- add_concurrent_index :customer_relations_organizations, 'group_id, lower(name), id', name: NEW_INDEX, unique: true
-
- remove_concurrent_index_by_name :customer_relations_organizations, OLD_INDEX
- end
-
- def down
- add_concurrent_index :customer_relations_organizations, 'group_id, lower(name)', name: OLD_INDEX, unique: true
-
- remove_concurrent_index_by_name :customer_relations_organizations, NEW_INDEX
- end
-end
diff --git a/db/post_migrate/20220316112206_add_contacts_index_on_group_email_and_id.rb b/db/post_migrate/20220316112206_add_contacts_index_on_group_email_and_id.rb
deleted file mode 100644
index 21434a80314..00000000000
--- a/db/post_migrate/20220316112206_add_contacts_index_on_group_email_and_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddContactsIndexOnGroupEmailAndId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_customer_relations_contacts_on_unique_email_per_group'
-
- def up
- add_concurrent_index :customer_relations_contacts, 'group_id, lower(email), id', name: INDEX_NAME, unique: true
- end
-
- def down
- remove_concurrent_index_by_name :customer_relations_contacts, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220316165539_add_index_to_vulnerabilities.rb b/db/post_migrate/20220316165539_add_index_to_vulnerabilities.rb
deleted file mode 100644
index 1128ccd7b16..00000000000
--- a/db/post_migrate/20220316165539_add_index_to_vulnerabilities.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToVulnerabilities < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_vulnerabilites_common_finder_query'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index(
- :vulnerabilities,
- %i[project_id state report_type severity id],
- name: INDEX_NAME
- )
- end
-
- def down
- remove_concurrent_index_by_name(
- :vulnerabilities,
- INDEX_NAME
- )
- end
-end
diff --git a/db/post_migrate/20220316202640_populate_container_repositories_migration_plan.rb b/db/post_migrate/20220316202640_populate_container_repositories_migration_plan.rb
deleted file mode 100644
index 7eef227ec3c..00000000000
--- a/db/post_migrate/20220316202640_populate_container_repositories_migration_plan.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class PopulateContainerRepositoriesMigrationPlan < Gitlab::Database::Migration[1.0]
- MIGRATION = 'PopulateContainerRepositoryMigrationPlan'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 1500
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('container_repositories'),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220317161914_remove_ci_runners_ci_builds_runner_id_fk.rb b/db/post_migrate/20220317161914_remove_ci_runners_ci_builds_runner_id_fk.rb
deleted file mode 100644
index 3c7c4e73199..00000000000
--- a/db/post_migrate/20220317161914_remove_ci_runners_ci_builds_runner_id_fk.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveCiRunnersCiBuildsRunnerIdFk < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- return unless foreign_key_exists?(:ci_builds, :ci_runners, name: "fk_e4ef9c2f27")
-
- with_lock_retries do
- execute('LOCK ci_runners, ci_builds IN ACCESS EXCLUSIVE MODE') if transaction_open?
-
- remove_foreign_key_if_exists(:ci_builds, :ci_runners, name: "fk_e4ef9c2f27")
- end
- end
-
- def down
- add_concurrent_foreign_key :ci_builds, :ci_runners, name: "fk_e4ef9c2f27", column: :runner_id, target_column: :id, on_delete: :nullify, validate: false
- end
-end
diff --git a/db/post_migrate/20220318111040_add_indexes_for_primary_email_second_cleanup_migration.rb b/db/post_migrate/20220318111040_add_indexes_for_primary_email_second_cleanup_migration.rb
deleted file mode 100644
index 5dcb99b36b6..00000000000
--- a/db/post_migrate/20220318111040_add_indexes_for_primary_email_second_cleanup_migration.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexesForPrimaryEmailSecondCleanupMigration < Gitlab::Database::Migration[1.0]
- USERS_INDEX = :index_users_on_id_for_primary_email_migration
- EMAIL_INDEX = :index_emails_on_email_user_id
-
- disable_ddl_transaction!
-
- def up
- unless index_exists_by_name?(:users, USERS_INDEX)
-
- disable_statement_timeout do
- execute <<~SQL
- CREATE INDEX CONCURRENTLY #{USERS_INDEX}
- ON users (id) INCLUDE (email, confirmed_at)
- WHERE confirmed_at IS NOT NULL
- SQL
- end
- end
-
- add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX
- end
-
- def down
- remove_concurrent_index_by_name :users, USERS_INDEX
- remove_concurrent_index_by_name :emails, EMAIL_INDEX
- end
-end
diff --git a/db/post_migrate/20220318111729_cleanup_after_fixing_issue_when_admin_changed_primary_email.rb b/db/post_migrate/20220318111729_cleanup_after_fixing_issue_when_admin_changed_primary_email.rb
deleted file mode 100644
index 3d29d78573a..00000000000
--- a/db/post_migrate/20220318111729_cleanup_after_fixing_issue_when_admin_changed_primary_email.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupAfterFixingIssueWhenAdminChangedPrimaryEmail < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- BATCH_SIZE = 10_000
-
- # Stubbed class to access the User table
- class User < ActiveRecord::Base
- include ::EachBatch
-
- self.table_name = 'users'
- self.inheritance_column = :_type_disabled
-
- scope :confirmed, -> { where.not(confirmed_at: nil) }
-
- has_many :emails
- end
-
- # Stubbed class to access the Emails table
- class Email < ActiveRecord::Base
- self.table_name = 'emails'
- self.inheritance_column = :_type_disabled
-
- belongs_to :user
- end
-
- def up
- # Select confirmed users that do not have their primary email in the emails table,
- # and create the email record.
- not_exists_condition = 'NOT EXISTS (SELECT 1 FROM emails WHERE emails.email = users.email AND emails.user_id = users.id)'
-
- User.confirmed.each_batch(of: BATCH_SIZE) do |user_batch|
- user_batch.select(:id, :email, :confirmed_at).where(not_exists_condition).each do |user|
- current_time = Time.now.utc
-
- begin
- Email.create(
- user_id: user.id,
- email: user.email,
- confirmed_at: user.confirmed_at,
- created_at: current_time,
- updated_at: current_time
- )
- rescue StandardError => error
- Gitlab::AppLogger.error("Could not add primary email #{user.email} to emails for user with ID #{user.id} due to #{error}")
- end
- end
- end
- end
-
- def down
- # Intentionally left blank
- end
-end
diff --git a/db/post_migrate/20220318111949_drop_temporary_indexes_for_primary_email_migration_second_cleanup.rb b/db/post_migrate/20220318111949_drop_temporary_indexes_for_primary_email_migration_second_cleanup.rb
deleted file mode 100644
index 755751aaa1a..00000000000
--- a/db/post_migrate/20220318111949_drop_temporary_indexes_for_primary_email_migration_second_cleanup.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class DropTemporaryIndexesForPrimaryEmailMigrationSecondCleanup < Gitlab::Database::Migration[1.0]
- USERS_INDEX = :index_users_on_id_for_primary_email_migration
- EMAIL_INDEX = :index_emails_on_email_user_id
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index_by_name :users, USERS_INDEX
- remove_concurrent_index_by_name :emails, EMAIL_INDEX
- end
-
- def down
- unless index_exists_by_name?(:users, USERS_INDEX)
-
- disable_statement_timeout do
- execute <<~SQL
- CREATE INDEX CONCURRENTLY #{USERS_INDEX}
- ON users (id) INCLUDE (email, confirmed_at)
- WHERE confirmed_at IS NOT NULL
- SQL
- end
- end
-
- add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX
- end
-end
diff --git a/db/post_migrate/20220321025720_alter_constraint_remote_import_url.rb b/db/post_migrate/20220321025720_alter_constraint_remote_import_url.rb
deleted file mode 100644
index 90cb54cdd44..00000000000
--- a/db/post_migrate/20220321025720_alter_constraint_remote_import_url.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class AlterConstraintRemoteImportUrl < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- remove_text_limit :import_export_uploads, :remote_import_url
- add_text_limit :import_export_uploads, :remote_import_url, 2048
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220321201912_remove_user_email_lookup_limit.rb b/db/post_migrate/20220321201912_remove_user_email_lookup_limit.rb
deleted file mode 100644
index a95534b586e..00000000000
--- a/db/post_migrate/20220321201912_remove_user_email_lookup_limit.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveUserEmailLookupLimit < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- remove_column :application_settings, :user_email_lookup_limit
- end
-
- def down
- add_column :application_settings, :user_email_lookup_limit, :integer, null: false, default: 60
- end
-end
diff --git a/db/post_migrate/20220322023800_add_tmp_index_routes_id_for_project_namespaces.rb b/db/post_migrate/20220322023800_add_tmp_index_routes_id_for_project_namespaces.rb
deleted file mode 100644
index bc775514b75..00000000000
--- a/db/post_migrate/20220322023800_add_tmp_index_routes_id_for_project_namespaces.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddTmpIndexRoutesIdForProjectNamespaces < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'tmp_index_for_project_namespace_id_migration_on_routes'
-
- disable_ddl_transaction!
-
- def up
- # Temporary index to be removed in 15.0
- # https://gitlab.com/gitlab-org/gitlab/-/issues/352353
- add_concurrent_index :routes, :id, where: "namespace_id IS NULL AND source_type = 'Project'", name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :routes, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220322035654_add_migration_plan_index_to_container_repositories.rb b/db/post_migrate/20220322035654_add_migration_plan_index_to_container_repositories.rb
deleted file mode 100644
index 78e331a8b63..00000000000
--- a/db/post_migrate/20220322035654_add_migration_plan_index_to_container_repositories.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddMigrationPlanIndexToContainerRepositories < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'idx_container_repos_on_migration_state_migration_plan_created'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :container_repositories,
- [:migration_state, :migration_plan, :created_at],
- name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :container_repositories, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220322071127_finalize_project_namespaces_backfill.rb b/db/post_migrate/20220322071127_finalize_project_namespaces_backfill.rb
deleted file mode 100644
index 21b8dc78f7d..00000000000
--- a/db/post_migrate/20220322071127_finalize_project_namespaces_backfill.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-# This migration acts as a gate-keeper for other migrations related to project namespace back-filling
-# so that other migrations that depend on project namespace back-filling cannot be run unless project namespace
-# back-filling has finalized successfully.
-class FinalizeProjectNamespacesBackfill < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'ProjectNamespaces::BackfillProjectNamespaces'
-
- def up
- ensure_batched_background_migration_is_finished(
- job_class_name: MIGRATION,
- table_name: :projects,
- column_name: :id,
- job_arguments: [nil, 'up']
- )
- end
-
- def down
- # noop
- end
-end
diff --git a/db/post_migrate/20220322094410_remove_wiki_notes.rb b/db/post_migrate/20220322094410_remove_wiki_notes.rb
deleted file mode 100644
index c3705e1e20f..00000000000
--- a/db/post_migrate/20220322094410_remove_wiki_notes.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveWikiNotes < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- class Note < ApplicationRecord
- self.table_name = 'notes'
- self.inheritance_column = :_type_disabled
- end
-
- def up
- return unless Gitlab.dev_or_test_env? || Gitlab.staging? || Gitlab.com?
-
- Note.where(noteable_type: 'Wiki', id: [97, 98, 110, 242, 272]).delete_all
- end
-
- def down
- # NO-OP
- end
-end
diff --git a/db/post_migrate/20220322132242_update_pages_onboarding_state.rb b/db/post_migrate/20220322132242_update_pages_onboarding_state.rb
deleted file mode 100644
index 896ab78a266..00000000000
--- a/db/post_migrate/20220322132242_update_pages_onboarding_state.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-class UpdatePagesOnboardingState < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
- BATCH_SIZE = 75
-
- def up
- define_batchable_model(
- :project_pages_metadata
- ).where(
- deployed: true
- ).each_batch(
- of: BATCH_SIZE,
- column: :project_id
- ) do |batch|
- batch.update_all(onboarding_complete: true)
- end
- end
-
- def down
- define_batchable_model(
- :project_pages_metadata
- ).where(
- onboarding_complete: true
- ).each_batch(
- of: BATCH_SIZE,
- column: :project_id
- ) do |batch|
- batch.update_all(onboarding_complete: false)
- end
- end
-end
diff --git a/db/post_migrate/20220322205008_change_search_rate_limit_values.rb b/db/post_migrate/20220322205008_change_search_rate_limit_values.rb
deleted file mode 100644
index ed4aad72ddf..00000000000
--- a/db/post_migrate/20220322205008_change_search_rate_limit_values.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class ChangeSearchRateLimitValues < Gitlab::Database::Migration[1.0]
- def up
- # Change search_rate_limits to a more reasonable value
- # as long as they are still using the default values.
- #
- # The reason why `search_rate_limit` could be either 30 or 60
- # is because its value was ported over from the now deprecated
- # `user_email_lookup_limit` which had a default value of 60.
- execute("update application_settings set search_rate_limit=300 where search_rate_limit IN (30,60)")
- execute("update application_settings set search_rate_limit_unauthenticated=100 where search_rate_limit_unauthenticated = 10")
- end
-
- def down
- # noop. Because this migration is updating values, it is not reversible.
- end
-end
diff --git a/db/post_migrate/20220323023800_backfill_namespace_id_for_project_routes.rb b/db/post_migrate/20220323023800_backfill_namespace_id_for_project_routes.rb
deleted file mode 100644
index 0b2c7318887..00000000000
--- a/db/post_migrate/20220323023800_backfill_namespace_id_for_project_routes.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillNamespaceIdForProjectRoutes < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'BackfillNamespaceIdForProjectRoute'
- INTERVAL = 2.minutes
- BATCH_SIZE = 1_000
- MAX_BATCH_SIZE = 10_000
- SUB_BATCH_SIZE = 200
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :routes,
- :id,
- job_interval: INTERVAL,
- batch_size: BATCH_SIZE,
- max_batch_size: MAX_BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
- end
-
- def down
- delete_batched_background_migration(MIGRATION, :routes, :id, [])
- end
-end
diff --git a/db/post_migrate/20220323130000_add_temp_index_on_null_project_namespace_ids.rb b/db/post_migrate/20220323130000_add_temp_index_on_null_project_namespace_ids.rb
deleted file mode 100644
index e73993065b0..00000000000
--- a/db/post_migrate/20220323130000_add_temp_index_on_null_project_namespace_ids.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class AddTempIndexOnNullProjectNamespaceIds < Gitlab::Database::Migration[1.0]
- TMP_INDEX_FOR_NULL_PROJECT_NAMESPACE_ID = 'tmp_index_for_null_project_namespace_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :projects, :id, name: TMP_INDEX_FOR_NULL_PROJECT_NAMESPACE_ID, where: 'project_namespace_id IS NULL'
- end
-
- def down
- remove_concurrent_index_by_name :projects, name: TMP_INDEX_FOR_NULL_PROJECT_NAMESPACE_ID
- end
-end
diff --git a/db/post_migrate/20220323152202_add_index_on_visible_deployments.rb b/db/post_migrate/20220323152202_add_index_on_visible_deployments.rb
deleted file mode 100644
index 57ec2f7013d..00000000000
--- a/db/post_migrate/20220323152202_add_index_on_visible_deployments.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexOnVisibleDeployments < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_deployments_for_visible_scope'
-
- def up
- add_concurrent_index :deployments,
- [:environment_id, :finished_at],
- order: { finished_at: :desc },
- where: 'status IN (1, 2, 3, 4, 6)',
- name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :deployments, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220324032250_migrate_shimo_confluence_service_category.rb b/db/post_migrate/20220324032250_migrate_shimo_confluence_service_category.rb
deleted file mode 100644
index d341cc50874..00000000000
--- a/db/post_migrate/20220324032250_migrate_shimo_confluence_service_category.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-class MigrateShimoConfluenceServiceCategory < Gitlab::Database::Migration[1.0]
- MIGRATION = 'MigrateShimoConfluenceIntegrationCategory'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 10_000
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('integrations').where(type_new: %w[Integrations::Confluence Integrations::Shimo]),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true)
- end
-
- def down
- end
-end
diff --git a/db/post_migrate/20220324081709_fix_and_backfill_project_namespaces_for_projects_with_duplicate_name.rb b/db/post_migrate/20220324081709_fix_and_backfill_project_namespaces_for_projects_with_duplicate_name.rb
deleted file mode 100644
index f5927a2cc16..00000000000
--- a/db/post_migrate/20220324081709_fix_and_backfill_project_namespaces_for_projects_with_duplicate_name.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class FixAndBackfillProjectNamespacesForProjectsWithDuplicateName < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION = 'FixDuplicateProjectNameAndPath'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 1000
-
- class Project < ActiveRecord::Base
- include ::EachBatch
-
- self.table_name = 'projects'
-
- scope :without_project_namespace, -> { where(project_namespace_id: nil) }
- end
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- Project.without_project_namespace, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE, track_jobs: true
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220324110247_untrack_deletions_on_ci_job_artifacts.rb b/db/post_migrate/20220324110247_untrack_deletions_on_ci_job_artifacts.rb
deleted file mode 100644
index d178c235e21..00000000000
--- a/db/post_migrate/20220324110247_untrack_deletions_on_ci_job_artifacts.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class UntrackDeletionsOnCiJobArtifacts < Gitlab::Database::Migration[1.0]
- include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
-
- enable_lock_retries!
-
- def up
- untrack_record_deletions(:ci_job_artifacts)
- end
-
- def down
- track_record_deletions(:ci_job_artifacts)
- end
-end
diff --git a/db/post_migrate/20220324180717_remove_project_pages_metadata_artifacts_archive_id_column.rb b/db/post_migrate/20220324180717_remove_project_pages_metadata_artifacts_archive_id_column.rb
deleted file mode 100644
index 287752b6b5c..00000000000
--- a/db/post_migrate/20220324180717_remove_project_pages_metadata_artifacts_archive_id_column.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProjectPagesMetadataArtifactsArchiveIdColumn < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- remove_column :project_pages_metadata, :artifacts_archive_id
- end
-
- def down
- unless column_exists?(:project_pages_metadata, :artifacts_archive_id)
- add_column :project_pages_metadata, :artifacts_archive_id, :bigint
- end
-
- add_concurrent_index(
- :project_pages_metadata,
- :artifacts_archive_id,
- name: "index_project_pages_metadata_on_artifacts_archive_id"
- )
- end
-end
diff --git a/db/post_migrate/20220325000000_prepare_index_for_ci_job_artifacts_unlocked_with_expire_at.rb b/db/post_migrate/20220325000000_prepare_index_for_ci_job_artifacts_unlocked_with_expire_at.rb
deleted file mode 100644
index fa43f3b7f59..00000000000
--- a/db/post_migrate/20220325000000_prepare_index_for_ci_job_artifacts_unlocked_with_expire_at.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class PrepareIndexForCiJobArtifactsUnlockedWithExpireAt < Gitlab::Database::Migration[1.0]
- TABLE_NAME = 'ci_job_artifacts'
- INDEX_NAME = 'index_ci_job_artifacts_on_expire_at_for_removal'
- CONDITIONS = 'locked = 0 AND expire_at IS NOT NULL'
-
- def up
- prepare_async_index TABLE_NAME, [:expire_at], where: CONDITIONS, name: INDEX_NAME
- end
-
- def down
- unprepare_async_index_by_name TABLE_NAME, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220325000001_finalize_index_for_ci_job_artifacts_unlocked_with_expire_at.rb b/db/post_migrate/20220325000001_finalize_index_for_ci_job_artifacts_unlocked_with_expire_at.rb
deleted file mode 100644
index d0fe7ceb34f..00000000000
--- a/db/post_migrate/20220325000001_finalize_index_for_ci_job_artifacts_unlocked_with_expire_at.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class FinalizeIndexForCiJobArtifactsUnlockedWithExpireAt < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- TABLE_NAME = 'ci_job_artifacts'
- INDEX_NAME = 'index_ci_job_artifacts_on_expire_at_for_removal'
- CONDITIONS = 'locked = 0 AND expire_at IS NOT NULL'
-
- def up
- add_concurrent_index TABLE_NAME, [:expire_at], where: CONDITIONS, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220325050642_drop_integrations_template_column.rb b/db/post_migrate/20220325050642_drop_integrations_template_column.rb
deleted file mode 100644
index e110c307a38..00000000000
--- a/db/post_migrate/20220325050642_drop_integrations_template_column.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-class DropIntegrationsTemplateColumn < Gitlab::Database::Migration[1.0]
- enable_lock_retries!
-
- def change
- remove_column :integrations, :template, :boolean, default: false
- end
-end
diff --git a/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb b/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb
deleted file mode 100644
index 4c4c29e2b7c..00000000000
--- a/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class StealBackgroundJobForFixingConflictingProjectNamesAndPaths < Gitlab::Database::Migration[1.0]
- def up
- Gitlab::BackgroundMigration.steal('FixDuplicateProjectNameAndPath')
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb b/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb
deleted file mode 100644
index d1cefa76cec..00000000000
--- a/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class CreateUniqueIndexOnProjectsNameAndNamespaceId < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'unique_projects_on_name_namespace_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :projects, [:name, :namespace_id], unique: true, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :projects, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220326161803_add_cascade_delete_fk_on_project_namespace_id.rb b/db/post_migrate/20220326161803_add_cascade_delete_fk_on_project_namespace_id.rb
deleted file mode 100644
index 005532c53d9..00000000000
--- a/db/post_migrate/20220326161803_add_cascade_delete_fk_on_project_namespace_id.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-class AddCascadeDeleteFkOnProjectNamespaceId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- TARGET_COLUMN = :project_namespace_id
-
- def up
- # add the new FK before removing the old one
- add_concurrent_foreign_key(
- :projects,
- :namespaces,
- column: TARGET_COLUMN,
- name: fk_name("#{TARGET_COLUMN}_new"),
- on_delete: :cascade
- )
-
- with_lock_retries do
- remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN, name: fk_name(TARGET_COLUMN))
- end
- end
-
- def down
- add_concurrent_foreign_key(
- :projects,
- :namespaces,
- column: TARGET_COLUMN,
- name: fk_name(TARGET_COLUMN),
- on_delete: :nullify
- )
-
- with_lock_retries do
- remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN, name: fk_name("#{TARGET_COLUMN}_new"))
- end
- end
-
- def fk_name(column_name)
- # generate a FK name
- concurrent_foreign_key_name(:projects, column_name)
- end
-end
diff --git a/db/post_migrate/20220326163653_add_not_null_contraint_to_project_namespace_id.rb b/db/post_migrate/20220326163653_add_not_null_contraint_to_project_namespace_id.rb
deleted file mode 100644
index 2273b84d003..00000000000
--- a/db/post_migrate/20220326163653_add_not_null_contraint_to_project_namespace_id.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class AddNotNullContraintToProjectNamespaceId < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- add_not_null_constraint :projects, :project_namespace_id, validate: false
- end
-
- def down
- remove_not_null_constraint :projects, :project_namespace_id
- end
-end
diff --git a/db/post_migrate/20220329175119_remove_leftover_ci_job_artifact_deletions.rb b/db/post_migrate/20220329175119_remove_leftover_ci_job_artifact_deletions.rb
deleted file mode 100644
index f0c09598bfb..00000000000
--- a/db/post_migrate/20220329175119_remove_leftover_ci_job_artifact_deletions.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveLeftoverCiJobArtifactDeletions < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- # Delete all pending record deletions in the public.ci_job_artifacts until
- # there are no more rows left.
- loop do
- result = execute <<~SQL
- DELETE FROM "loose_foreign_keys_deleted_records"
- WHERE
- ("loose_foreign_keys_deleted_records"."partition", "loose_foreign_keys_deleted_records"."id") IN (
- SELECT "loose_foreign_keys_deleted_records"."partition", "loose_foreign_keys_deleted_records"."id"
- FROM "loose_foreign_keys_deleted_records"
- WHERE
- "loose_foreign_keys_deleted_records"."fully_qualified_table_name" = 'public.ci_job_artifacts' AND
- "loose_foreign_keys_deleted_records"."status" = 1
- LIMIT 100
- )
- SQL
-
- break if result.cmd_tuples == 0
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220331074722_add_notes_null_discussion_id_temp_index_async.rb b/db/post_migrate/20220331074722_add_notes_null_discussion_id_temp_index_async.rb
deleted file mode 100644
index 9f52308935b..00000000000
--- a/db/post_migrate/20220331074722_add_notes_null_discussion_id_temp_index_async.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class AddNotesNullDiscussionIdTempIndexAsync < Gitlab::Database::Migration[1.0]
- # Temporary index to be removed in 15.0 https://gitlab.com/gitlab-org/gitlab/-/issues/357581
- INDEX_NAME = 'tmp_index_notes_on_id_where_discussion_id_is_null'
-
- def up
- prepare_async_index :notes, :id, where: 'discussion_id IS NULL', name: INDEX_NAME
- end
-
- def down
- unprepare_async_index_by_name :notes, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220401045621_remove_state_index_on_merge_request_assignees.rb b/db/post_migrate/20220401045621_remove_state_index_on_merge_request_assignees.rb
deleted file mode 100644
index ff62a1c646d..00000000000
--- a/db/post_migrate/20220401045621_remove_state_index_on_merge_request_assignees.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveStateIndexOnMergeRequestAssignees < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_on_merge_request_assignees_state'
-
- def up
- remove_concurrent_index_by_name :merge_request_assignees, INDEX_NAME
- end
-
- def down
- add_concurrent_index :merge_request_assignees, :state, where: 'state = 2', name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220401045642_remove_state_index_on_merge_request_reviewers.rb b/db/post_migrate/20220401045642_remove_state_index_on_merge_request_reviewers.rb
deleted file mode 100644
index ef59d9fcc25..00000000000
--- a/db/post_migrate/20220401045642_remove_state_index_on_merge_request_reviewers.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveStateIndexOnMergeRequestReviewers < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_on_merge_request_reviewers_state'
-
- def up
- remove_concurrent_index_by_name :merge_request_reviewers, INDEX_NAME
- end
-
- def down
- add_concurrent_index :merge_request_reviewers, :state, where: 'state = 2', name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220404183350_add_forbidden_state_index_to_users.rb b/db/post_migrate/20220404183350_add_forbidden_state_index_to_users.rb
deleted file mode 100644
index 7ae61a60b73..00000000000
--- a/db/post_migrate/20220404183350_add_forbidden_state_index_to_users.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddForbiddenStateIndexToUsers < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'users_forbidden_state_idx'
-
- def up
- add_concurrent_index :users, :id,
- name: INDEX_NAME,
- where: "confirmed_at IS NOT NULL AND (state <> ALL (ARRAY['blocked', 'banned', 'ldap_blocked']))"
- end
-
- def down
- remove_concurrent_index_by_name :users, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220404184814_drop_broader_expired_artifact_index.rb b/db/post_migrate/20220404184814_drop_broader_expired_artifact_index.rb
deleted file mode 100644
index b6327b89c11..00000000000
--- a/db/post_migrate/20220404184814_drop_broader_expired_artifact_index.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class DropBroaderExpiredArtifactIndex < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- TABLE_NAME = 'ci_job_artifacts'
- INDEX_NAME = 'ci_job_artifacts_expire_at_unlocked_idx'
-
- def up
- remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
- end
-
- def down
- add_concurrent_index TABLE_NAME, [:expire_at], where: 'locked = 0', name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb b/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb
deleted file mode 100644
index 9b74cef144f..00000000000
--- a/db/post_migrate/20220404194649_replace_work_item_type_backfill_next_batch_strategy.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class ReplaceWorkItemTypeBackfillNextBatchStrategy < Gitlab::Database::Migration[1.0]
- def up
- # no-op
- # migrations will be rescheduled with the correct batching class
- # no need for this migration
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220409160628_add_async_index_for_events_followed_users.rb b/db/post_migrate/20220409160628_add_async_index_for_events_followed_users.rb
deleted file mode 100644
index fb858248b19..00000000000
--- a/db/post_migrate/20220409160628_add_async_index_for_events_followed_users.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class AddAsyncIndexForEventsFollowedUsers < Gitlab::Database::Migration[1.0]
- INDEX_NAME = 'index_events_for_followed_users'
-
- def up
- prepare_async_index :events, %I[author_id target_type action id], name: INDEX_NAME
- end
-
- def down
- unprepare_async_index :events, %I[author_id target_type action id], name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb b/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb
deleted file mode 100644
index fb43e13364d..00000000000
--- a/db/post_migrate/20220412044906_finalize_traversal_ids_background_migrations.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class FinalizeTraversalIdsBackgroundMigrations < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- def up
- finalize_background_migration('BackfillNamespaceTraversalIdsRoots')
- finalize_background_migration('BackfillNamespaceTraversalIdsChildren')
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20220412143551_add_partial_index_on_unencrypted_integrations.rb b/db/post_migrate/20220412143551_add_partial_index_on_unencrypted_integrations.rb
deleted file mode 100644
index 0f5415d6bf5..00000000000
--- a/db/post_migrate/20220412143551_add_partial_index_on_unencrypted_integrations.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-#
-class AddPartialIndexOnUnencryptedIntegrations < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_integrations_on_id_where_not_encrypted'
- INDEX_FILTER_CONDITION = 'properties IS NOT NULL AND encrypted_properties IS NULL'
-
- def up
- add_concurrent_index :integrations, [:id],
- where: INDEX_FILTER_CONDITION,
- name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :integrations, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb b/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb
deleted file mode 100644
index 2213268fa73..00000000000
--- a/db/post_migrate/20220412143552_consume_remaining_encrypt_integration_property_jobs.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class ConsumeRemainingEncryptIntegrationPropertyJobs < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- BATCH_SIZE = 50
-
- def up
- Gitlab::BackgroundMigration.steal('EncryptIntegrationProperties')
-
- model = define_batchable_model('integrations')
- relation = model.where.not(properties: nil).where(encrypted_properties: nil)
-
- relation.each_batch(of: BATCH_SIZE) do |batch|
- range = batch.pick('MIN(id)', 'MAX(id)')
-
- Gitlab::BackgroundMigration::EncryptIntegrationProperties.new.perform(*range)
- end
- end
-
- def down
- end
-end
diff --git a/db/post_migrate/20220413011328_remove_partial_index_on_unencrypted_integrations.rb b/db/post_migrate/20220413011328_remove_partial_index_on_unencrypted_integrations.rb
deleted file mode 100644
index 873080144ab..00000000000
--- a/db/post_migrate/20220413011328_remove_partial_index_on_unencrypted_integrations.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-#
-# The inverse of 20220412143551_add_partial_index_on_unencrypted_integrations.rb
-class RemovePartialIndexOnUnencryptedIntegrations < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_integrations_on_id_where_not_encrypted'
- INDEX_FILTER_CONDITION = 'properties IS NOT NULL AND encrypted_properties IS NULL'
-
- def down
- add_concurrent_index :integrations, [:id],
- where: INDEX_FILTER_CONDITION,
- name: INDEX_NAME
- end
-
- def up
- remove_concurrent_index_by_name :integrations, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20221027203951_drop_experiment_users_table.rb b/db/post_migrate/20221027203951_drop_experiment_users_table.rb
index 95455db98e5..838a9605740 100644
--- a/db/post_migrate/20221027203951_drop_experiment_users_table.rb
+++ b/db/post_migrate/20221027203951_drop_experiment_users_table.rb
@@ -6,7 +6,7 @@ class DropExperimentUsersTable < Gitlab::Database::Migration[2.0]
end
def down
- create_table :experiment_users do |t| # rubocop:disable Migration/SchemaAdditionMethodsNoPost
+ create_table :experiment_users do |t|
t.bigint :experiment_id, null: false
t.bigint :user_id, null: false
t.integer :group_type, limit: 2, null: false, default: 0
diff --git a/db/post_migrate/20221114142602_drop_experiment_subjects_table.rb b/db/post_migrate/20221114142602_drop_experiment_subjects_table.rb
index 371f214de6d..f7c10192afb 100644
--- a/db/post_migrate/20221114142602_drop_experiment_subjects_table.rb
+++ b/db/post_migrate/20221114142602_drop_experiment_subjects_table.rb
@@ -7,7 +7,7 @@ class DropExperimentSubjectsTable < Gitlab::Database::Migration[2.0]
def down
unless table_exists?(:experiment_subjects)
- create_table :experiment_subjects do |t| # rubocop:disable Migration/SchemaAdditionMethodsNoPost
+ create_table :experiment_subjects do |t|
t.bigint :experiment_id, null: false
t.bigint :user_id
t.bigint :project_id
diff --git a/db/post_migrate/20221114142616_drop_experiments_table.rb b/db/post_migrate/20221114142616_drop_experiments_table.rb
index da6c1122494..a8280eb9f69 100644
--- a/db/post_migrate/20221114142616_drop_experiments_table.rb
+++ b/db/post_migrate/20221114142616_drop_experiments_table.rb
@@ -9,7 +9,7 @@ class DropExperimentsTable < Gitlab::Database::Migration[2.0]
def down
unless table_exists?(:experiments)
- create_table :experiments do |t| # rubocop:disable Migration/SchemaAdditionMethodsNoPost
+ create_table :experiments do |t|
t.text :name, null: false
t.index :name, unique: true
diff --git a/db/post_migrate/20221115184525_remove_namespaces_tmp_project_id_column.rb b/db/post_migrate/20221115184525_remove_namespaces_tmp_project_id_column.rb
index 01424f8113f..d044c44e95e 100644
--- a/db/post_migrate/20221115184525_remove_namespaces_tmp_project_id_column.rb
+++ b/db/post_migrate/20221115184525_remove_namespaces_tmp_project_id_column.rb
@@ -14,9 +14,9 @@ class RemoveNamespacesTmpProjectIdColumn < Gitlab::Database::Migration[2.0]
def down
unless column_exists?(:namespaces, :tmp_project_id)
with_lock_retries do
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ # rubocop:disable Migration/AddColumnsToWideTables
add_column :namespaces, :tmp_project_id, :integer
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ # rubocop:enable Migration/AddColumnsToWideTables
end
end
diff --git a/db/post_migrate/20221207135755_finalize_add_namespaces_emails_enabled_column_data.rb b/db/post_migrate/20221207135755_finalize_add_namespaces_emails_enabled_column_data.rb
new file mode 100644
index 00000000000..c4fc2aad60b
--- /dev/null
+++ b/db/post_migrate/20221207135755_finalize_add_namespaces_emails_enabled_column_data.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class FinalizeAddNamespacesEmailsEnabledColumnData < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'AddNamespacesEmailsEnabledColumnData'
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :namespaces,
+ column_name: :id,
+ job_arguments: []
+ )
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20221207135831_finalize_add_projects_emails_enabled_column_data.rb b/db/post_migrate/20221207135831_finalize_add_projects_emails_enabled_column_data.rb
new file mode 100644
index 00000000000..6118be6d4c4
--- /dev/null
+++ b/db/post_migrate/20221207135831_finalize_add_projects_emails_enabled_column_data.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class FinalizeAddProjectsEmailsEnabledColumnData < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'AddProjectsEmailsEnabledColumnData'
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :projects,
+ column_name: :id,
+ job_arguments: []
+ )
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20230104103748_remove_new_amount_used_column.rb b/db/post_migrate/20230104103748_remove_new_amount_used_column.rb
index 0aaa7c1bd8f..b93879c2b50 100644
--- a/db/post_migrate/20230104103748_remove_new_amount_used_column.rb
+++ b/db/post_migrate/20230104103748_remove_new_amount_used_column.rb
@@ -10,10 +10,10 @@ class RemoveNewAmountUsedColumn < Gitlab::Database::Migration[2.1]
def down
return if column_exists?(:ci_project_monthly_usages, :new_amount_used)
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ # rubocop:disable Migration/AddColumnsToWideTables
add_column :ci_project_monthly_usages, :new_amount_used, :decimal, default: 0.0,
precision: 18, scale: 2, null: false
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ # rubocop:enable Migration/AddColumnsToWideTables
install_rename_triggers :ci_project_monthly_usages, :amount_used, :new_amount_used, trigger_name: TRIGGER_NAME
end
diff --git a/db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb b/db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb
index cebda3e353e..11e212a697d 100644
--- a/db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb
+++ b/db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb
@@ -12,10 +12,10 @@ class RemoveNewAmountUsedColumnOnCiNamespaceMonthlyUsages < Gitlab::Database::Mi
def down
return if column_exists?(:ci_namespace_monthly_usages, :new_amount_used)
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ # rubocop:disable Migration/AddColumnsToWideTables
add_column :ci_namespace_monthly_usages, :new_amount_used, :decimal, default: 0.0,
precision: 18, scale: 2, null: false
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ # rubocop:enable Migration/AddColumnsToWideTables
install_rename_triggers :ci_namespace_monthly_usages, :amount_used, :new_amount_used, trigger_name: TRIGGER_NAME
end
diff --git a/db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb b/db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb
index 7f90b3293d8..76c93be0f42 100644
--- a/db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb
+++ b/db/post_migrate/20230201082038_drop_web_hook_calls_high_column.rb
@@ -14,9 +14,7 @@ class DropWebHookCallsHighColumn < Gitlab::Database::Migration[2.1]
def down
with_lock_retries do
unless column_exists?(:plan_limits, :web_hook_calls_high)
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
add_column :plan_limits, :web_hook_calls_high, :integer, default: 0
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
end
end
diff --git a/db/post_migrate/20230202211434_migrate_redis_slot_keys.rb b/db/post_migrate/20230202211434_migrate_redis_slot_keys.rb
index e1d3787cbb3..126555ae391 100644
--- a/db/post_migrate/20230202211434_migrate_redis_slot_keys.rb
+++ b/db/post_migrate/20230202211434_migrate_redis_slot_keys.rb
@@ -4,110 +4,10 @@ class MigrateRedisSlotKeys < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
def up
- BackupHLLRedisCounter.known_events.each do |event|
- if event[:aggregation].to_sym == :daily
- migrate_daily_aggregated(event)
- else
- migrate_weekly_aggregated(event)
- end
- end
+ # deleted as contained a bug
end
def down
# no-op
end
-
- private
-
- def migrate_daily_aggregated(event)
- days_back = BackupHLLRedisCounter::DEFAULT_DAILY_KEY_EXPIRY_LENGTH
- start_date = Date.today - days_back - 1.day
- end_date = Date.today + 1.day
-
- (start_date..end_date).each do |date|
- rename_key(event, date)
- end
- end
-
- def migrate_weekly_aggregated(event)
- weeks_back = BackupHLLRedisCounter::DEFAULT_WEEKLY_KEY_EXPIRY_LENGTH
- start_date = (Date.today - weeks_back).beginning_of_week - 1.day
- end_date = Date.today.end_of_week + 1.day
-
- (start_date..end_date).each { |date| rename_key(event, date) }
- end
-
- def rename_key(event, date)
- old_key = old_redis_key(event, date)
- new_key = BackupHLLRedisCounter.redis_key(event, date)
-
- # cannot simply rename due to different slots
- Gitlab::Redis::SharedState.with do |r|
- break unless r.exists?(old_key)
-
- Gitlab::Redis::HLL.add(
- key: new_key,
- value: r.pfcount(old_key),
- expiry: r.ttl(old_key)
- )
- end
- end
-
- def old_redis_key(event, time)
- name_with_slot = if event[:redis_slot].present?
- event[:name].to_s.gsub(event[:redis_slot], "{#{event[:redis_slot]}}")
- else
- "{#{event[:name]}}"
- end
-
- BackupHLLRedisCounter.apply_time_aggregation(name_with_slot, time, event)
- end
-
- # :nocov: Existing backed up class # rubocop:disable Gitlab/NoCodeCoverageComment
- module BackupHLLRedisCounter
- DEFAULT_WEEKLY_KEY_EXPIRY_LENGTH = 6.weeks
- DEFAULT_DAILY_KEY_EXPIRY_LENGTH = 29.days
- REDIS_SLOT = 'hll_counters'
-
- KNOWN_EVENTS_PATH = File.expand_path('known_events/*.yml', __dir__)
- ALLOWED_AGGREGATIONS = %i[daily weekly].freeze
-
- class << self
- def known_events
- @known_events ||= load_events(KNOWN_EVENTS_PATH)
- end
-
- def load_events(wildcard)
- Dir[wildcard].each_with_object([]) do |path, events|
- events.push(*load_yaml_from_path(path))
- end
- end
-
- def load_yaml_from_path(path)
- YAML.safe_load(File.read(path))&.map(&:with_indifferent_access)
- end
-
- def known_events_names
- known_events.map { |event| event[:name] } # rubocop:disable Rails/Pluck
- end
-
- def redis_key(event, time, context = '')
- key = "{#{REDIS_SLOT}}_#{event[:name]}"
- key = apply_time_aggregation(key, time, event)
- key = "#{context}_#{key}" if context.present?
- key
- end
-
- def apply_time_aggregation(key, time, event)
- if event[:aggregation].to_sym == :daily
- year_day = time.strftime('%G-%j')
- "#{year_day}-#{key}"
- else
- year_week = time.strftime('%G-%V')
- "#{key}-#{year_week}"
- end
- end
- end
- end
- # :nocov: # rubocop:disable Gitlab/NoCodeCoverageComment
end
diff --git a/db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb b/db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb
index 11468a5844e..6a2aecbda98 100644
--- a/db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb
+++ b/db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb
@@ -1,83 +1,7 @@
# frozen_string_literal: true
class SwapMergeRequestUserMentionsNoteIdToBigint < Gitlab::Database::Migration[2.1]
- include Gitlab::Database::MigrationHelpers::ConvertToBigint
-
- disable_ddl_transaction!
-
- TABLE_NAME = 'merge_request_user_mentions'
-
- def up
- return unless should_run?
-
- swap
- end
-
- def down
- return unless should_run?
-
- swap
-
- add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
- name: 'index_merge_request_user_mentions_note_id_convert_to_bigint',
- where: 'note_id_convert_to_bigint IS NOT NULL'
-
- add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
- name: 'fk_merge_request_user_mentions_note_id_convert_to_bigint',
- on_delete: :cascade,
- validate: false
- end
-
- def swap
- # This will replace the existing index_merge_request_user_mentions_on_note_id
- add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
- name: 'index_merge_request_user_mentions_note_id_convert_to_bigint',
- where: 'note_id_convert_to_bigint IS NOT NULL'
-
- # This will replace the existing merge_request_user_mentions_on_mr_id_and_note_id_index
- add_concurrent_index TABLE_NAME, [:merge_request_id, :note_id_convert_to_bigint], unique: true,
- name: 'mr_user_mentions_on_mr_id_and_note_id_convert_to_bigint_index'
-
- # This will replace the existing merge_request_user_mentions_on_mr_id_index
- add_concurrent_index TABLE_NAME, :merge_request_id, unique: true,
- name: 'merge_request_user_mentions_on_mr_id_index_convert_to_bigint',
- where: 'note_id_convert_to_bigint IS NULL'
-
- # This will replace the existing fk_rails_c440b9ea31
- add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
- name: 'fk_merge_request_user_mentions_note_id_convert_to_bigint',
- on_delete: :cascade
-
- with_lock_retries(raise_on_exhaustion: true) do
- execute "LOCK TABLE notes, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
-
- execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id TO note_id_tmp"
- execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_convert_to_bigint TO note_id"
- execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_tmp TO note_id_convert_to_bigint"
-
- function_name = Gitlab::Database::UnidirectionalCopyTrigger
- .on_table(TABLE_NAME, connection: connection)
- .name(:note_id, :note_id_convert_to_bigint)
- execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
-
- execute 'DROP INDEX IF EXISTS index_merge_request_user_mentions_on_note_id'
- rename_index TABLE_NAME, 'index_merge_request_user_mentions_note_id_convert_to_bigint',
- 'index_merge_request_user_mentions_on_note_id'
-
- execute 'DROP INDEX IF EXISTS merge_request_user_mentions_on_mr_id_and_note_id_index'
- rename_index TABLE_NAME, 'mr_user_mentions_on_mr_id_and_note_id_convert_to_bigint_index',
- 'merge_request_user_mentions_on_mr_id_and_note_id_index'
-
- execute 'DROP INDEX IF EXISTS merge_request_user_mentions_on_mr_id_index'
- rename_index TABLE_NAME, 'merge_request_user_mentions_on_mr_id_index_convert_to_bigint',
- 'merge_request_user_mentions_on_mr_id_index'
-
- execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_c440b9ea31"
- rename_constraint(TABLE_NAME, 'fk_merge_request_user_mentions_note_id_convert_to_bigint', 'fk_rails_c440b9ea31')
- end
- end
-
- def should_run?
- com_or_dev_or_test_but_not_jh?
- end
+ # No-op, moved to db/post_migrate/20230310020356_swap_merge_request_user_mentions_note_id_to_bigint_2.rb
+ def up; end
+ def down; end
end
diff --git a/db/post_migrate/20230310020356_swap_merge_request_user_mentions_note_id_to_bigint_2.rb b/db/post_migrate/20230310020356_swap_merge_request_user_mentions_note_id_to_bigint_2.rb
new file mode 100644
index 00000000000..c680b129493
--- /dev/null
+++ b/db/post_migrate/20230310020356_swap_merge_request_user_mentions_note_id_to_bigint_2.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+class SwapMergeRequestUserMentionsNoteIdToBigint2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'merge_request_user_mentions'
+
+ def up
+ return unless should_run?
+ return if columns_already_swapped?
+
+ swap
+ end
+
+ def down
+ return unless should_run?
+ return unless columns_already_swapped?
+
+ swap
+
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
+ name: 'index_merge_request_user_mentions_note_id_convert_to_bigint',
+ where: 'note_id_convert_to_bigint IS NOT NULL'
+
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
+ name: 'fk_merge_request_user_mentions_note_id_convert_to_bigint',
+ on_delete: :cascade,
+ validate: false
+ end
+
+ def swap
+ # This will replace the existing index_merge_request_user_mentions_on_note_id
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
+ name: 'index_merge_request_user_mentions_note_id_convert_to_bigint',
+ where: 'note_id_convert_to_bigint IS NOT NULL'
+
+ # This will replace the existing merge_request_user_mentions_on_mr_id_and_note_id_index
+ add_concurrent_index TABLE_NAME, [:merge_request_id, :note_id_convert_to_bigint], unique: true,
+ name: 'mr_user_mentions_on_mr_id_and_note_id_convert_to_bigint_index'
+
+ # This will replace the existing merge_request_user_mentions_on_mr_id_index
+ add_concurrent_index TABLE_NAME, :merge_request_id, unique: true,
+ name: 'merge_request_user_mentions_on_mr_id_index_convert_to_bigint',
+ where: 'note_id_convert_to_bigint IS NULL'
+
+ # This will replace the existing fk_rails_c440b9ea31
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
+ name: 'fk_merge_request_user_mentions_note_id_convert_to_bigint',
+ on_delete: :cascade
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE notes, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id TO note_id_tmp"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_convert_to_bigint TO note_id"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_tmp TO note_id_convert_to_bigint"
+
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger
+ .on_table(TABLE_NAME, connection: connection)
+ .name(:note_id, :note_id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ execute 'DROP INDEX IF EXISTS index_merge_request_user_mentions_on_note_id'
+ rename_index TABLE_NAME, 'index_merge_request_user_mentions_note_id_convert_to_bigint',
+ 'index_merge_request_user_mentions_on_note_id'
+
+ execute 'DROP INDEX IF EXISTS merge_request_user_mentions_on_mr_id_and_note_id_index'
+ rename_index TABLE_NAME, 'mr_user_mentions_on_mr_id_and_note_id_convert_to_bigint_index',
+ 'merge_request_user_mentions_on_mr_id_and_note_id_index'
+
+ execute 'DROP INDEX IF EXISTS merge_request_user_mentions_on_mr_id_index'
+ rename_index TABLE_NAME, 'merge_request_user_mentions_on_mr_id_index_convert_to_bigint',
+ 'merge_request_user_mentions_on_mr_id_index'
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_c440b9ea31"
+ rename_constraint(TABLE_NAME, 'fk_merge_request_user_mentions_note_id_convert_to_bigint', 'fk_rails_c440b9ea31')
+ end
+ end
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+
+ def columns_already_swapped?
+ table_columns = columns(TABLE_NAME)
+ note_id = table_columns.find { |c| c.name == 'note_id' }
+ note_id_convert_to_bigint = table_columns.find { |c| c.name == 'note_id_convert_to_bigint' }
+
+ note_id_convert_to_bigint.sql_type == 'integer' && note_id.sql_type == 'bigint'
+ end
+end
diff --git a/db/post_migrate/20230316185746_drop_packages_events_table.rb b/db/post_migrate/20230316185746_drop_packages_events_table.rb
index bb51fc7ae9c..f8b37651249 100644
--- a/db/post_migrate/20230316185746_drop_packages_events_table.rb
+++ b/db/post_migrate/20230316185746_drop_packages_events_table.rb
@@ -8,7 +8,7 @@ class DropPackagesEventsTable < Gitlab::Database::Migration[2.1]
def down
return if table_exists?(:packages_events)
- create_table :packages_events do |t| # rubocop:disable Migration/SchemaAdditionMethodsNoPost
+ create_table :packages_events do |t|
t.integer :event_type, limit: 2, null: false
t.integer :event_scope, limit: 2, null: false
t.integer :originator_type, limit: 2, null: false
diff --git a/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb b/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb
index b4468c851ae..59bff26f964 100644
--- a/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb
+++ b/db/post_migrate/20230317004428_migrate_daily_redis_hll_events_to_weekly_aggregation.rb
@@ -3,6 +3,93 @@
class MigrateDailyRedisHllEventsToWeeklyAggregation < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
+ DAILY_EVENTS =
+ %w[g_edit_by_web_ide
+ g_edit_by_sfe
+ g_edit_by_snippet_ide
+ g_edit_by_live_preview
+ wiki_action
+ design_action
+ project_action
+ git_write_action
+ merge_request_action
+ i_source_code_code_intelligence
+ g_project_management_issue_title_changed
+ g_project_management_issue_description_changed
+ g_project_management_issue_assignee_changed
+ g_project_management_issue_made_confidential
+ g_project_management_issue_made_visible
+ g_project_management_issue_created
+ g_project_management_issue_closed
+ g_project_management_issue_reopened
+ g_project_management_issue_label_changed
+ g_project_management_issue_milestone_changed
+ g_project_management_issue_cross_referenced
+ g_project_management_issue_moved
+ g_project_management_issue_related
+ g_project_management_issue_unrelated
+ g_project_management_issue_marked_as_duplicate
+ g_project_management_issue_locked
+ g_project_management_issue_unlocked
+ g_project_management_issue_designs_added
+ g_project_management_issue_designs_modified
+ g_project_management_issue_designs_removed
+ g_project_management_issue_due_date_changed
+ g_project_management_issue_design_comments_removed
+ g_project_management_issue_time_estimate_changed
+ g_project_management_issue_time_spent_changed
+ g_project_management_issue_comment_added
+ g_project_management_issue_comment_edited
+ g_project_management_issue_comment_removed
+ g_project_management_issue_cloned
+ g_geo_proxied_requests
+ approval_project_rule_created
+ g_project_management_issue_added_to_epic
+ g_project_management_issue_changed_epic
+ g_project_management_issue_health_status_changed
+ g_project_management_issue_iteration_changed
+ g_project_management_issue_removed_from_epic
+ g_project_management_issue_weight_changed
+ g_geo_proxied_requests
+ g_project_management_users_creating_epic_boards
+ g_project_management_users_viewing_epic_boards
+ g_project_management_users_updating_epic_board_names
+ g_project_management_epic_created
+ project_management_users_unchecking_epic_task
+ project_management_users_checking_epic_task
+ g_project_management_users_updating_epic_titles
+ g_project_management_users_updating_epic_descriptions
+ g_project_management_users_creating_epic_notes
+ g_project_management_users_updating_epic_notes
+ g_project_management_users_destroying_epic_notes
+ g_project_management_users_awarding_epic_emoji
+ g_project_management_users_removing_epic_emoji
+ g_project_management_users_setting_epic_start_date_as_fixed
+ g_project_management_users_updating_fixed_epic_start_date
+ g_project_management_users_setting_epic_start_date_as_inherited
+ g_project_management_users_setting_epic_due_date_as_fixed
+ g_project_management_users_updating_fixed_epic_due_date
+ g_project_management_users_setting_epic_due_date_as_inherited
+ g_project_management_epic_issue_added
+ g_project_management_epic_issue_removed
+ g_project_management_epic_issue_moved_from_project
+ g_project_management_users_updating_epic_parent
+ g_project_management_epic_closed
+ g_project_management_epic_reopened
+ g_project_management_issue_promoted_to_epic
+ g_project_management_users_setting_epic_confidential
+ g_project_management_users_setting_epic_visible
+ g_project_management_epic_users_changing_labels
+ g_project_management_epic_destroyed
+ g_project_management_epic_cross_referenced
+ g_project_management_users_epic_issue_added_from_epic
+ g_project_management_epic_related_added
+ g_project_management_epic_related_removed
+ g_project_management_epic_blocking_added
+ g_project_management_epic_blocking_removed
+ g_project_management_epic_blocked_added
+ g_project_management_epic_blocked_removed].freeze
+
def up
days_back = 29.days
start_date = Date.today - days_back - 1.day
@@ -10,7 +97,7 @@ class MigrateDailyRedisHllEventsToWeeklyAggregation < Gitlab::Database::Migratio
keys = {}
Gitlab::UsageDataCounters::HLLRedisCounter.known_events.each do |event|
- next unless event[:aggregation].to_sym == :daily
+ next unless DAILY_EVENTS.include?(event[:name].to_s)
(start_date..end_date).each do |date|
daily_key = redis_key(event, date, :daily)
diff --git a/db/post_migrate/20230323131521_remove_machine_id_from_builds_metadata.rb b/db/post_migrate/20230323131521_remove_machine_id_from_builds_metadata.rb
index f034bc21847..41d23735807 100644
--- a/db/post_migrate/20230323131521_remove_machine_id_from_builds_metadata.rb
+++ b/db/post_migrate/20230323131521_remove_machine_id_from_builds_metadata.rb
@@ -14,7 +14,7 @@ class RemoveMachineIdFromBuildsMetadata < Gitlab::Database::Migration[2.1]
end
def down
- add_column :p_ci_builds_metadata, :runner_machine_id, :bigint, if_not_exists: true # rubocop: disable Migration/SchemaAdditionMethodsNoPost
+ add_column :p_ci_builds_metadata, :runner_machine_id, :bigint, if_not_exists: true
add_concurrent_partitioned_index :p_ci_builds_metadata, :runner_machine_id, name: INDEX_NAME,
where: 'runner_machine_id IS NOT NULL'
diff --git a/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb b/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb
index f09888bd821..17776d8e42e 100644
--- a/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb
+++ b/db/post_migrate/20230328111013_re_migrate_redis_slot_keys.rb
@@ -3,9 +3,98 @@
class ReMigrateRedisSlotKeys < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
+ KEY_EXPIRY_LENGTH = 6.weeks
+
+ DAILY_EVENTS =
+ %w[g_edit_by_web_ide
+ g_edit_by_sfe
+ g_edit_by_snippet_ide
+ g_edit_by_live_preview
+ wiki_action
+ design_action
+ project_action
+ git_write_action
+ merge_request_action
+ i_source_code_code_intelligence
+ g_project_management_issue_title_changed
+ g_project_management_issue_description_changed
+ g_project_management_issue_assignee_changed
+ g_project_management_issue_made_confidential
+ g_project_management_issue_made_visible
+ g_project_management_issue_created
+ g_project_management_issue_closed
+ g_project_management_issue_reopened
+ g_project_management_issue_label_changed
+ g_project_management_issue_milestone_changed
+ g_project_management_issue_cross_referenced
+ g_project_management_issue_moved
+ g_project_management_issue_related
+ g_project_management_issue_unrelated
+ g_project_management_issue_marked_as_duplicate
+ g_project_management_issue_locked
+ g_project_management_issue_unlocked
+ g_project_management_issue_designs_added
+ g_project_management_issue_designs_modified
+ g_project_management_issue_designs_removed
+ g_project_management_issue_due_date_changed
+ g_project_management_issue_design_comments_removed
+ g_project_management_issue_time_estimate_changed
+ g_project_management_issue_time_spent_changed
+ g_project_management_issue_comment_added
+ g_project_management_issue_comment_edited
+ g_project_management_issue_comment_removed
+ g_project_management_issue_cloned
+ g_geo_proxied_requests
+ approval_project_rule_created
+ g_project_management_issue_added_to_epic
+ g_project_management_issue_changed_epic
+ g_project_management_issue_health_status_changed
+ g_project_management_issue_iteration_changed
+ g_project_management_issue_removed_from_epic
+ g_project_management_issue_weight_changed
+ g_geo_proxied_requests
+ g_project_management_users_creating_epic_boards
+ g_project_management_users_viewing_epic_boards
+ g_project_management_users_updating_epic_board_names
+ g_project_management_epic_created
+ project_management_users_unchecking_epic_task
+ project_management_users_checking_epic_task
+ g_project_management_users_updating_epic_titles
+ g_project_management_users_updating_epic_descriptions
+ g_project_management_users_creating_epic_notes
+ g_project_management_users_updating_epic_notes
+ g_project_management_users_destroying_epic_notes
+ g_project_management_users_awarding_epic_emoji
+ g_project_management_users_removing_epic_emoji
+ g_project_management_users_setting_epic_start_date_as_fixed
+ g_project_management_users_updating_fixed_epic_start_date
+ g_project_management_users_setting_epic_start_date_as_inherited
+ g_project_management_users_setting_epic_due_date_as_fixed
+ g_project_management_users_updating_fixed_epic_due_date
+ g_project_management_users_setting_epic_due_date_as_inherited
+ g_project_management_epic_issue_added
+ g_project_management_epic_issue_removed
+ g_project_management_epic_issue_moved_from_project
+ g_project_management_users_updating_epic_parent
+ g_project_management_epic_closed
+ g_project_management_epic_reopened
+ g_project_management_issue_promoted_to_epic
+ g_project_management_users_setting_epic_confidential
+ g_project_management_users_setting_epic_visible
+ g_project_management_epic_users_changing_labels
+ g_project_management_epic_destroyed
+ g_project_management_epic_cross_referenced
+ g_project_management_users_epic_issue_added_from_epic
+ g_project_management_epic_related_added
+ g_project_management_epic_related_removed
+ g_project_management_epic_blocking_added
+ g_project_management_epic_blocking_removed
+ g_project_management_epic_blocked_added
+ g_project_management_epic_blocked_removed].freeze
+
def up
Gitlab::UsageDataCounters::HLLRedisCounter.known_events.each do |event|
- if event[:aggregation].to_sym == :daily
+ if DAILY_EVENTS.include?(event[:name].to_s)
migrate_daily_aggregated(event)
else
migrate_weekly_aggregated(event)
@@ -20,7 +109,7 @@ class ReMigrateRedisSlotKeys < Gitlab::Database::Migration[2.1]
private
def migrate_daily_aggregated(event)
- days_back = Gitlab::UsageDataCounters::HLLRedisCounter::DEFAULT_DAILY_KEY_EXPIRY_LENGTH
+ days_back = 29.days
start_date = Date.today - days_back - 1.day
end_date = Date.today + 1.day
@@ -30,7 +119,7 @@ class ReMigrateRedisSlotKeys < Gitlab::Database::Migration[2.1]
end
def migrate_weekly_aggregated(event)
- weeks_back = Gitlab::UsageDataCounters::HLLRedisCounter::DEFAULT_WEEKLY_KEY_EXPIRY_LENGTH
+ weeks_back = KEY_EXPIRY_LENGTH
start_date = (Date.today - weeks_back).beginning_of_week - 1.day
end_date = Date.today.end_of_week + 1.day
@@ -49,7 +138,7 @@ class ReMigrateRedisSlotKeys < Gitlab::Database::Migration[2.1]
temp_key = new_key + "_#{Time.current.to_i}"
ttl = redis.ttl(old_key)
- ttl = ttl > 0 ? ttl : Gitlab::UsageDataCounters::HLLRedisCounter.send(:expiry, event)
+ ttl = ttl > 0 ? ttl : KEY_EXPIRY_LENGTH
redis.multi do |multi|
multi.set(temp_key, hll_blob, ex: 1.day.to_i)
@@ -77,7 +166,7 @@ class ReMigrateRedisSlotKeys < Gitlab::Database::Migration[2.1]
end
def apply_time_aggregation(key, time, event)
- if event[:aggregation].to_sym == :daily
+ if DAILY_EVENTS.include?(event[:name].to_s)
year_day = time.strftime('%G-%j')
"#{year_day}-#{key}"
else
diff --git a/db/post_migrate/20230412141541_reschedule_links_avoiding_duplication.rb b/db/post_migrate/20230412141541_reschedule_links_avoiding_duplication.rb
index 9c6213c60ee..8449acb33e1 100644
--- a/db/post_migrate/20230412141541_reschedule_links_avoiding_duplication.rb
+++ b/db/post_migrate/20230412141541_reschedule_links_avoiding_duplication.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-# rubocop: disable BackgroundMigration/MissingDictionaryFile
-
class RescheduleLinksAvoidingDuplication < Gitlab::Database::Migration[2.1]
MIGRATION = 'MigrateLinksForVulnerabilityFindings'
DELAY_INTERVAL = 2.minutes
@@ -13,20 +11,10 @@ class RescheduleLinksAvoidingDuplication < Gitlab::Database::Migration[2.1]
restrict_gitlab_migration gitlab_schema: :gitlab_main
def up
- delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, [])
-
- queue_batched_background_migration(
- MIGRATION,
- :vulnerability_occurrences,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op as it is rescheduled via db/post_migrate/20230412141541_reschedule_links_avoiding_duplication.rb
end
def down
- delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, [])
+ # no-op as it is rescheduled via db/post_migrate/20230412141541_reschedule_links_avoiding_duplication.rb
end
end
-# rubocop: enable BackgroundMigration/MissingDictionaryFile
diff --git a/db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb b/db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb
index cb29b47a64d..cf6736fb6c1 100644
--- a/db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb
+++ b/db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb
@@ -9,14 +9,14 @@ class SwapIssueUserMentionsNoteIdToBigintForGitlabDotCom2 < Gitlab::Database::Mi
def up
return unless should_run?
- return if columns_alredy_swapped?
+ return if columns_already_swapped?
swap
end
def down
return unless should_run?
- return unless columns_alredy_swapped?
+ return unless columns_already_swapped?
swap
@@ -83,7 +83,7 @@ class SwapIssueUserMentionsNoteIdToBigintForGitlabDotCom2 < Gitlab::Database::Mi
com_or_dev_or_test_but_not_jh?
end
- def columns_alredy_swapped?
+ def columns_already_swapped?
table_columns = columns(TABLE_NAME)
note_id = table_columns.find { |c| c.name == 'note_id' }
note_id_convert_to_bigint = table_columns.find { |c| c.name == 'note_id_convert_to_bigint' }
diff --git a/db/post_migrate/20230425114355_remove_application_settings_clickhouse_connection_string.rb b/db/post_migrate/20230425114355_remove_application_settings_clickhouse_connection_string.rb
index d5bdd33a952..3c27c48a7f3 100644
--- a/db/post_migrate/20230425114355_remove_application_settings_clickhouse_connection_string.rb
+++ b/db/post_migrate/20230425114355_remove_application_settings_clickhouse_connection_string.rb
@@ -9,9 +9,7 @@ class RemoveApplicationSettingsClickhouseConnectionString < Gitlab::Database::Mi
def down
unless column_exists?(:application_settings, :clickhouse_connection_string)
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
add_column :application_settings, :clickhouse_connection_string, :text
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
add_text_limit :application_settings, :clickhouse_connection_string, 1024
diff --git a/db/post_migrate/20230426030342_index_system_note_metadata_on_id_for_relate_and_unrelate_actions.rb b/db/post_migrate/20230426030342_index_system_note_metadata_on_id_for_relate_and_unrelate_actions.rb
new file mode 100644
index 00000000000..2b21a25311f
--- /dev/null
+++ b/db/post_migrate/20230426030342_index_system_note_metadata_on_id_for_relate_and_unrelate_actions.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class IndexSystemNoteMetadataOnIdForRelateAndUnrelateActions < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'tmp_index_for_backfilling_resource_link_events'
+ CONDITION = "action='relate_to_parent' OR action='unrelate_from_parent'"
+
+ disable_ddl_transaction!
+
+ def up
+ # Temporary index to be removed in https://gitlab.com/gitlab-org/gitlab/-/issues/408797
+ add_concurrent_index :system_note_metadata, :id,
+ where: CONDITION,
+ name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :system_note_metadata, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230426085615_queue_backfill_resource_link_events.rb b/db/post_migrate/20230426085615_queue_backfill_resource_link_events.rb
new file mode 100644
index 00000000000..fe4ea099d2e
--- /dev/null
+++ b/db/post_migrate/20230426085615_queue_backfill_resource_link_events.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+class QueueBackfillResourceLinkEvents < Gitlab::Database::Migration[2.1]
+ MIGRATION = "BackfillResourceLinkEvents"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 5000
+ SUB_BATCH_SIZE = 10
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ class SystemNoteMetadata < MigrationRecord
+ self.table_name = 'system_note_metadata'
+
+ def self.batch_start_id
+ SystemNoteMetadata
+ .select(:id)
+ .where("action='relate_to_parent' OR action='unrelate_from_parent'")
+ .order(id: :asc)
+ .limit(1)
+ .first&.id
+ end
+ end
+
+ def up
+ batch_min_value = SystemNoteMetadata.batch_start_id
+
+ return unless batch_min_value
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :system_note_metadata,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE,
+ batch_min_value: batch_min_value
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :system_note_metadata, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230501180958_drop_clusters_applications_cert_managers.rb b/db/post_migrate/20230501180958_drop_clusters_applications_cert_managers.rb
index 8949e37dcc3..3eb5fc13a2a 100644
--- a/db/post_migrate/20230501180958_drop_clusters_applications_cert_managers.rb
+++ b/db/post_migrate/20230501180958_drop_clusters_applications_cert_managers.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsCertManagers < Gitlab::Database::Migration[2.1]
# Based on init migration:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20181228175414_init_schema.rb#L680-L689
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table "clusters_applications_cert_managers", id: :serial, force: :cascade do |t|
t.integer "cluster_id", null: false
@@ -23,5 +22,4 @@ class DropClustersApplicationsCertManagers < Gitlab::Database::Migration[2.1]
t.index ["cluster_id"], name: "index_clusters_applications_cert_managers_on_cluster_id", unique: true
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230502102833_add_index_to_members_on_source_and_type_and_access_level.rb b/db/post_migrate/20230502102833_add_index_to_members_on_source_and_type_and_access_level.rb
new file mode 100644
index 00000000000..29960856299
--- /dev/null
+++ b/db/post_migrate/20230502102833_add_index_to_members_on_source_and_type_and_access_level.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexToMembersOnSourceAndTypeAndAccessLevel < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_members_on_source_and_type_and_access_level'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :members, %i[source_id source_type type access_level], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :members, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230502120022_add_index_to_project_authorizations_on_project_user_access_level.rb b/db/post_migrate/20230502120022_add_index_to_project_authorizations_on_project_user_access_level.rb
new file mode 100644
index 00000000000..3f8561b2be7
--- /dev/null
+++ b/db/post_migrate/20230502120022_add_index_to_project_authorizations_on_project_user_access_level.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexToProjectAuthorizationsOnProjectUserAccessLevel < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_project_authorizations_on_project_user_access_level'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :project_authorizations, %i[project_id user_id access_level], name: INDEX_NAME, unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name :project_authorizations, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230502134532_drop_clusters_applications_cilium.rb b/db/post_migrate/20230502134532_drop_clusters_applications_cilium.rb
index 8d80bae0a52..2c7b7d89bf5 100644
--- a/db/post_migrate/20230502134532_drop_clusters_applications_cilium.rb
+++ b/db/post_migrate/20230502134532_drop_clusters_applications_cilium.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsCilium < Gitlab::Database::Migration[2.1]
# Based on original migration:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20200615234047_create_clusters_applications_cilium.rb
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table :clusters_applications_cilium do |t|
t.references :cluster, null: false, index: { unique: true }
@@ -19,5 +18,4 @@ class DropClustersApplicationsCilium < Gitlab::Database::Migration[2.1]
t.text :status_reason # rubocop:disable Migration/AddLimitToTextColumns
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230502182754_drop_clusters_applications_crossplane.rb b/db/post_migrate/20230502182754_drop_clusters_applications_crossplane.rb
index c35cfc8fd96..1eeb7770c82 100644
--- a/db/post_migrate/20230502182754_drop_clusters_applications_crossplane.rb
+++ b/db/post_migrate/20230502182754_drop_clusters_applications_crossplane.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsCrossplane < Gitlab::Database::Migration[2.1]
# Based on original migration:
# https://gitlab.com/gitlab-org/gitlab/-/blob/8b1637296b286a5c46e0d8fdf6da42a43a7c9986/db/migrate/20191017191341_create_clusters_applications_crossplane.rb
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table :clusters_applications_crossplane, id: :integer do |t|
t.timestamps_with_timezone null: false
@@ -22,5 +21,4 @@ class DropClustersApplicationsCrossplane < Gitlab::Database::Migration[2.1]
t.index :cluster_id, unique: true
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230502193525_drop_clusters_applications_helm.rb b/db/post_migrate/20230502193525_drop_clusters_applications_helm.rb
index 21df851229c..c435b356e01 100644
--- a/db/post_migrate/20230502193525_drop_clusters_applications_helm.rb
+++ b/db/post_migrate/20230502193525_drop_clusters_applications_helm.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsHelm < Gitlab::Database::Migration[2.1]
# Based on init schema:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20181228175414_init_schema.rb#L691-L702
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
# rubocop:disable Migration/Datetime
def down
create_table "clusters_applications_helm", id: :serial, force: :cascade do |t|
@@ -26,6 +25,5 @@ class DropClustersApplicationsHelm < Gitlab::Database::Migration[2.1]
t.index ["cluster_id"], name: "index_clusters_applications_helm_on_cluster_id", unique: true
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
# rubocop:enable Migration/Datetime
end
diff --git a/db/post_migrate/20230502201251_drop_clusters_applications_ingress.rb b/db/post_migrate/20230502201251_drop_clusters_applications_ingress.rb
index a349346f91b..3ccc536cb7e 100644
--- a/db/post_migrate/20230502201251_drop_clusters_applications_ingress.rb
+++ b/db/post_migrate/20230502201251_drop_clusters_applications_ingress.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsIngress < Gitlab::Database::Migration[2.1]
# Based on init schema:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20181228175414_init_schema.rb#L704-L715
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
# rubocop:disable Migration/Datetime
def down
create_table "clusters_applications_ingress", id: :serial, force: :cascade do |t|
@@ -27,6 +26,5 @@ class DropClustersApplicationsIngress < Gitlab::Database::Migration[2.1]
t.index ["cluster_id"], name: "index_clusters_applications_ingress_on_cluster_id", unique: true
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
# rubocop:enable Migration/Datetime
end
diff --git a/db/post_migrate/20230503115918_drop_clusters_applications_jupyter.rb b/db/post_migrate/20230503115918_drop_clusters_applications_jupyter.rb
index 3c2a0cc3ee8..bd98aa6d19c 100644
--- a/db/post_migrate/20230503115918_drop_clusters_applications_jupyter.rb
+++ b/db/post_migrate/20230503115918_drop_clusters_applications_jupyter.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsJupyter < Gitlab::Database::Migration[2.1]
# Based on init schema:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20181228175414_init_schema.rb#L717-L728
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table "clusters_applications_jupyter", id: :serial, force: :cascade do |t|
t.integer "cluster_id", null: false
@@ -25,5 +24,4 @@ class DropClustersApplicationsJupyter < Gitlab::Database::Migration[2.1]
t.index ["oauth_application_id"], name: "index_clusters_applications_jupyter_on_oauth_application_id"
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230503152349_drop_clusters_applications_knative.rb b/db/post_migrate/20230503152349_drop_clusters_applications_knative.rb
index c94b9bba64b..e8473b74408 100644
--- a/db/post_migrate/20230503152349_drop_clusters_applications_knative.rb
+++ b/db/post_migrate/20230503152349_drop_clusters_applications_knative.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsKnative < Gitlab::Database::Migration[2.1]
# Based on init migration:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20181228175414_init_schema.rb#L730-L740
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table "clusters_applications_knative", id: :serial, force: :cascade do |t|
t.integer "cluster_id", null: false
@@ -25,5 +24,4 @@ class DropClustersApplicationsKnative < Gitlab::Database::Migration[2.1]
t.index ["cluster_id"], name: "index_clusters_applications_knative_on_cluster_id", unique: true
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230503173101_drop_clusters_applications_prometheus.rb b/db/post_migrate/20230503173101_drop_clusters_applications_prometheus.rb
index 6391c1ee5ae..b62452f2052 100644
--- a/db/post_migrate/20230503173101_drop_clusters_applications_prometheus.rb
+++ b/db/post_migrate/20230503173101_drop_clusters_applications_prometheus.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsPrometheus < Gitlab::Database::Migration[2.1]
# Based on init schema:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20181228175414_init_schema.rb#L742-L750
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table "clusters_applications_prometheus", id: :serial, force: :cascade do |t|
t.integer "cluster_id", null: false
@@ -26,5 +25,4 @@ class DropClustersApplicationsPrometheus < Gitlab::Database::Migration[2.1]
t.boolean "healthy"
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230503175406_drop_clusters_applications_runners.rb b/db/post_migrate/20230503175406_drop_clusters_applications_runners.rb
index 813cb23f56a..a4ab75dbce5 100644
--- a/db/post_migrate/20230503175406_drop_clusters_applications_runners.rb
+++ b/db/post_migrate/20230503175406_drop_clusters_applications_runners.rb
@@ -10,7 +10,6 @@ class DropClustersApplicationsRunners < Gitlab::Database::Migration[2.1]
# Based on init schema:
# https://gitlab.com/gitlab-org/gitlab/-/blob/b237f836df215a4ada92b9406733e6cd2483ca2d/db/migrate/20181228175414_init_schema.rb#L752-L763
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table "clusters_applications_runners", id: :serial, force: :cascade do |t|
t.integer "cluster_id", null: false
@@ -25,5 +24,4 @@ class DropClustersApplicationsRunners < Gitlab::Database::Migration[2.1]
t.index ["runner_id"], name: "index_clusters_applications_runners_on_runner_id"
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230503181808_drop_serverless_domain_cluster.rb b/db/post_migrate/20230503181808_drop_serverless_domain_cluster.rb
index 94d3a2faf3b..003f2d91b54 100644
--- a/db/post_migrate/20230503181808_drop_serverless_domain_cluster.rb
+++ b/db/post_migrate/20230503181808_drop_serverless_domain_cluster.rb
@@ -10,7 +10,6 @@ class DropServerlessDomainCluster < Gitlab::Database::Migration[2.1]
# Based on original migration:
# https://gitlab.com/gitlab-org/gitlab/-/blob/5f7bd5b1455d87e2f1a2d1ae2c1147d51e97aa55/db/migrate/20191127030005_create_serverless_domain_cluster.rb
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
def down
create_table :serverless_domain_cluster, id: false, primary_key: :uuid do |t|
t.string :uuid, null: false, limit: 14, primary_key: true
@@ -29,5 +28,4 @@ class DropServerlessDomainCluster < Gitlab::Database::Migration[2.1]
t.index :creator_id, name: 'index_serverless_domain_cluster_on_creator_id'
end
end
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
diff --git a/db/post_migrate/20230508175057_backfill_corrected_secure_files_expirations.rb b/db/post_migrate/20230508175057_backfill_corrected_secure_files_expirations.rb
index 9644a555756..d26fabb316b 100644
--- a/db/post_migrate/20230508175057_backfill_corrected_secure_files_expirations.rb
+++ b/db/post_migrate/20230508175057_backfill_corrected_secure_files_expirations.rb
@@ -1,27 +1,10 @@
# frozen_string_literal: true
class BackfillCorrectedSecureFilesExpirations < Gitlab::Database::Migration[2.1]
- disable_ddl_transaction!
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
- BATCH_SIZE = 1000
-
- def up
- each_batch_range('ci_secure_files', of: BATCH_SIZE) do |min, max|
- sql = <<-SQL
- SELECT id
- FROM ci_secure_files
- WHERE name ILIKE any (array['%.cer', '%.p12'])
- AND ci_secure_files.id BETWEEN #{min} AND #{max}
- SQL
-
- rows = execute(sql)
-
- rows.each do |row|
- ::Ci::ParseSecureFileMetadataWorker.perform_async(row["id"])
- end
- end
- end
+ # The contents of this migration have been removed but the structure has been
+ # left in place because this could be promlematic for some customers, but it has
+ # already been run in gitlab.com staging and production environments
+ def up; end
def down; end
end
diff --git a/db/post_migrate/20230510013754_cleanup_notes_bigint_preparation.rb b/db/post_migrate/20230510013754_cleanup_notes_bigint_preparation.rb
new file mode 100644
index 00000000000..b2b898059b8
--- /dev/null
+++ b/db/post_migrate/20230510013754_cleanup_notes_bigint_preparation.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+class CleanupNotesBigintPreparation < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+
+ remove_concurrent_index_by_name(
+ :merge_request_user_mentions,
+ :index_merge_request_user_mentions_note_id_convert_to_bigint,
+ if_exists: true
+ )
+
+ remove_concurrent_index_by_name(
+ :issue_user_mentions,
+ :index_issue_user_mentions_on_note_id_convert_to_bigint,
+ if_exists: true
+ )
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ :issue_user_mentions,
+ :notes,
+ name: :fk_issue_user_mentions_note_id_convert_to_bigint,
+ reverse_lock_order: true
+ )
+ end
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ :merge_request_user_mentions,
+ :notes,
+ name: :fk_merge_request_user_mentions_note_id_convert_to_bigint,
+ reverse_lock_order: true
+ )
+ end
+ end
+
+ def down
+ # No-op
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230510062503_queue_cleanup_personal_access_tokens_with_nil_expires_at.rb b/db/post_migrate/20230510062503_queue_cleanup_personal_access_tokens_with_nil_expires_at.rb
index a7dd1bda9db..859bdb8c3e4 100644
--- a/db/post_migrate/20230510062503_queue_cleanup_personal_access_tokens_with_nil_expires_at.rb
+++ b/db/post_migrate/20230510062503_queue_cleanup_personal_access_tokens_with_nil_expires_at.rb
@@ -1,23 +1,15 @@
# frozen_string_literal: true
class QueueCleanupPersonalAccessTokensWithNilExpiresAt < Gitlab::Database::Migration[2.1]
- MIGRATION = "CleanupPersonalAccessTokensWithNilExpiresAt"
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 50_000
-
- restrict_gitlab_migration gitlab_schema: :gitlab_main
-
- def up
- queue_batched_background_migration(
- MIGRATION,
- :personal_access_tokens,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- delete_batched_background_migration(MIGRATION, :personal_access_tokens, :id, [])
- end
+ # per: https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#requeuing-batched-background-migrations
+ # > When you requeue the batched background migration, turn the original queuing
+ # > into a no-op by clearing up the #up and #down methods of the migration
+ # > performing the requeuing. Otherwise, the batched background migration is
+ # > queued multiple times on systems that are upgrading multiple patch releases
+ # > at once.
+ #
+ # being re-run via https://gitlab.com/gitlab-org/gitlab/-/merge_requests/123002
+ def up; end
+
+ def down; end
end
diff --git a/db/post_migrate/20230510130050_remove_ci_triggers_ref_column.rb b/db/post_migrate/20230510130050_remove_ci_triggers_ref_column.rb
index fa4fab5b8df..84b69f7bc86 100644
--- a/db/post_migrate/20230510130050_remove_ci_triggers_ref_column.rb
+++ b/db/post_migrate/20230510130050_remove_ci_triggers_ref_column.rb
@@ -8,8 +8,6 @@ class RemoveCiTriggersRefColumn < Gitlab::Database::Migration[2.1]
end
def down
- # rubocop:disable Migration/SchemaAdditionMethodsNoPost
add_column :ci_triggers, :ref, :string, if_not_exists: true
- # rubocop:enable Migration/SchemaAdditionMethodsNoPost
end
end
diff --git a/db/post_migrate/20230510152153_remove_mr_state_id_temp_index_with_right_column.rb b/db/post_migrate/20230510152153_remove_mr_state_id_temp_index_with_right_column.rb
new file mode 100644
index 00000000000..57b21bcf4ed
--- /dev/null
+++ b/db/post_migrate/20230510152153_remove_mr_state_id_temp_index_with_right_column.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveMrStateIdTempIndexWithRightColumn < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'merge_requests_state_id_temp_index'
+
+ # TODO: Index to be destroyed synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/408766
+
+ def up
+ prepare_async_index_removal :merge_requests, :id, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :merge_requests, :id, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230511132140_create_component_id_index.rb b/db/post_migrate/20230511132140_create_component_id_index.rb
new file mode 100644
index 00000000000..3b466010f7c
--- /dev/null
+++ b/db/post_migrate/20230511132140_create_component_id_index.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class CreateComponentIdIndex < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_sbom_occurrences_on_project_id_component_id'
+
+ def up
+ return if index_exists_by_name?(:sbom_occurrences, INDEX_NAME)
+
+ add_concurrent_index :sbom_occurrences, [:project_id, :component_id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :sbom_sources, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230512104238_add_audit_events_group_index.rb b/db/post_migrate/20230512104238_add_audit_events_group_index.rb
new file mode 100644
index 00000000000..d1d7e5f26fc
--- /dev/null
+++ b/db/post_migrate/20230512104238_add_audit_events_group_index.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddAuditEventsGroupIndex < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ TABLE_NAME = :audit_events
+ COLUMN_NAMES = [:entity_id, :entity_type, :created_at, :id]
+ INDEX_NAME = 'index_audit_events_on_entity_id_and_entity_type_and_created_at'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_partitioned_index(TABLE_NAME, COLUMN_NAMES, name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_partitioned_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20230512143000_remove_dependency_list_exports_project_id_not_null_constraint.rb b/db/post_migrate/20230512143000_remove_dependency_list_exports_project_id_not_null_constraint.rb
new file mode 100644
index 00000000000..d7077e9dfdd
--- /dev/null
+++ b/db/post_migrate/20230512143000_remove_dependency_list_exports_project_id_not_null_constraint.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class RemoveDependencyListExportsProjectIdNotNullConstraint < Gitlab::Database::Migration[2.1]
+ def up
+ change_column_null :dependency_list_exports, :project_id, true
+ end
+
+ def down
+ # no-op as there can be null values after the migration
+ end
+end
diff --git a/db/post_migrate/20230515101208_index_group_id_on_dependency_list_exports.rb b/db/post_migrate/20230515101208_index_group_id_on_dependency_list_exports.rb
new file mode 100644
index 00000000000..6019074b1f7
--- /dev/null
+++ b/db/post_migrate/20230515101208_index_group_id_on_dependency_list_exports.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class IndexGroupIdOnDependencyListExports < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_dependency_list_exports_on_group_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :dependency_list_exports, :group_id, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :dependency_list_exports, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230515102353_add_foreign_key_to_group_id_on_dependency_list_exports.rb b/db/post_migrate/20230515102353_add_foreign_key_to_group_id_on_dependency_list_exports.rb
new file mode 100644
index 00000000000..2780c551b2d
--- /dev/null
+++ b/db/post_migrate/20230515102353_add_foreign_key_to_group_id_on_dependency_list_exports.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToGroupIdOnDependencyListExports < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :dependency_list_exports,
+ :namespaces,
+ column: :group_id,
+ on_delete: :cascade,
+ reverse_lock_order: true
+ end
+
+ def down
+ remove_foreign_key_if_exists :dependency_list_exports, column: :group_id
+ end
+end
diff --git a/db/post_migrate/20230515142300_add_unique_index_for_ml_model_packages.rb b/db/post_migrate/20230515142300_add_unique_index_for_ml_model_packages.rb
new file mode 100644
index 00000000000..a776c227032
--- /dev/null
+++ b/db/post_migrate/20230515142300_add_unique_index_for_ml_model_packages.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexForMlModelPackages < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'uniq_idx_packages_packages_on_project_id_name_version_ml_model'
+ PACKAGE_TYPE_ML_MODEL = 14
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :packages_packages, [:project_id, :name, :version],
+ unique: true,
+ where: "package_type = #{PACKAGE_TYPE_ML_MODEL}",
+ name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name(:packages_packages, INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20230515153600_finalize_back_fill_prepared_at_merge_requests.rb b/db/post_migrate/20230515153600_finalize_back_fill_prepared_at_merge_requests.rb
new file mode 100644
index 00000000000..6c0e4e722d2
--- /dev/null
+++ b/db/post_migrate/20230515153600_finalize_back_fill_prepared_at_merge_requests.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class FinalizeBackFillPreparedAtMergeRequests < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'BackfillPreparedAtMergeRequests'
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :merge_requests,
+ column_name: :id,
+ job_arguments: []
+ )
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20230516032545_add_unique_notes_id_convert_to_bigint_for_gitlab_com.rb b/db/post_migrate/20230516032545_add_unique_notes_id_convert_to_bigint_for_gitlab_com.rb
new file mode 100644
index 00000000000..330bf23434d
--- /dev/null
+++ b/db/post_migrate/20230516032545_add_unique_notes_id_convert_to_bigint_for_gitlab_com.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class AddUniqueNotesIdConvertToBigintForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :notes
+ INDEX_NAME = :index_notes_on_id_convert_to_bigint
+
+ def up
+ return unless should_run?
+
+ # This was created async for GitLab.com with
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119913
+ # and will replace the existing PK index when we swap the integer and bigint columns in
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119705
+ add_concurrent_index TABLE_NAME, :id_convert_to_bigint,
+ unique: true,
+ name: INDEX_NAME
+ end
+
+ def down
+ return unless should_run?
+
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230516033729_add_referencing_bigint_fks_for_notes_on_gitlab_com.rb b/db/post_migrate/20230516033729_add_referencing_bigint_fks_for_notes_on_gitlab_com.rb
new file mode 100644
index 00000000000..0cc77d43625
--- /dev/null
+++ b/db/post_migrate/20230516033729_add_referencing_bigint_fks_for_notes_on_gitlab_com.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+class AddReferencingBigintFksForNotesOnGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ REFERENCING_FOREIGN_KEYS = [
+ [:todos, :fk_91d1f47b13, :note_id, :cascade],
+ [:incident_management_timeline_events, :fk_d606a2a890, :promoted_from_note_id, :nullify],
+ [:system_note_metadata, :fk_d83a918cb1, :note_id, :cascade],
+ [:diff_note_positions, :fk_rails_13c7212859, :note_id, :cascade],
+ [:epic_user_mentions, :fk_rails_1c65976a49, :note_id, :cascade],
+ [:suggestions, :fk_rails_33b03a535c, :note_id, :cascade],
+ [:issue_user_mentions, :fk_rails_3861d9fefa, :note_id, :cascade],
+ [:note_diff_files, :fk_rails_3d66047aeb, :diff_note_id, :cascade],
+ [:snippet_user_mentions, :fk_rails_4d3f96b2cb, :note_id, :cascade],
+ [:design_user_mentions, :fk_rails_8de8c6d632, :note_id, :cascade],
+ [:vulnerability_user_mentions, :fk_rails_a18600f210, :note_id, :cascade],
+ [:commit_user_mentions, :fk_rails_a6760813e0, :note_id, :cascade],
+ [:merge_request_user_mentions, :fk_rails_c440b9ea31, :note_id, :cascade],
+ [:note_metadata, :fk_rails_d853224d37, :note_id, :cascade],
+ [:alert_management_alert_user_mentions, :fk_rails_eb2de0cdef, :note_id, :cascade],
+ [:timelogs, :fk_timelogs_note_id, :note_id, :nullify]
+ ]
+
+ def up
+ return unless should_run?
+
+ REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, on_delete)|
+ temporary_name = "#{name}_tmp"
+
+ # This will replace the existing FKs when
+ # we swap the integer and bigint columns in
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119705
+ add_concurrent_foreign_key(
+ from_table,
+ :notes,
+ column: column,
+ target_column: :id_convert_to_bigint,
+ name: temporary_name,
+ on_delete: on_delete,
+ reverse_lock_order: true,
+ validate: false)
+
+ prepare_async_foreign_key_validation from_table, column, name: temporary_name
+ end
+ end
+
+ def down
+ return unless should_run?
+
+ REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, _)|
+ temporary_name = "#{name}_tmp"
+
+ unprepare_async_foreign_key_validation from_table, column, name: temporary_name
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ from_table,
+ :notes,
+ name: temporary_name,
+ reverse_lock_order: true
+ )
+ end
+ end
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230516123202_create_routing_table_for_ci_builds.rb b/db/post_migrate/20230516123202_create_routing_table_for_ci_builds.rb
new file mode 100644
index 00000000000..b95c1307b1b
--- /dev/null
+++ b/db/post_migrate/20230516123202_create_routing_table_for_ci_builds.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+class CreateRoutingTableForCiBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_builds
+ PARENT_TABLE_NAME = :p_ci_builds
+ FIRST_PARTITION = 100
+ PARTITION_COLUMN = :partition_id
+ FOREIGN_KEYS = {
+ p_ci_builds_metadata: :fk_e20479742e_p,
+ p_ci_runner_machine_builds: :fk_bb490f12fe_p
+ }
+
+ def up
+ return if connection.table_exists?(PARENT_TABLE_NAME) && partition_attached?
+
+ convert_table_to_first_list_partition(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION,
+ lock_tables: %w[ci_pipelines ci_stages ci_builds ci_resource_groups]
+ )
+ end
+
+ def down
+ # rubocop:disable Migration/WithLockRetriesDisallowedMethod
+ with_lock_retries(raise_on_exhaustion: true) do
+ drop_foreign_keys
+
+ execute(<<~SQL)
+ ALTER TABLE #{PARENT_TABLE_NAME} DETACH PARTITION #{TABLE_NAME};
+ ALTER SEQUENCE ci_builds_id_seq OWNED BY #{TABLE_NAME}.id;
+ SQL
+
+ drop_table PARENT_TABLE_NAME
+ recreate_partition_foreign_keys
+ end
+ # rubocop:enable Migration/WithLockRetriesDisallowedMethod
+
+ finalize_foreign_keys_creation
+
+ prepare_constraint_for_list_partitioning(
+ table_name: TABLE_NAME,
+ partitioning_column: PARTITION_COLUMN,
+ parent_table_name: PARENT_TABLE_NAME,
+ initial_partitioning_value: FIRST_PARTITION
+ )
+ end
+
+ private
+
+ def partition_attached?
+ connection.select_value(<<~SQL)
+ SELECT true FROM postgres_partitions WHERE name = '#{TABLE_NAME}';
+ SQL
+ end
+
+ def drop_foreign_keys
+ FOREIGN_KEYS.each do |source, name|
+ remove_foreign_key_if_exists source, name: name
+ end
+ end
+
+ def recreate_partition_foreign_keys
+ FOREIGN_KEYS.each do |source, name|
+ Gitlab::Database::PostgresPartitionedTable.each_partition(source) do |partition|
+ execute(<<~SQL)
+ ALTER TABLE #{partition.identifier}
+ ADD CONSTRAINT #{name} FOREIGN KEY (partition_id, build_id)
+ REFERENCES #{TABLE_NAME}(partition_id, id)
+ ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;
+ SQL
+ end
+ end
+ end
+
+ def finalize_foreign_keys_creation
+ FOREIGN_KEYS.each do |source, name|
+ add_concurrent_partitioned_foreign_key(source, TABLE_NAME,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ reverse_lock_order: true,
+ on_update: :cascade,
+ on_delete: :cascade,
+ name: name
+ )
+ end
+ end
+end
diff --git a/db/post_migrate/20230516172446_prepare_issues_work_item_type_id_project_id_index.rb b/db/post_migrate/20230516172446_prepare_issues_work_item_type_id_project_id_index.rb
new file mode 100644
index 00000000000..45f00e8292d
--- /dev/null
+++ b/db/post_migrate/20230516172446_prepare_issues_work_item_type_id_project_id_index.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class PrepareIssuesWorkItemTypeIdProjectIdIndex < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_issues_on_work_item_type_id_project_id_created_at_state'
+
+ # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/121297
+ def up
+ prepare_async_index :issues, [:work_item_type_id, :project_id, :created_at, :state_id], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :issues, [:work_item_type_id, :project_id, :created_at, :state_id], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230516192543_add_issues_work_item_type_id_project_id_index.rb b/db/post_migrate/20230516192543_add_issues_work_item_type_id_project_id_index.rb
new file mode 100644
index 00000000000..2ae226bd85f
--- /dev/null
+++ b/db/post_migrate/20230516192543_add_issues_work_item_type_id_project_id_index.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIssuesWorkItemTypeIdProjectIdIndex < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_issues_on_work_item_type_id_project_id_created_at_state'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :issues, [:work_item_type_id, :project_id, :created_at, :state_id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :issues, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230517001535_prepare_async_index_for_ci_pipeline_variables_bigint_id.rb b/db/post_migrate/20230517001535_prepare_async_index_for_ci_pipeline_variables_bigint_id.rb
new file mode 100644
index 00000000000..55b46369870
--- /dev/null
+++ b/db/post_migrate/20230517001535_prepare_async_index_for_ci_pipeline_variables_bigint_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class PrepareAsyncIndexForCiPipelineVariablesBigintId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_pipeline_variables
+ INDEX_NAME = "index_#{TABLE_NAME}_on_id_convert_to_bigint"
+
+ # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/408936
+ def up
+ prepare_async_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230517005523_ensure_backfill_bigint_id_is_completed.rb b/db/post_migrate/20230517005523_ensure_backfill_bigint_id_is_completed.rb
new file mode 100644
index 00000000000..850ac7bcf5d
--- /dev/null
+++ b/db/post_migrate/20230517005523_ensure_backfill_bigint_id_is_completed.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureBackfillBigintIdIsCompleted < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_pipeline_variables
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: TABLE_NAME,
+ column_name: 'id',
+ job_arguments: [['id'], ['id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230517163300_queue_backfill_root_storage_statistics_fork_storage_sizes.rb b/db/post_migrate/20230517163300_queue_backfill_root_storage_statistics_fork_storage_sizes.rb
new file mode 100644
index 00000000000..6732e33d0a4
--- /dev/null
+++ b/db/post_migrate/20230517163300_queue_backfill_root_storage_statistics_fork_storage_sizes.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class QueueBackfillRootStorageStatisticsForkStorageSizes < Gitlab::Database::Migration[2.1]
+ MIGRATION = "BackfillRootStorageStatisticsForkStorageSizes"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 100
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :namespace_root_storage_statistics,
+ :namespace_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :namespace_root_storage_statistics, :namespace_id, [])
+ end
+end
diff --git a/db/post_migrate/20230518005523_add_concurrent_index_for_ci_pipeline_variables_bigint_id.rb b/db/post_migrate/20230518005523_add_concurrent_index_for_ci_pipeline_variables_bigint_id.rb
new file mode 100644
index 00000000000..19c48f7bf11
--- /dev/null
+++ b/db/post_migrate/20230518005523_add_concurrent_index_for_ci_pipeline_variables_bigint_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddConcurrentIndexForCiPipelineVariablesBigintId < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_pipeline_variables
+ INDEX_NAME = "index_#{TABLE_NAME}_on_id_convert_to_bigint"
+
+ def up
+ add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230518071251_queue_backfill_code_suggestions_namespace_settings.rb b/db/post_migrate/20230518071251_queue_backfill_code_suggestions_namespace_settings.rb
new file mode 100644
index 00000000000..bae143ddbb1
--- /dev/null
+++ b/db/post_migrate/20230518071251_queue_backfill_code_suggestions_namespace_settings.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class QueueBackfillCodeSuggestionsNamespaceSettings < Gitlab::Database::Migration[2.1]
+ MIGRATION = "BackfillCodeSuggestionsNamespaceSettings"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 50_000
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :namespace_settings,
+ :namespace_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :namespace_settings, :namespace_id, [])
+ end
+end
diff --git a/db/post_migrate/20230518121320_remove_time_format_in_24h_column.rb b/db/post_migrate/20230518121320_remove_time_format_in_24h_column.rb
new file mode 100644
index 00000000000..489c2446fe2
--- /dev/null
+++ b/db/post_migrate/20230518121320_remove_time_format_in_24h_column.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RemoveTimeFormatIn24hColumn < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def up
+ remove_column :user_preferences, :time_format_in_24h
+ end
+
+ def down
+ add_column :user_preferences, :time_format_in_24h, :boolean
+ end
+end
diff --git a/db/post_migrate/20230519011151_schedule_to_remove_invalid_deploy_access_level_groups.rb b/db/post_migrate/20230519011151_schedule_to_remove_invalid_deploy_access_level_groups.rb
new file mode 100644
index 00000000000..c3bd64634ce
--- /dev/null
+++ b/db/post_migrate/20230519011151_schedule_to_remove_invalid_deploy_access_level_groups.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class ScheduleToRemoveInvalidDeployAccessLevelGroups < Gitlab::Database::Migration[2.1]
+ MIGRATION = "RemoveInvalidDeployAccessLevelGroups"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 1000
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :protected_environment_deploy_access_levels,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :protected_environment_deploy_access_levels, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230519023720_swap_ci_pipeline_variables_pk_with_bigint.rb b/db/post_migrate/20230519023720_swap_ci_pipeline_variables_pk_with_bigint.rb
new file mode 100644
index 00000000000..6c088cd12a9
--- /dev/null
+++ b/db/post_migrate/20230519023720_swap_ci_pipeline_variables_pk_with_bigint.rb
@@ -0,0 +1,75 @@
+# frozen_string_literal: true
+
+class SwapCiPipelineVariablesPkWithBigint < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'ci_pipeline_variables'
+
+ def up
+ swap
+ end
+
+ def down
+ swap(stepping_down: true)
+ end
+
+ private
+
+ def swap(stepping_down: false)
+ # Prepare the names we need below
+ primary_key_constraint_name = "#{TABLE_NAME}_pkey"
+ sequence_name = "#{TABLE_NAME}_id_seq"
+ bigint_primary_key_index_name = "index_#{TABLE_NAME}_on_id_convert_to_bigint"
+ temp_name = quote_column_name(:id_tmp)
+ id_name = quote_column_name(:id)
+ id_convert_to_bigint_name = quote_column_name(:id_convert_to_bigint)
+ function_name = quote_table_name(
+ Gitlab::Database::UnidirectionalCopyTrigger.on_table(
+ TABLE_NAME, connection: Ci::ApplicationRecord.connection
+ ).name(:id, :id_convert_to_bigint)
+ )
+
+ # 2. Create indexes using the bigint columns that match the existing indexes using the integer column
+ # NOTE: this index is already created in:
+ # - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120946
+ # - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120950
+ # Therefore, this won't have any effect for `up` step, but will be used for `down` step.
+ add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: bigint_primary_key_index_name
+
+ # 4. Inside a transaction, swap the columns
+ # When stepping up, it will swap the bigint column as the primary key and the int column as `bigint`
+ # When stepping down, it will swap the int column as the primary key and the bigint column as `bigint`
+ with_lock_retries(raise_on_exhaustion: true) do
+ # a. Lock the tables involved.
+ execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ # b. Rename the columns to swap names
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_name} TO #{temp_name}"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_convert_to_bigint_name} TO #{id_name}"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{temp_name} TO #{id_convert_to_bigint_name}"
+
+ # c. Reset the trigger function
+ execute "ALTER FUNCTION #{function_name} RESET ALL"
+
+ # d. Swap the defaults
+ execute "ALTER SEQUENCE #{sequence_name} OWNED BY #{TABLE_NAME}.id"
+ change_column_default TABLE_NAME, :id, -> { "nextval('#{sequence_name}'::regclass)" }
+ change_column_default TABLE_NAME, :id_convert_to_bigint, 0
+
+ # e. Swap the PK constraint
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT #{primary_key_constraint_name} CASCADE"
+ rename_index TABLE_NAME, bigint_primary_key_index_name, primary_key_constraint_name
+ execute <<~SQL
+ ALTER TABLE #{TABLE_NAME}
+ ADD CONSTRAINT #{primary_key_constraint_name} PRIMARY KEY
+ USING INDEX #{primary_key_constraint_name}
+ SQL
+ end
+
+ return unless stepping_down
+
+ # For stepping down, we will need to recreate the index after the swap
+ add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: bigint_primary_key_index_name
+ end
+end
diff --git a/db/post_migrate/20230521521419_drop_merge_request_state_id_temp_index.rb b/db/post_migrate/20230521521419_drop_merge_request_state_id_temp_index.rb
new file mode 100644
index 00000000000..3411b374d7e
--- /dev/null
+++ b/db/post_migrate/20230521521419_drop_merge_request_state_id_temp_index.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class DropMergeRequestStateIdTempIndex < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'merge_requests_state_id_temp_index'
+ INDEX_CONDITION = "state_id IN (2, 3)"
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index(:merge_requests, :id, where: INDEX_CONDITION, name: INDEX_NAME)
+ end
+
+ def down
+ add_concurrent_index(:merge_requests, :id, where: INDEX_CONDITION, name: INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20230522073230_add_not_null_constraint_to_personal_access_tokens_expires_at.rb b/db/post_migrate/20230522073230_add_not_null_constraint_to_personal_access_tokens_expires_at.rb
new file mode 100644
index 00000000000..74dddb68d3b
--- /dev/null
+++ b/db/post_migrate/20230522073230_add_not_null_constraint_to_personal_access_tokens_expires_at.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddNotNullConstraintToPersonalAccessTokensExpiresAt < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_not_null_constraint :personal_access_tokens, :expires_at, validate: false
+ end
+
+ def down
+ remove_not_null_constraint :personal_access_tokens, :expires_at
+ end
+end
diff --git a/db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb b/db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb
new file mode 100644
index 00000000000..d351d795ddf
--- /dev/null
+++ b/db/post_migrate/20230522111534_reschedule_migration_for_links_from_metadata.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+# rubocop: disable BackgroundMigration/MissingDictionaryFile
+
+class RescheduleMigrationForLinksFromMetadata < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'MigrateLinksForVulnerabilityFindings'
+ DELAY_INTERVAL = 2.minutes
+ SUB_BATCH_SIZE = 500
+ BATCH_SIZE = 4000
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, [])
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :vulnerability_occurrences,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :vulnerability_occurrences, :id, [])
+ end
+end
+# rubocop: enable BackgroundMigration/MissingDictionaryFile
diff --git a/db/post_migrate/20230522220709_ensure_incident_work_item_type_backfill_is_finished.rb b/db/post_migrate/20230522220709_ensure_incident_work_item_type_backfill_is_finished.rb
new file mode 100644
index 00000000000..a93f5417dd0
--- /dev/null
+++ b/db/post_migrate/20230522220709_ensure_incident_work_item_type_backfill_is_finished.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class EnsureIncidentWorkItemTypeBackfillIsFinished < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'BackfillWorkItemTypeIdForIssues'
+ INCIDENT_ENUM_TYPE = 1
+
+ class MigrationWorkItemType < MigrationRecord
+ self.table_name = 'work_item_types'
+ end
+
+ def up
+ incident_work_item_type = MigrationWorkItemType.find_by(namespace_id: nil, base_type: INCIDENT_ENUM_TYPE)
+
+ if incident_work_item_type.blank?
+ say(
+ 'Incident work item type not found. Make sure the work_item_types table is populated' \
+ 'before running this migration'
+ )
+ return
+ end
+
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :issues,
+ column_name: :id,
+ job_arguments: [INCIDENT_ENUM_TYPE, incident_work_item_type.id]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230522225610_remove_tmp_index_issues_on_issue_type_and_id_only_incidents.rb b/db/post_migrate/20230522225610_remove_tmp_index_issues_on_issue_type_and_id_only_incidents.rb
new file mode 100644
index 00000000000..f6cbff24755
--- /dev/null
+++ b/db/post_migrate/20230522225610_remove_tmp_index_issues_on_issue_type_and_id_only_incidents.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class RemoveTmpIndexIssuesOnIssueTypeAndIdOnlyIncidents < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'tmp_index_issues_on_issue_type_and_id_only_incidents'
+ INCIDENT_ENUM_VALUE = 1
+
+ def up
+ remove_concurrent_index_by_name :issues, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :issues, [:issue_type, :id], name: INDEX_NAME, where: "issue_type = #{INCIDENT_ENUM_VALUE}"
+ end
+end
diff --git a/db/post_migrate/20230523125245_remove_project_ci_cd_setting_opt_in_jwt_column.rb b/db/post_migrate/20230523125245_remove_project_ci_cd_setting_opt_in_jwt_column.rb
new file mode 100644
index 00000000000..2826077d6f0
--- /dev/null
+++ b/db/post_migrate/20230523125245_remove_project_ci_cd_setting_opt_in_jwt_column.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RemoveProjectCiCdSettingOptInJwtColumn < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def up
+ remove_column(:project_ci_cd_settings, :opt_in_jwt)
+ end
+
+ def down
+ add_column(:project_ci_cd_settings, :opt_in_jwt, :boolean, default: false, null: false, if_not_exists: true)
+ end
+end
diff --git a/db/post_migrate/20230523131914_recreate_index_on_vulnerability_reads.rb b/db/post_migrate/20230523131914_recreate_index_on_vulnerability_reads.rb
new file mode 100644
index 00000000000..13f30b5ef6e
--- /dev/null
+++ b/db/post_migrate/20230523131914_recreate_index_on_vulnerability_reads.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class RecreateIndexOnVulnerabilityReads < Gitlab::Database::Migration[2.1]
+ OLD_INDEX_NAME = "index_vulnerability_reads_common_finder_query"
+ NEW_INDEX_NAME = "index_vulnerability_reads_common_finder_query_2"
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(
+ :vulnerability_reads,
+ %i[project_id state report_type severity vulnerability_id dismissal_reason],
+ name: NEW_INDEX_NAME,
+ order: { vulnerability_id: :desc }
+ )
+ remove_concurrent_index_by_name(
+ :vulnerability_reads,
+ OLD_INDEX_NAME
+ )
+ end
+
+ def down
+ add_concurrent_index(
+ :vulnerability_reads,
+ %i[project_id state report_type severity vulnerability_id],
+ name: OLD_INDEX_NAME,
+ order: { vulnerability_id: :desc }
+ )
+ remove_concurrent_index_by_name(
+ :vulnerability_reads,
+ NEW_INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230523132647_recreate_index_on_vulnerability_reads2.rb b/db/post_migrate/20230523132647_recreate_index_on_vulnerability_reads2.rb
new file mode 100644
index 00000000000..0624ad22cf2
--- /dev/null
+++ b/db/post_migrate/20230523132647_recreate_index_on_vulnerability_reads2.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class RecreateIndexOnVulnerabilityReads2 < Gitlab::Database::Migration[2.1]
+ OLD_INDEX_NAME = "index_vulnerability_reads_common_finder_query_with_namespace_id"
+ NEW_INDEX_NAME = "index_vulnerability_reads_common_finder_query_w_namespace_id"
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(
+ :vulnerability_reads,
+ %i[namespace_id state report_type severity vulnerability_id dismissal_reason],
+ name: NEW_INDEX_NAME,
+ order: { vulnerability_id: :desc }
+ )
+ remove_concurrent_index_by_name(
+ :vulnerability_reads,
+ OLD_INDEX_NAME
+ )
+ end
+
+ def down
+ add_concurrent_index(
+ :vulnerability_reads,
+ %i[namespace_id state report_type severity vulnerability_id],
+ name: OLD_INDEX_NAME,
+ order: { vulnerability_id: :desc }
+ )
+ remove_concurrent_index_by_name(
+ :vulnerability_reads,
+ NEW_INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230523210653_remove_file_md5_from_debian_project_component_files.rb b/db/post_migrate/20230523210653_remove_file_md5_from_debian_project_component_files.rb
new file mode 100644
index 00000000000..9ffba2da108
--- /dev/null
+++ b/db/post_migrate/20230523210653_remove_file_md5_from_debian_project_component_files.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class RemoveFileMd5FromDebianProjectComponentFiles < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def change
+ remove_column :packages_debian_project_component_files, :file_md5, :bytea
+ end
+end
diff --git a/db/post_migrate/20230523210758_remove_file_md5_from_debian_group_component_files.rb b/db/post_migrate/20230523210758_remove_file_md5_from_debian_group_component_files.rb
new file mode 100644
index 00000000000..fb9e6da9850
--- /dev/null
+++ b/db/post_migrate/20230523210758_remove_file_md5_from_debian_group_component_files.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class RemoveFileMd5FromDebianGroupComponentFiles < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def change
+ remove_column :packages_debian_group_component_files, :file_md5, :bytea
+ end
+end
diff --git a/db/post_migrate/20230524093249_add_async_index_to_vsa_issues.rb b/db/post_migrate/20230524093249_add_async_index_to_vsa_issues.rb
new file mode 100644
index 00000000000..b11dcae4b84
--- /dev/null
+++ b/db/post_migrate/20230524093249_add_async_index_to_vsa_issues.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class AddAsyncIndexToVsaIssues < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ TABLE_NAME = :analytics_cycle_analytics_issue_stage_events
+ COLUMN_NAMES = %I[stage_event_hash_id group_id end_event_timestamp issue_id]
+ INDEX_NAME = 'index_issue_stage_events_for_consistency_check'
+
+ disable_ddl_transaction!
+
+ def up
+ # The table is hash partitioned
+ each_partition(TABLE_NAME) do |partition, partition_index_name|
+ prepare_async_index(
+ partition.identifier,
+ COLUMN_NAMES,
+ name: partition_index_name
+ )
+ end
+ end
+
+ def down
+ each_partition(TABLE_NAME) do |partition, partition_index_name|
+ unprepare_async_index_by_name(partition.identifier, partition_index_name)
+ end
+ end
+
+ private
+
+ def each_partition(table_name)
+ partitioned_table = find_partitioned_table(table_name)
+ partitioned_table.postgres_partitions.order(:name).each do |partition|
+ partition_index_name = generated_index_name(partition.identifier, INDEX_NAME)
+
+ yield partition, partition_index_name
+ end
+ end
+end
diff --git a/db/post_migrate/20230524093355_add_async_index_to_vsa_mrs.rb b/db/post_migrate/20230524093355_add_async_index_to_vsa_mrs.rb
new file mode 100644
index 00000000000..4104493cb36
--- /dev/null
+++ b/db/post_migrate/20230524093355_add_async_index_to_vsa_mrs.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class AddAsyncIndexToVsaMrs < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ TABLE_NAME = :analytics_cycle_analytics_merge_request_stage_events
+ COLUMN_NAMES = %I[stage_event_hash_id group_id end_event_timestamp merge_request_id]
+ INDEX_NAME = 'index_mr_stage_events_for_consistency_check'
+
+ disable_ddl_transaction!
+
+ def up
+ # The table is hash partitioned
+ each_partition(TABLE_NAME) do |partition, partition_index_name|
+ prepare_async_index(
+ partition.identifier,
+ COLUMN_NAMES,
+ name: partition_index_name
+ )
+ end
+ end
+
+ def down
+ each_partition(TABLE_NAME) do |partition, partition_index_name|
+ unprepare_async_index_by_name(partition.identifier, partition_index_name)
+ end
+ end
+
+ private
+
+ def each_partition(table_name)
+ partitioned_table = find_partitioned_table(table_name)
+ partitioned_table.postgres_partitions.order(:name).each do |partition|
+ partition_index_name = generated_index_name(partition.identifier, INDEX_NAME)
+
+ yield partition, partition_index_name
+ end
+ end
+end
diff --git a/db/post_migrate/20230524120241_add_temp_index_to_packages_on_project_id_when_npm_and_not_pending_destruction.rb b/db/post_migrate/20230524120241_add_temp_index_to_packages_on_project_id_when_npm_and_not_pending_destruction.rb
new file mode 100644
index 00000000000..58a3a26d2eb
--- /dev/null
+++ b/db/post_migrate/20230524120241_add_temp_index_to_packages_on_project_id_when_npm_and_not_pending_destruction.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddTempIndexToPackagesOnProjectIdWhenNpmAndNotPendingDestruction < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'tmp_idx_packages_on_project_id_when_npm_not_pending_destruction'
+ NPM_PACKAGE_TYPE = 2
+ PENDING_DESTRUCTION_STATUS = 4
+
+ def up
+ # Temporary index to be removed in 16.2 https://gitlab.com/gitlab-org/gitlab/-/issues/414216
+ add_concurrent_index(
+ :packages_packages,
+ :project_id,
+ name: INDEX_NAME,
+ where: "package_type = #{NPM_PACKAGE_TYPE} AND status <> #{PENDING_DESTRUCTION_STATUS}"
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name :packages_packages, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230524135543_replace_ci_build_pending_states_foreign_key.rb b/db/post_migrate/20230524135543_replace_ci_build_pending_states_foreign_key.rb
new file mode 100644
index 00000000000..deceb923a48
--- /dev/null
+++ b/db/post_migrate/20230524135543_replace_ci_build_pending_states_foreign_key.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class ReplaceCiBuildPendingStatesForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_build_pending_states, :p_ci_builds,
+ name: 'temp_fk_861cd17da3_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_build_pending_states, name: 'temp_fk_861cd17da3_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_build_pending_states, name: 'temp_fk_861cd17da3_p'
+ remove_foreign_key :ci_build_pending_states, name: 'temp_fk_861cd17da3_p'
+ end
+end
diff --git a/db/post_migrate/20230524135555_replace_ci_build_trace_chunks_foreign_key.rb b/db/post_migrate/20230524135555_replace_ci_build_trace_chunks_foreign_key.rb
new file mode 100644
index 00000000000..d5e4dddd0fc
--- /dev/null
+++ b/db/post_migrate/20230524135555_replace_ci_build_trace_chunks_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiBuildTraceChunksForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_build_trace_chunks, :p_ci_builds,
+ name: 'temp_fk_89e29fa5ee_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_build_trace_chunks,
+ name: 'temp_fk_89e29fa5ee_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_build_trace_chunks, name: 'temp_fk_89e29fa5ee_p'
+ remove_foreign_key :ci_build_trace_chunks, name: 'temp_fk_89e29fa5ee_p'
+ end
+end
diff --git a/db/post_migrate/20230524135607_replace_ci_unit_test_failures_foreign_key.rb b/db/post_migrate/20230524135607_replace_ci_unit_test_failures_foreign_key.rb
new file mode 100644
index 00000000000..5319118b9ef
--- /dev/null
+++ b/db/post_migrate/20230524135607_replace_ci_unit_test_failures_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiUnitTestFailuresForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_unit_test_failures, :p_ci_builds,
+ name: 'temp_fk_9e0fc58930_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_unit_test_failures,
+ name: 'temp_fk_9e0fc58930_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_unit_test_failures, name: 'temp_fk_9e0fc58930_p'
+ remove_foreign_key :ci_unit_test_failures, name: 'temp_fk_9e0fc58930_p'
+ end
+end
diff --git a/db/post_migrate/20230524135620_replace_ci_sources_pipelines_foreign_key.rb b/db/post_migrate/20230524135620_replace_ci_sources_pipelines_foreign_key.rb
new file mode 100644
index 00000000000..b0251de7f00
--- /dev/null
+++ b/db/post_migrate/20230524135620_replace_ci_sources_pipelines_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiSourcesPipelinesForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_sources_pipelines, :p_ci_builds,
+ name: 'temp_fk_be5624bf37_p',
+ column: [:source_partition_id, :source_job_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_sources_pipelines,
+ name: 'temp_fk_be5624bf37_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_sources_pipelines, name: 'temp_fk_be5624bf37_p'
+ remove_foreign_key :ci_sources_pipelines, name: 'temp_fk_be5624bf37_p'
+ end
+end
diff --git a/db/post_migrate/20230524135632_replace_ci_resources_foreign_key.rb b/db/post_migrate/20230524135632_replace_ci_resources_foreign_key.rb
new file mode 100644
index 00000000000..adf99e73fdb
--- /dev/null
+++ b/db/post_migrate/20230524135632_replace_ci_resources_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiResourcesForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_resources, :p_ci_builds,
+ name: 'temp_fk_e169a8e3d5_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :nullify,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_resources,
+ name: 'temp_fk_e169a8e3d5_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_resources, name: 'temp_fk_e169a8e3d5_p'
+ remove_foreign_key :ci_resources, name: 'temp_fk_e169a8e3d5_p'
+ end
+end
diff --git a/db/post_migrate/20230524135645_replace_ci_build_report_results_foreign_key.rb b/db/post_migrate/20230524135645_replace_ci_build_report_results_foreign_key.rb
new file mode 100644
index 00000000000..9e54d1e2885
--- /dev/null
+++ b/db/post_migrate/20230524135645_replace_ci_build_report_results_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiBuildReportResultsForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_build_report_results, :p_ci_builds,
+ name: 'temp_fk_rails_16cb1ff064_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_build_report_results,
+ name: 'temp_fk_rails_16cb1ff064_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_build_report_results, name: 'temp_fk_rails_16cb1ff064_p'
+ remove_foreign_key :ci_build_report_results, name: 'temp_fk_rails_16cb1ff064_p'
+ end
+end
diff --git a/db/post_migrate/20230524135658_replace_ci_build_needs_foreign_key.rb b/db/post_migrate/20230524135658_replace_ci_build_needs_foreign_key.rb
new file mode 100644
index 00000000000..a41bd6d78bf
--- /dev/null
+++ b/db/post_migrate/20230524135658_replace_ci_build_needs_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiBuildNeedsForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_build_needs, :p_ci_builds,
+ name: 'temp_fk_rails_3cf221d4ed_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_build_needs,
+ name: 'temp_fk_rails_3cf221d4ed_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_build_needs, name: 'temp_fk_rails_3cf221d4ed_p'
+ remove_foreign_key :ci_build_needs, name: 'temp_fk_rails_3cf221d4ed_p'
+ end
+end
diff --git a/db/post_migrate/20230524135711_replace_ci_builds_runner_session_foreign_key.rb b/db/post_migrate/20230524135711_replace_ci_builds_runner_session_foreign_key.rb
new file mode 100644
index 00000000000..9ae6a84d28c
--- /dev/null
+++ b/db/post_migrate/20230524135711_replace_ci_builds_runner_session_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiBuildsRunnerSessionForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_builds_runner_session, :p_ci_builds,
+ name: 'temp_fk_rails_70707857d3_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_builds_runner_session,
+ name: 'temp_fk_rails_70707857d3_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_builds_runner_session, name: 'temp_fk_rails_70707857d3_p'
+ remove_foreign_key :ci_builds_runner_session, name: 'temp_fk_rails_70707857d3_p'
+ end
+end
diff --git a/db/post_migrate/20230524135724_replace_ci_pending_builds_foreign_key.rb b/db/post_migrate/20230524135724_replace_ci_pending_builds_foreign_key.rb
new file mode 100644
index 00000000000..6717ea27237
--- /dev/null
+++ b/db/post_migrate/20230524135724_replace_ci_pending_builds_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiPendingBuildsForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_pending_builds, :p_ci_builds,
+ name: 'temp_fk_rails_725a2644a3_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_pending_builds,
+ name: 'temp_fk_rails_725a2644a3_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_pending_builds, name: 'temp_fk_rails_725a2644a3_p'
+ remove_foreign_key :ci_pending_builds, name: 'temp_fk_rails_725a2644a3_p'
+ end
+end
diff --git a/db/post_migrate/20230524135737_replace_ci_build_trace_metadata_foreign_key.rb b/db/post_migrate/20230524135737_replace_ci_build_trace_metadata_foreign_key.rb
new file mode 100644
index 00000000000..abf5700ec98
--- /dev/null
+++ b/db/post_migrate/20230524135737_replace_ci_build_trace_metadata_foreign_key.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ReplaceCiBuildTraceMetadataForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ci_build_trace_metadata, :p_ci_builds,
+ name: 'temp_fk_rails_aebc78111f_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_build_trace_metadata,
+ name: 'temp_fk_rails_aebc78111f_p'
+ end
+
+ def down
+ unprepare_async_foreign_key_validation :ci_build_trace_metadata, name: 'temp_fk_rails_aebc78111f_p'
+ remove_foreign_key :ci_build_trace_metadata, name: 'temp_fk_rails_aebc78111f_p'
+ end
+end
diff --git a/db/post_migrate/20230524135750_replace_ci_job_artifacts_foreign_key.rb b/db/post_migrate/20230524135750_replace_ci_job_artifacts_foreign_key.rb
new file mode 100644
index 00000000000..48c07bceb6a
--- /dev/null
+++ b/db/post_migrate/20230524135750_replace_ci_job_artifacts_foreign_key.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ReplaceCiJobArtifactsForeignKey < Gitlab::Database::Migration[2.1]
+ def up
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+
+ def down
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+end
diff --git a/db/post_migrate/20230524135803_replace_ci_running_builds_foreign_key.rb b/db/post_migrate/20230524135803_replace_ci_running_builds_foreign_key.rb
new file mode 100644
index 00000000000..5d3807242ef
--- /dev/null
+++ b/db/post_migrate/20230524135803_replace_ci_running_builds_foreign_key.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ReplaceCiRunningBuildsForeignKey < Gitlab::Database::Migration[2.1]
+ def up
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+
+ def down
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+end
diff --git a/db/post_migrate/20230524135815_replace_ci_job_variables_foreign_key.rb b/db/post_migrate/20230524135815_replace_ci_job_variables_foreign_key.rb
new file mode 100644
index 00000000000..baac0d495a7
--- /dev/null
+++ b/db/post_migrate/20230524135815_replace_ci_job_variables_foreign_key.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ReplaceCiJobVariablesForeignKey < Gitlab::Database::Migration[2.1]
+ def up
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+
+ def down
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+end
diff --git a/db/post_migrate/20230524135828_replace_p_ci_builds_metadata_foreign_key.rb b/db/post_migrate/20230524135828_replace_p_ci_builds_metadata_foreign_key.rb
new file mode 100644
index 00000000000..c398b457978
--- /dev/null
+++ b/db/post_migrate/20230524135828_replace_p_ci_builds_metadata_foreign_key.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ReplacePCiBuildsMetadataForeignKey < Gitlab::Database::Migration[2.1]
+ def up
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+
+ def down
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+end
diff --git a/db/post_migrate/20230524135840_replace_p_ci_runner_machine_builds_foreign_key.rb b/db/post_migrate/20230524135840_replace_p_ci_runner_machine_builds_foreign_key.rb
new file mode 100644
index 00000000000..bc9d534ec1f
--- /dev/null
+++ b/db/post_migrate/20230524135840_replace_p_ci_runner_machine_builds_foreign_key.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ReplacePCiRunnerMachineBuildsForeignKey < Gitlab::Database::Migration[2.1]
+ def up
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+
+ def down
+ # This migration was skipped in the ci database on gitlab.com as part of
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/14888
+ end
+end
diff --git a/db/post_migrate/20230524150232_remove_index_user_details_on_user_id_for_enterprise_users_without_date.rb b/db/post_migrate/20230524150232_remove_index_user_details_on_user_id_for_enterprise_users_without_date.rb
new file mode 100644
index 00000000000..d1c56af1721
--- /dev/null
+++ b/db/post_migrate/20230524150232_remove_index_user_details_on_user_id_for_enterprise_users_without_date.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class RemoveIndexUserDetailsOnUserIdForEnterpriseUsersWithoutDate < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_user_details_on_user_id_for_enterprise_users_without_date'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :user_details, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index(
+ :user_details, :user_id,
+ where: 'provisioned_by_group_id IS NOT NULL AND provisioned_by_group_at IS NULL',
+ name: INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230524150438_remove_index_user_details_on_user_id_for_enterprise_users_with_date.rb b/db/post_migrate/20230524150438_remove_index_user_details_on_user_id_for_enterprise_users_with_date.rb
new file mode 100644
index 00000000000..350c72ce20b
--- /dev/null
+++ b/db/post_migrate/20230524150438_remove_index_user_details_on_user_id_for_enterprise_users_with_date.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class RemoveIndexUserDetailsOnUserIdForEnterpriseUsersWithDate < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_user_details_on_user_id_for_enterprise_users_with_date'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :user_details, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index(
+ :user_details, :user_id,
+ where: 'provisioned_by_group_id IS NOT NULL AND provisioned_by_group_at IS NOT NULL',
+ name: INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230524201454_queue_mark_duplicate_npm_packages_for_destruction.rb b/db/post_migrate/20230524201454_queue_mark_duplicate_npm_packages_for_destruction.rb
new file mode 100644
index 00000000000..7460d93fd49
--- /dev/null
+++ b/db/post_migrate/20230524201454_queue_mark_duplicate_npm_packages_for_destruction.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class QueueMarkDuplicateNpmPackagesForDestruction < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'MarkDuplicateNpmPackagesForDestruction'
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 5000
+ BATCH_CLASS_NAME = 'LooseIndexScanBatchingStrategy'
+ SUB_BATCH_SIZE = 500
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :packages_packages,
+ :project_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ batch_class_name: BATCH_CLASS_NAME,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :packages_packages, :project_id, [])
+ end
+end
diff --git a/db/post_migrate/20230525180605_add_index_work_item_types_on_base_type_id.rb b/db/post_migrate/20230525180605_add_index_work_item_types_on_base_type_id.rb
new file mode 100644
index 00000000000..620153f2a7b
--- /dev/null
+++ b/db/post_migrate/20230525180605_add_index_work_item_types_on_base_type_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexWorkItemTypesOnBaseTypeId < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_work_item_types_on_base_type_and_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :work_item_types, [:base_type, :id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :work_item_types, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230529183648_remove_temporary_billable_index.rb b/db/post_migrate/20230529183648_remove_temporary_billable_index.rb
new file mode 100644
index 00000000000..88940aad968
--- /dev/null
+++ b/db/post_migrate/20230529183648_remove_temporary_billable_index.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveTemporaryBillableIndex < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'migrate_index_users_for_active_billable_users'
+ def up
+ remove_concurrent_index_by_name :users, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :users, :id,
+ name: INDEX_NAME,
+ where: "((state)::text = 'active'::text) " \
+ "AND (user_type IS NULL OR user_type = 0 OR user_type = ANY (ARRAY[0, 6, 4, 13])) " \
+ "AND (user_type IS NULL OR user_type = 0 OR user_type = ANY (ARRAY[0, 4, 5]))"
+ end
+end
diff --git a/db/post_migrate/20230529185110_cleanup_temporary_activity_index.rb b/db/post_migrate/20230529185110_cleanup_temporary_activity_index.rb
new file mode 100644
index 00000000000..d3e75aa7975
--- /dev/null
+++ b/db/post_migrate/20230529185110_cleanup_temporary_activity_index.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class CleanupTemporaryActivityIndex < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'i_users_on_last_activity_for_active_human_service_migration'
+
+ def up
+ remove_concurrent_index_by_name :users, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :users, [:id, :last_activity_on],
+ name: INDEX_NAME,
+ where: "state = 'active' AND ((user_type IS NULL) OR (user_type = 0) OR (user_type = 4))"
+ end
+end
diff --git a/db/post_migrate/20230530003634_cleanup_tofa_settings.rb b/db/post_migrate/20230530003634_cleanup_tofa_settings.rb
new file mode 100644
index 00000000000..0e580a52bfd
--- /dev/null
+++ b/db/post_migrate/20230530003634_cleanup_tofa_settings.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class CleanupTofaSettings < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ cleanup_concurrent_column_rename :application_settings, :encrypted_tofa_credentials,
+ :encrypted_vertex_ai_credentials
+ cleanup_concurrent_column_rename :application_settings, :encrypted_tofa_credentials_iv,
+ :encrypted_vertex_ai_credentials_iv
+ cleanup_concurrent_column_rename :application_settings, :vertex_project,
+ :vertex_ai_project
+ end
+
+ def down
+ undo_cleanup_concurrent_column_rename :application_settings, :encrypted_tofa_credentials,
+ :encrypted_vertex_ai_credentials
+ undo_cleanup_concurrent_column_rename :application_settings, :encrypted_tofa_credentials_iv,
+ :encrypted_vertex_ai_credentials_iv
+ undo_cleanup_concurrent_column_rename :application_settings, :vertex_project,
+ :vertex_ai_project
+ end
+end
diff --git a/db/post_migrate/20230530015535_swap_notes_id_to_bigint_for_gitlab_dot_com.rb b/db/post_migrate/20230530015535_swap_notes_id_to_bigint_for_gitlab_dot_com.rb
new file mode 100644
index 00000000000..2dfeb80aba7
--- /dev/null
+++ b/db/post_migrate/20230530015535_swap_notes_id_to_bigint_for_gitlab_dot_com.rb
@@ -0,0 +1,195 @@
+# frozen_string_literal: true
+
+class SwapNotesIdToBigintForGitlabDotCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'notes'
+ PK_INDEX_NAME = 'index_notes_on_id_convert_to_bigint'
+
+ SECONDARY_INDEXES = [
+ {
+ original_name: :index_notes_on_author_id_and_created_at_and_id,
+ temporary_name: :index_notes_on_author_id_created_at_id_convert_to_bigint,
+ columns: [:author_id, :created_at, :id_convert_to_bigint],
+ options: {}
+ },
+ {
+ original_name: :index_notes_on_id_where_confidential,
+ temporary_name: :index_notes_on_id_convert_to_bigint_where_confidential,
+ columns: [:id_convert_to_bigint],
+ options: { where: 'confidential = true' }
+ },
+ {
+ original_name: :index_notes_on_id_where_internal,
+ temporary_name: :index_notes_on_id_convert_to_bigint_where_internal,
+ columns: [:id_convert_to_bigint],
+ options: { where: 'internal = true' }
+ },
+ {
+ original_name: :index_notes_on_project_id_and_id_and_system_false,
+ temporary_name: :index_notes_on_project_id_id_convert_to_bigint_system_false,
+ columns: [:project_id, :id_convert_to_bigint],
+ options: { where: 'NOT system' }
+ },
+ {
+ original_name: :note_mentions_temp_index,
+ temporary_name: :note_mentions_temp_index_convert_to_bigint,
+ columns: [:id_convert_to_bigint, :noteable_type],
+ options: { where: "note ~~ '%@%'::text" }
+ }
+ ]
+
+ REFERENCING_FOREIGN_KEYS = [
+ [:todos, :fk_91d1f47b13, :note_id, :cascade],
+ [:incident_management_timeline_events, :fk_d606a2a890, :promoted_from_note_id, :nullify],
+ [:system_note_metadata, :fk_d83a918cb1, :note_id, :cascade],
+ [:diff_note_positions, :fk_rails_13c7212859, :note_id, :cascade],
+ [:epic_user_mentions, :fk_rails_1c65976a49, :note_id, :cascade],
+ [:suggestions, :fk_rails_33b03a535c, :note_id, :cascade],
+ [:issue_user_mentions, :fk_rails_3861d9fefa, :note_id, :cascade],
+ [:note_diff_files, :fk_rails_3d66047aeb, :diff_note_id, :cascade],
+ [:snippet_user_mentions, :fk_rails_4d3f96b2cb, :note_id, :cascade],
+ [:design_user_mentions, :fk_rails_8de8c6d632, :note_id, :cascade],
+ [:vulnerability_user_mentions, :fk_rails_a18600f210, :note_id, :cascade],
+ [:commit_user_mentions, :fk_rails_a6760813e0, :note_id, :cascade],
+ [:merge_request_user_mentions, :fk_rails_c440b9ea31, :note_id, :cascade],
+ [:note_metadata, :fk_rails_d853224d37, :note_id, :cascade],
+ [:alert_management_alert_user_mentions, :fk_rails_eb2de0cdef, :note_id, :cascade],
+ [:timelogs, :fk_timelogs_note_id, :note_id, :nullify]
+ ]
+
+ def up
+ return unless should_run?
+
+ swap
+ end
+
+ def down
+ return unless should_run?
+
+ swap
+
+ add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: PK_INDEX_NAME
+
+ REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, on_delete)|
+ temporary_name = "#{name}_tmp"
+
+ add_concurrent_foreign_key(
+ from_table,
+ TABLE_NAME,
+ column: column,
+ target_column: :id_convert_to_bigint,
+ name: temporary_name,
+ on_delete: on_delete,
+ reverse_lock_order: true,
+ validate: false)
+ end
+ end
+
+ def swap
+ # Copy existing indexes from the original column to the new column
+ create_indexes
+
+ # Copy existing FKs from the original column to the new column
+ create_referencing_foreign_keys
+
+ # Remove existing FKs from the referencing tables, so we don't have to lock on them when we drop the existing PK
+ replace_referencing_foreign_keys
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ # Swap the original and new column names
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN id TO id_tmp"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN id_convert_to_bigint TO id"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN id_tmp TO id_convert_to_bigint"
+
+ # Reset the function so PG drops the plan cache for the incorrect integer type
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger
+ .on_table(TABLE_NAME, connection: connection)
+ .name(:id, :id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ # Swap defaults of the two columns, and change ownership of the sequence to the new id
+ execute "ALTER SEQUENCE notes_id_seq OWNED BY #{TABLE_NAME}.id"
+ change_column_default TABLE_NAME, :id, -> { "nextval('notes_id_seq'::regclass)" }
+ change_column_default TABLE_NAME, :id_convert_to_bigint, 0
+
+ # Swap the PK constraint from the original column to the new column.
+ # We deliberately don't CASCADE here because the old FKs should be removed already
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT notes_pkey"
+ rename_index TABLE_NAME, PK_INDEX_NAME, 'notes_pkey'
+ execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT notes_pkey PRIMARY KEY USING INDEX notes_pkey"
+
+ # Remove old column indexes and change new column indexes to have the original names
+ rename_secondary_indexes # rubocop:disable Migration/WithLockRetriesDisallowedMethod
+ end
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+
+ def create_indexes
+ add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: PK_INDEX_NAME
+
+ SECONDARY_INDEXES.each do |index_definition|
+ options = index_definition[:options]
+ options[:name] = index_definition[:temporary_name]
+
+ add_concurrent_index(TABLE_NAME, index_definition[:columns], options)
+ end
+ end
+
+ def rename_secondary_indexes
+ SECONDARY_INDEXES.each do |index_definition|
+ remove_index(TABLE_NAME, name: index_definition[:original_name], if_exists: true) # rubocop:disable Migration/RemoveIndex
+ rename_index(TABLE_NAME, index_definition[:temporary_name], index_definition[:original_name])
+ end
+ end
+
+ def create_referencing_foreign_keys
+ REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, on_delete)|
+ # Don't attempt to create the FK if one already exists from the table to the new column
+ # The check in `add_concurrent_foreign_key` already checks for this, but it looks for the foreign key
+ # with the new name only (containing the `_tmp` suffix).
+ #
+ # Since we might partially rename FKs and re-run the migration, we also have to check and see if a FK exists
+ # on those columns that might not match the `_tmp` name.
+ next if foreign_key_exists?(
+ from_table, TABLE_NAME, column: column,
+ primary_key: :id_convert_to_bigint, name: name)
+
+ temporary_name = "#{name}_tmp"
+
+ add_concurrent_foreign_key(
+ from_table,
+ TABLE_NAME,
+ column: column,
+ target_column: :id_convert_to_bigint,
+ name: temporary_name,
+ on_delete: on_delete,
+ reverse_lock_order: true)
+ end
+ end
+
+ def replace_referencing_foreign_keys
+ REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, _)|
+ # Don't attempt to replace the FK unless it exists and points at the original column.
+ # This could happen if the migration is re-run due to failing midway.
+ next unless foreign_key_exists?(from_table, TABLE_NAME, column: column, primary_key: :id, name: name)
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ temporary_name = "#{name}_tmp"
+
+ # Explicitly lock table in order of parent, child to attempt to avoid deadlocks
+ execute "LOCK TABLE #{TABLE_NAME}, #{from_table} IN ACCESS EXCLUSIVE MODE"
+
+ remove_foreign_key(from_table, TABLE_NAME, column: column, primary_key: :id, name: name)
+ rename_constraint(from_table, temporary_name, name)
+ end
+ end
+ end
+end
diff --git a/db/post_migrate/20230530100400_change_user_type_null.rb b/db/post_migrate/20230530100400_change_user_type_null.rb
new file mode 100644
index 00000000000..a74e8c3a774
--- /dev/null
+++ b/db/post_migrate/20230530100400_change_user_type_null.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ChangeUserTypeNull < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ add_not_null_constraint :users, :user_type, validate: false
+ end
+
+ def down
+ remove_not_null_constraint :users, :user_type
+ end
+end
diff --git a/db/post_migrate/20230530114845_cleanup_organizations_with_null_path.rb b/db/post_migrate/20230530114845_cleanup_organizations_with_null_path.rb
new file mode 100644
index 00000000000..6d04bf6e4ec
--- /dev/null
+++ b/db/post_migrate/20230530114845_cleanup_organizations_with_null_path.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class CleanupOrganizationsWithNullPath < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ module Organizations
+ class Organization < Gitlab::Database::Migration[2.1]::MigrationRecord
+ end
+ end
+
+ def up
+ Organizations::Organization.update_all("path = lower(name)")
+ end
+
+ def down
+ Organizations::Organization.update_all(path: '')
+ end
+end
diff --git a/db/post_migrate/20230530115830_remove_default_on_organization_path.rb b/db/post_migrate/20230530115830_remove_default_on_organization_path.rb
new file mode 100644
index 00000000000..82c71d5fef3
--- /dev/null
+++ b/db/post_migrate/20230530115830_remove_default_on_organization_path.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class RemoveDefaultOnOrganizationPath < Gitlab::Database::Migration[2.1]
+ def up
+ change_column_default :organizations, :path, nil
+ end
+
+ def down
+ change_column_default :organizations, :path, ''
+ end
+end
diff --git a/db/post_migrate/20230530140456_validate_fk_ci_build_pending_states_p_ci_builds.rb b/db/post_migrate/20230530140456_validate_fk_ci_build_pending_states_p_ci_builds.rb
new file mode 100644
index 00000000000..6104731152d
--- /dev/null
+++ b/db/post_migrate/20230530140456_validate_fk_ci_build_pending_states_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiBuildPendingStatesPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_build_pending_states, nil, name: :temp_fk_861cd17da3_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140509_validate_fk_ci_build_trace_chunks_p_ci_builds.rb b/db/post_migrate/20230530140509_validate_fk_ci_build_trace_chunks_p_ci_builds.rb
new file mode 100644
index 00000000000..40cef0428cf
--- /dev/null
+++ b/db/post_migrate/20230530140509_validate_fk_ci_build_trace_chunks_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiBuildTraceChunksPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_build_trace_chunks, nil, name: :temp_fk_89e29fa5ee_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140521_validate_fk_ci_unit_test_failures_p_ci_builds.rb b/db/post_migrate/20230530140521_validate_fk_ci_unit_test_failures_p_ci_builds.rb
new file mode 100644
index 00000000000..948d9a837a5
--- /dev/null
+++ b/db/post_migrate/20230530140521_validate_fk_ci_unit_test_failures_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiUnitTestFailuresPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_unit_test_failures, nil, name: :temp_fk_9e0fc58930_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140534_validate_fk_ci_sources_pipelines_p_ci_builds.rb b/db/post_migrate/20230530140534_validate_fk_ci_sources_pipelines_p_ci_builds.rb
new file mode 100644
index 00000000000..7e92026f21f
--- /dev/null
+++ b/db/post_migrate/20230530140534_validate_fk_ci_sources_pipelines_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiSourcesPipelinesPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_sources_pipelines, nil, name: :temp_fk_be5624bf37_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140546_validate_fk_ci_resources_p_ci_builds.rb b/db/post_migrate/20230530140546_validate_fk_ci_resources_p_ci_builds.rb
new file mode 100644
index 00000000000..7cb58aed2ed
--- /dev/null
+++ b/db/post_migrate/20230530140546_validate_fk_ci_resources_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiResourcesPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_resources, nil, name: :temp_fk_e169a8e3d5_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140558_validate_fk_ci_build_report_results_p_ci_builds.rb b/db/post_migrate/20230530140558_validate_fk_ci_build_report_results_p_ci_builds.rb
new file mode 100644
index 00000000000..f5188ab6bfe
--- /dev/null
+++ b/db/post_migrate/20230530140558_validate_fk_ci_build_report_results_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiBuildReportResultsPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_build_report_results, nil, name: :temp_fk_rails_16cb1ff064_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140611_validate_fk_ci_build_needs_p_ci_builds.rb b/db/post_migrate/20230530140611_validate_fk_ci_build_needs_p_ci_builds.rb
new file mode 100644
index 00000000000..6988e1027e5
--- /dev/null
+++ b/db/post_migrate/20230530140611_validate_fk_ci_build_needs_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiBuildNeedsPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_build_needs, nil, name: :temp_fk_rails_3cf221d4ed_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140623_validate_fk_ci_builds_runner_session_p_ci_builds.rb b/db/post_migrate/20230530140623_validate_fk_ci_builds_runner_session_p_ci_builds.rb
new file mode 100644
index 00000000000..892df3ae00b
--- /dev/null
+++ b/db/post_migrate/20230530140623_validate_fk_ci_builds_runner_session_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiBuildsRunnerSessionPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_builds_runner_session, nil, name: :temp_fk_rails_70707857d3_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140634_validate_fk_ci_pending_builds_p_ci_builds.rb b/db/post_migrate/20230530140634_validate_fk_ci_pending_builds_p_ci_builds.rb
new file mode 100644
index 00000000000..8f6113aea31
--- /dev/null
+++ b/db/post_migrate/20230530140634_validate_fk_ci_pending_builds_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiPendingBuildsPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_pending_builds, nil, name: :temp_fk_rails_725a2644a3_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230530140646_validate_fk_ci_build_trace_metadata_p_ci_builds.rb b/db/post_migrate/20230530140646_validate_fk_ci_build_trace_metadata_p_ci_builds.rb
new file mode 100644
index 00000000000..00c015321ba
--- /dev/null
+++ b/db/post_migrate/20230530140646_validate_fk_ci_build_trace_metadata_p_ci_builds.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ValidateFkCiBuildTraceMetadataPCiBuilds < Gitlab::Database::Migration[2.1]
+ def up
+ validate_foreign_key :ci_build_trace_metadata, nil, name: :temp_fk_rails_aebc78111f_p
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20220315181125_remove_issues_work_item_type_id_index.rb b/db/post_migrate/20230531165731_drop_index_issues_on_work_item_type_id.rb
index 6650201c063..d200aecea65 100644
--- a/db/post_migrate/20220315181125_remove_issues_work_item_type_id_index.rb
+++ b/db/post_migrate/20230531165731_drop_index_issues_on_work_item_type_id.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
-class RemoveIssuesWorkItemTypeIdIndex < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
+class DropIndexIssuesOnWorkItemTypeId < Gitlab::Database::Migration[2.1]
INDEX_NAME = 'index_issues_on_work_item_type_id'
+ disable_ddl_transaction!
+
def up
- remove_concurrent_index_by_name :issues, name: INDEX_NAME
+ remove_concurrent_index_by_name :issues, INDEX_NAME
end
def down
diff --git a/db/post_migrate/20230601184234_drop_unnecessary_async_index_from_events.rb b/db/post_migrate/20230601184234_drop_unnecessary_async_index_from_events.rb
new file mode 100644
index 00000000000..f3ce879c70e
--- /dev/null
+++ b/db/post_migrate/20230601184234_drop_unnecessary_async_index_from_events.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class DropUnnecessaryAsyncIndexFromEvents < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_on_events_to_improve_contribution_analytics_performance'
+
+ def up
+ prepare_async_index_removal :events, %i[project_id target_type action created_at author_id id], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :events, %i[project_id target_type action created_at author_id id], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230602063059_remove_broadcast_messages_namespace_id_column.rb b/db/post_migrate/20230602063059_remove_broadcast_messages_namespace_id_column.rb
new file mode 100644
index 00000000000..144b16e4806
--- /dev/null
+++ b/db/post_migrate/20230602063059_remove_broadcast_messages_namespace_id_column.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveBroadcastMessagesNamespaceIdColumn < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_broadcast_messages_on_namespace_id'
+
+ def up
+ remove_column :broadcast_messages, :namespace_id
+ end
+
+ def down
+ add_column :broadcast_messages, :namespace_id, :bigint unless column_exists?(:broadcast_messages, :namespace_id)
+
+ add_concurrent_index :broadcast_messages, :namespace_id, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230602112904_change_user_preferences_defaults.rb b/db/post_migrate/20230602112904_change_user_preferences_defaults.rb
new file mode 100644
index 00000000000..98d93979039
--- /dev/null
+++ b/db/post_migrate/20230602112904_change_user_preferences_defaults.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class ChangeUserPreferencesDefaults < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def change
+ change_column_default(:user_preferences, :tab_width, from: nil, to: 8)
+ change_column_default(:user_preferences, :time_display_relative, from: nil, to: true)
+ change_column_default(:user_preferences, :render_whitespace_in_code, from: nil, to: false)
+ end
+end
diff --git a/db/post_migrate/20230602131429_change_notified_of_own_activity_default.rb b/db/post_migrate/20230602131429_change_notified_of_own_activity_default.rb
new file mode 100644
index 00000000000..d564ad9ab4c
--- /dev/null
+++ b/db/post_migrate/20230602131429_change_notified_of_own_activity_default.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class ChangeNotifiedOfOwnActivityDefault < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def change
+ change_column_default(:users, :notified_of_own_activity, from: nil, to: false)
+ end
+end
diff --git a/db/post_migrate/20230605085936_add_new_index_to_vsa_issue_stage_events.rb b/db/post_migrate/20230605085936_add_new_index_to_vsa_issue_stage_events.rb
new file mode 100644
index 00000000000..75f28f35fe2
--- /dev/null
+++ b/db/post_migrate/20230605085936_add_new_index_to_vsa_issue_stage_events.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddNewIndexToVsaIssueStageEvents < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ TABLE_NAME = :analytics_cycle_analytics_issue_stage_events
+ COLUMN_NAMES = %I[stage_event_hash_id group_id end_event_timestamp issue_id].freeze
+ INDEX_NAME = 'index_issue_stage_events_for_consistency_check'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_partitioned_index TABLE_NAME, COLUMN_NAMES, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_partitioned_index_by_name TABLE_NAME, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230605085957_add_new_index_to_vsa_mr_stage_events.rb b/db/post_migrate/20230605085957_add_new_index_to_vsa_mr_stage_events.rb
new file mode 100644
index 00000000000..b4ed38519c5
--- /dev/null
+++ b/db/post_migrate/20230605085957_add_new_index_to_vsa_mr_stage_events.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddNewIndexToVsaMrStageEvents < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ TABLE_NAME = :analytics_cycle_analytics_merge_request_stage_events
+ COLUMN_NAMES = %I[stage_event_hash_id group_id end_event_timestamp merge_request_id]
+ INDEX_NAME = 'index_mr_stage_events_for_consistency_check'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_partitioned_index TABLE_NAME, COLUMN_NAMES, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_partitioned_index_by_name TABLE_NAME, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230605093005_add_index_for_sbom_occurrences_on_project_id_source_id.rb b/db/post_migrate/20230605093005_add_index_for_sbom_occurrences_on_project_id_source_id.rb
new file mode 100644
index 00000000000..868cf276354
--- /dev/null
+++ b/db/post_migrate/20230605093005_add_index_for_sbom_occurrences_on_project_id_source_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexForSbomOccurrencesOnProjectIdSourceId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'idx_sbom_occurrences_on_project_id_and_source_id'
+
+ def up
+ add_concurrent_index :sbom_occurrences, [:project_id, :source_id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :sbom_occurrences, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230605192000_drop_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb b/db/post_migrate/20230605192000_drop_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb
new file mode 100644
index 00000000000..c74df0a5cdd
--- /dev/null
+++ b/db/post_migrate/20230605192000_drop_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class DropTmpIndexOauthAccessTokensOnIdWhereExpiresInNull < Gitlab::Database::Migration[2.1]
+ TMP_INDEX = 'tmp_index_oauth_access_tokens_on_id_where_expires_in_null'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :oauth_access_tokens, TMP_INDEX
+ end
+
+ def down
+ add_concurrent_index :oauth_access_tokens, :id, where: "expires_in IS NULL", name: TMP_INDEX
+ end
+end
diff --git a/db/post_migrate/20230606183327_add_index_user_details_on_enterprise_group_id.rb b/db/post_migrate/20230606183327_add_index_user_details_on_enterprise_group_id.rb
new file mode 100644
index 00000000000..d3b53867b4f
--- /dev/null
+++ b/db/post_migrate/20230606183327_add_index_user_details_on_enterprise_group_id.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddIndexUserDetailsOnEnterpriseGroupId < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_user_details_on_enterprise_group_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :user_details, :enterprise_group_id, name: INDEX_NAME
+
+ add_concurrent_foreign_key :user_details, :namespaces, column: :enterprise_group_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :user_details, column: :enterprise_group_id
+ end
+
+ remove_concurrent_index_by_name :user_details, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230606193037_create_index_alert_management_alerts_on_created_at_project_id_with_issue.rb b/db/post_migrate/20230606193037_create_index_alert_management_alerts_on_created_at_project_id_with_issue.rb
new file mode 100644
index 00000000000..3038193e949
--- /dev/null
+++ b/db/post_migrate/20230606193037_create_index_alert_management_alerts_on_created_at_project_id_with_issue.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class CreateIndexAlertManagementAlertsOnCreatedAtProjectIdWithIssue < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'idx_alert_management_alerts_on_created_at_project_id_with_issue'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :alert_management_alerts, [:created_at, :project_id],
+ where: 'issue_id IS NOT NULL',
+ name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :alert_management_alerts, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230607093222_remove_webauthn_registrations_u2f_registration_id_column.rb b/db/post_migrate/20230607093222_remove_webauthn_registrations_u2f_registration_id_column.rb
new file mode 100644
index 00000000000..6e861fc258a
--- /dev/null
+++ b/db/post_migrate/20230607093222_remove_webauthn_registrations_u2f_registration_id_column.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class RemoveWebauthnRegistrationsU2fRegistrationIdColumn < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_webauthn_registrations_on_u2f_registration_id'
+
+ def up
+ remove_column :webauthn_registrations, :u2f_registration_id
+ end
+
+ def down
+ add_column :webauthn_registrations, :u2f_registration_id, :integer
+
+ add_concurrent_index(
+ :webauthn_registrations,
+ :u2f_registration_id,
+ name: INDEX_NAME,
+ where: 'u2f_registration_id IS NOT NULL')
+ end
+end
diff --git a/db/post_migrate/20230607165632_remove_fk_on_project_id_on_project_wiki_repository_states.rb b/db/post_migrate/20230607165632_remove_fk_on_project_id_on_project_wiki_repository_states.rb
new file mode 100644
index 00000000000..a70cc3aeab6
--- /dev/null
+++ b/db/post_migrate/20230607165632_remove_fk_on_project_id_on_project_wiki_repository_states.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class RemoveFkOnProjectIdOnProjectWikiRepositoryStates < Gitlab::Database::Migration[2.1]
+ SOURCE_TABLE_NAME = :project_wiki_repository_states
+ TARGET_TABLE_NAME = :projects
+ FK_NAME = :fk_rails_9647227ce1
+
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(SOURCE_TABLE_NAME, TARGET_TABLE_NAME, name: FK_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(SOURCE_TABLE_NAME, TARGET_TABLE_NAME,
+ column: :project_id, name: FK_NAME, on_delete: :cascade)
+ end
+end
diff --git a/db/post_migrate/20230607165718_drop_project_wiki_repository_states.rb b/db/post_migrate/20230607165718_drop_project_wiki_repository_states.rb
new file mode 100644
index 00000000000..3ae92ca2dc1
--- /dev/null
+++ b/db/post_migrate/20230607165718_drop_project_wiki_repository_states.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+class DropProjectWikiRepositoryStates < Gitlab::Database::Migration[2.1]
+ VERIFICATION_STATE_INDEX_NAME = "index_project_wiki_repository_states_on_verification_state"
+ PENDING_VERIFICATION_INDEX_NAME = "index_project_wiki_repository_states_pending_verification"
+ FAILED_VERIFICATION_INDEX_NAME = "index_project_wiki_repository_states_failed_verification"
+ NEEDS_VERIFICATION_INDEX_NAME = "index_project_wiki_repository_states_needs_verification"
+ PROJECT_WIKI_REPOSITORY_INDEX_NAME = "idx_project_wiki_repository_states_project_wiki_repository_id"
+
+ disable_ddl_transaction!
+
+ def up
+ drop_table :project_wiki_repository_states, if_exists: true
+ end
+
+ def down
+ unless table_exists?(:project_wiki_repository_states)
+ create_table :project_wiki_repository_states, id: false do |t| # rubocop:disable Migration/SchemaAdditionMethodsNoPost
+ t.datetime_with_timezone :verification_started_at
+ t.datetime_with_timezone :verification_retry_at
+ t.datetime_with_timezone :verified_at
+ t.bigint :project_id, primary_key: true, index: false
+ t.integer :verification_state, default: 0, limit: 2, null: false
+ t.integer :verification_retry_count, limit: 2
+ t.binary :verification_checksum, using: 'verification_checksum::bytea'
+ t.text :verification_failure, limit: 255
+ t.bigint :project_wiki_repository_id
+
+ t.index :verification_state,
+ name: VERIFICATION_STATE_INDEX_NAME
+
+ t.index :verified_at,
+ where: "(verification_state = 0)",
+ order: { verified_at: 'ASC NULLS FIRST' },
+ name: PENDING_VERIFICATION_INDEX_NAME
+
+ t.index :verification_retry_at,
+ where: "(verification_state = 3)",
+ order: { verification_retry_at: 'ASC NULLS FIRST' },
+ name: FAILED_VERIFICATION_INDEX_NAME
+
+ t.index :verification_state,
+ where: "(verification_state = 0 OR verification_state = 3)",
+ name: NEEDS_VERIFICATION_INDEX_NAME
+ end
+ end
+
+ add_concurrent_index :project_wiki_repository_states,
+ :project_wiki_repository_id,
+ name: PROJECT_WIKI_REPOSITORY_INDEX_NAME
+
+ add_concurrent_foreign_key :project_wiki_repository_states,
+ :project_wiki_repositories,
+ column: :project_wiki_repository_id,
+ on_delete: :cascade
+ end
+end
diff --git a/db/post_migrate/20230608071301_requeue_cleanup_personal_access_tokens_with_nil_expires_at.rb b/db/post_migrate/20230608071301_requeue_cleanup_personal_access_tokens_with_nil_expires_at.rb
new file mode 100644
index 00000000000..ec8cacc34ab
--- /dev/null
+++ b/db/post_migrate/20230608071301_requeue_cleanup_personal_access_tokens_with_nil_expires_at.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class RequeueCleanupPersonalAccessTokensWithNilExpiresAt < Gitlab::Database::Migration[2.1]
+ MIGRATION = "CleanupPersonalAccessTokensWithNilExpiresAt"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 50_000
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ delete_batched_background_migration(MIGRATION, :personal_access_tokens, :id, [])
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :personal_access_tokens,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :personal_access_tokens, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230608081257_delete_index_members_on_source_id_and_source_type.rb b/db/post_migrate/20230608081257_delete_index_members_on_source_id_and_source_type.rb
new file mode 100644
index 00000000000..5018d361841
--- /dev/null
+++ b/db/post_migrate/20230608081257_delete_index_members_on_source_id_and_source_type.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DeleteIndexMembersOnSourceIdAndSourceType < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_members_on_source_id_and_source_type'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :members, name: INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :members, %i[source_id source_type], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230608081924_delete_index_unique_project_authorizations_on_project_id_user_id.rb b/db/post_migrate/20230608081924_delete_index_unique_project_authorizations_on_project_id_user_id.rb
new file mode 100644
index 00000000000..722f58b836a
--- /dev/null
+++ b/db/post_migrate/20230608081924_delete_index_unique_project_authorizations_on_project_id_user_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DeleteIndexUniqueProjectAuthorizationsOnProjectIdUserId < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_unique_project_authorizations_on_project_id_user_id'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :project_authorizations, name: INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :project_authorizations, %i[project_id user_id], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230608101503_add_ci_job_annotations_foreign_key.rb b/db/post_migrate/20230608101503_add_ci_job_annotations_foreign_key.rb
new file mode 100644
index 00000000000..b4548ed8c28
--- /dev/null
+++ b/db/post_migrate/20230608101503_add_ci_job_annotations_foreign_key.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddCiJobAnnotationsForeignKey < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_partitioned_foreign_key(
+ :p_ci_job_annotations, :p_ci_builds,
+ column: [:partition_id, :job_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ reverse_lock_order: true
+ )
+ end
+
+ def down
+ remove_foreign_key_if_exists :p_ci_job_annotations, :p_ci_builds
+ end
+end
diff --git a/db/post_migrate/20230608231452_cleanup_bigint_conversion_for_todos_for_gitlab_com.rb b/db/post_migrate/20230608231452_cleanup_bigint_conversion_for_todos_for_gitlab_com.rb
new file mode 100644
index 00000000000..281b5f926fa
--- /dev/null
+++ b/db/post_migrate/20230608231452_cleanup_bigint_conversion_for_todos_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForTodosForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :todos
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230608232452_cleanup_bigint_conversion_for_system_note_metadata_for_gitlab_com.rb b/db/post_migrate/20230608232452_cleanup_bigint_conversion_for_system_note_metadata_for_gitlab_com.rb
new file mode 100644
index 00000000000..e52dd3e5da8
--- /dev/null
+++ b/db/post_migrate/20230608232452_cleanup_bigint_conversion_for_system_note_metadata_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForSystemNoteMetadataForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :system_note_metadata
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230608233452_cleanup_bigint_conversion_for_epic_user_mentions_for_gitlab_com.rb b/db/post_migrate/20230608233452_cleanup_bigint_conversion_for_epic_user_mentions_for_gitlab_com.rb
new file mode 100644
index 00000000000..733aaa62b31
--- /dev/null
+++ b/db/post_migrate/20230608233452_cleanup_bigint_conversion_for_epic_user_mentions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForEpicUserMentionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :epic_user_mentions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230608234452_cleanup_bigint_conversion_for_suggestions_for_gitlab_com.rb b/db/post_migrate/20230608234452_cleanup_bigint_conversion_for_suggestions_for_gitlab_com.rb
new file mode 100644
index 00000000000..90f175bd35e
--- /dev/null
+++ b/db/post_migrate/20230608234452_cleanup_bigint_conversion_for_suggestions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForSuggestionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :suggestions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230608235452_cleanup_bigint_conversion_for_issue_user_mentions_for_gitlab_com.rb b/db/post_migrate/20230608235452_cleanup_bigint_conversion_for_issue_user_mentions_for_gitlab_com.rb
new file mode 100644
index 00000000000..094a8f43eef
--- /dev/null
+++ b/db/post_migrate/20230608235452_cleanup_bigint_conversion_for_issue_user_mentions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForIssueUserMentionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :issue_user_mentions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609000452_cleanup_bigint_conversion_for_note_diff_files_for_gitlab_com.rb b/db/post_migrate/20230609000452_cleanup_bigint_conversion_for_note_diff_files_for_gitlab_com.rb
new file mode 100644
index 00000000000..bdb6ef83ea7
--- /dev/null
+++ b/db/post_migrate/20230609000452_cleanup_bigint_conversion_for_note_diff_files_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForNoteDiffFilesForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :note_diff_files
+ COLUMNS = [:diff_note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609001452_cleanup_bigint_conversion_for_snippet_user_mentions_for_gitlab_com.rb b/db/post_migrate/20230609001452_cleanup_bigint_conversion_for_snippet_user_mentions_for_gitlab_com.rb
new file mode 100644
index 00000000000..f4b7724567b
--- /dev/null
+++ b/db/post_migrate/20230609001452_cleanup_bigint_conversion_for_snippet_user_mentions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForSnippetUserMentionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :snippet_user_mentions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609002452_cleanup_bigint_conversion_for_design_user_mentions_for_gitlab_com.rb b/db/post_migrate/20230609002452_cleanup_bigint_conversion_for_design_user_mentions_for_gitlab_com.rb
new file mode 100644
index 00000000000..2314cb4ac00
--- /dev/null
+++ b/db/post_migrate/20230609002452_cleanup_bigint_conversion_for_design_user_mentions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForDesignUserMentionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :design_user_mentions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609003452_cleanup_bigint_conversion_for_vulnerability_user_mentions_for_gitlab_com.rb b/db/post_migrate/20230609003452_cleanup_bigint_conversion_for_vulnerability_user_mentions_for_gitlab_com.rb
new file mode 100644
index 00000000000..4722d3d24e8
--- /dev/null
+++ b/db/post_migrate/20230609003452_cleanup_bigint_conversion_for_vulnerability_user_mentions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForVulnerabilityUserMentionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :vulnerability_user_mentions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609004452_cleanup_bigint_conversion_for_commit_user_mentions_for_gitlab_com.rb b/db/post_migrate/20230609004452_cleanup_bigint_conversion_for_commit_user_mentions_for_gitlab_com.rb
new file mode 100644
index 00000000000..b7399f3a6db
--- /dev/null
+++ b/db/post_migrate/20230609004452_cleanup_bigint_conversion_for_commit_user_mentions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForCommitUserMentionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :commit_user_mentions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609005452_cleanup_bigint_conversion_for_merge_request_user_mentions_for_gitlab_com.rb b/db/post_migrate/20230609005452_cleanup_bigint_conversion_for_merge_request_user_mentions_for_gitlab_com.rb
new file mode 100644
index 00000000000..b4b66d218f0
--- /dev/null
+++ b/db/post_migrate/20230609005452_cleanup_bigint_conversion_for_merge_request_user_mentions_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForMergeRequestUserMentionsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :merge_request_user_mentions
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609010452_cleanup_bigint_conversion_for_timelogs_for_gitlab_com.rb b/db/post_migrate/20230609010452_cleanup_bigint_conversion_for_timelogs_for_gitlab_com.rb
new file mode 100644
index 00000000000..6a9d5532716
--- /dev/null
+++ b/db/post_migrate/20230609010452_cleanup_bigint_conversion_for_timelogs_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForTimelogsForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :timelogs
+ COLUMNS = [:note_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230609011452_cleanup_bigint_conversion_for_award_emoji_for_gitlab_com.rb b/db/post_migrate/20230609011452_cleanup_bigint_conversion_for_award_emoji_for_gitlab_com.rb
new file mode 100644
index 00000000000..5edbd8ed212
--- /dev/null
+++ b/db/post_migrate/20230609011452_cleanup_bigint_conversion_for_award_emoji_for_gitlab_com.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupBigintConversionForAwardEmojiForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ enable_lock_retries!
+
+ TABLE = :award_emoji
+ COLUMNS = [:awardable_id]
+
+ def up
+ return unless should_run?
+
+ cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ def down
+ return unless should_run?
+
+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230612075608_replace_ci_job_artifacts_foreign_key_v2.rb b/db/post_migrate/20230612075608_replace_ci_job_artifacts_foreign_key_v2.rb
new file mode 100644
index 00000000000..34a77316f6b
--- /dev/null
+++ b/db/post_migrate/20230612075608_replace_ci_job_artifacts_foreign_key_v2.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class ReplaceCiJobArtifactsForeignKeyV2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+
+ add_concurrent_foreign_key :ci_job_artifacts, :p_ci_builds,
+ name: 'temp_fk_rails_c5137cb2c1_p',
+ column: [:partition_id, :job_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_job_artifacts,
+ name: 'temp_fk_rails_c5137cb2c1_p'
+ end
+
+ def down
+ return unless should_run?
+
+ unprepare_async_foreign_key_validation :ci_job_artifacts, name: 'temp_fk_rails_c5137cb2c1_p'
+ remove_foreign_key_if_exists :ci_job_artifacts, name: 'temp_fk_rails_c5137cb2c1_p'
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_job_artifacts, :ci_builds)
+ end
+end
diff --git a/db/post_migrate/20230612083337_replace_ci_running_builds_foreign_key_v2.rb b/db/post_migrate/20230612083337_replace_ci_running_builds_foreign_key_v2.rb
new file mode 100644
index 00000000000..f8abe274610
--- /dev/null
+++ b/db/post_migrate/20230612083337_replace_ci_running_builds_foreign_key_v2.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class ReplaceCiRunningBuildsForeignKeyV2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+
+ add_concurrent_foreign_key :ci_running_builds, :p_ci_builds,
+ name: 'temp_fk_rails_da45cfa165_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_running_builds,
+ name: 'temp_fk_rails_da45cfa165_p'
+ end
+
+ def down
+ return unless should_run?
+
+ unprepare_async_foreign_key_validation :ci_running_builds, name: 'temp_fk_rails_da45cfa165_p'
+ remove_foreign_key_if_exists :ci_running_builds, name: 'temp_fk_rails_da45cfa165_p'
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_running_builds, :ci_builds)
+ end
+end
diff --git a/db/post_migrate/20230612083655_replace_ci_job_variables_foreign_key_v2.rb b/db/post_migrate/20230612083655_replace_ci_job_variables_foreign_key_v2.rb
new file mode 100644
index 00000000000..df3593c5304
--- /dev/null
+++ b/db/post_migrate/20230612083655_replace_ci_job_variables_foreign_key_v2.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class ReplaceCiJobVariablesForeignKeyV2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+
+ add_concurrent_foreign_key :ci_job_variables, :p_ci_builds,
+ name: 'temp_fk_rails_fbf3b34792_p',
+ column: [:partition_id, :job_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_async_foreign_key_validation :ci_job_variables,
+ name: 'temp_fk_rails_fbf3b34792_p'
+ end
+
+ def down
+ return unless should_run?
+
+ unprepare_async_foreign_key_validation :ci_job_variables, name: 'temp_fk_rails_fbf3b34792_p'
+ remove_foreign_key_if_exists :ci_job_variables, name: 'temp_fk_rails_fbf3b34792_p'
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_job_variables, :ci_builds)
+ end
+end
diff --git a/db/post_migrate/20230612083810_replace_p_ci_builds_metadata_foreign_key_v2.rb b/db/post_migrate/20230612083810_replace_p_ci_builds_metadata_foreign_key_v2.rb
new file mode 100644
index 00000000000..c97dd22eee1
--- /dev/null
+++ b/db/post_migrate/20230612083810_replace_p_ci_builds_metadata_foreign_key_v2.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class ReplacePCiBuildsMetadataForeignKeyV2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+
+ add_concurrent_partitioned_foreign_key :p_ci_builds_metadata, :p_ci_builds,
+ name: 'temp_fk_e20479742e_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_partitioned_async_foreign_key_validation :p_ci_builds_metadata,
+ name: 'temp_fk_e20479742e_p'
+ end
+
+ def down
+ return unless should_run?
+
+ unprepare_partitioned_async_foreign_key_validation :p_ci_builds_metadata, name: 'temp_fk_e20479742e_p'
+
+ Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_builds_metadata) do |partition|
+ execute "ALTER TABLE #{partition.identifier} DROP CONSTRAINT IF EXISTS temp_fk_e20479742e_p"
+ end
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_builds_metadata, :ci_builds)
+ end
+end
diff --git a/db/post_migrate/20230612084013_replace_p_ci_runner_machine_builds_foreign_key_v2.rb b/db/post_migrate/20230612084013_replace_p_ci_runner_machine_builds_foreign_key_v2.rb
new file mode 100644
index 00000000000..dbbf7263d87
--- /dev/null
+++ b/db/post_migrate/20230612084013_replace_p_ci_runner_machine_builds_foreign_key_v2.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class ReplacePCiRunnerMachineBuildsForeignKeyV2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+
+ add_concurrent_partitioned_foreign_key :p_ci_runner_machine_builds, :p_ci_builds,
+ name: 'temp_fk_bb490f12fe_p',
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: false,
+ reverse_lock_order: true
+
+ prepare_partitioned_async_foreign_key_validation :p_ci_runner_machine_builds,
+ name: 'temp_fk_bb490f12fe_p'
+ end
+
+ def down
+ return unless should_run?
+
+ unprepare_partitioned_async_foreign_key_validation :p_ci_runner_machine_builds, name: 'temp_fk_bb490f12fe_p'
+
+ Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_runner_machine_builds) do |partition|
+ execute "ALTER TABLE #{partition.identifier} DROP CONSTRAINT IF EXISTS temp_fk_bb490f12fe_p"
+ end
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_builds)
+ end
+end
diff --git a/db/post_migrate/20230612162643_pm_checkpoints_remove_advisory_entries.rb b/db/post_migrate/20230612162643_pm_checkpoints_remove_advisory_entries.rb
new file mode 100644
index 00000000000..370441730b6
--- /dev/null
+++ b/db/post_migrate/20230612162643_pm_checkpoints_remove_advisory_entries.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class PmCheckpointsRemoveAdvisoryEntries < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_pm
+
+ def up
+ execute("DELETE FROM pm_checkpoints
+ WHERE data_type = #{Enums::PackageMetadata::DATA_TYPES[:licenses]} and version_format = 1")
+ execute("UPDATE pm_checkpoints SET data_type = #{Enums::PackageMetadata::DATA_TYPES[:licenses]}
+ WHERE data_type = #{Enums::PackageMetadata::DATA_TYPES[:advisories]} and version_format = 1")
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20230614073136_restore_index_for_contribution_analytics_events.rb b/db/post_migrate/20230614073136_restore_index_for_contribution_analytics_events.rb
new file mode 100644
index 00000000000..2ac485f8dc0
--- /dev/null
+++ b/db/post_migrate/20230614073136_restore_index_for_contribution_analytics_events.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RestoreIndexForContributionAnalyticsEvents < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_on_events_to_improve_contribution_analytics_performance'
+
+ disable_ddl_transaction!
+
+ def up
+ prepare_async_index :events, %i[project_id target_type action created_at author_id id], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :events, %i[project_id target_type action created_at author_id id], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230614181637_add_idx_issues_on_work_item_type_project_closed_at_where_closed.rb b/db/post_migrate/20230614181637_add_idx_issues_on_work_item_type_project_closed_at_where_closed.rb
new file mode 100644
index 00000000000..dd260b868e5
--- /dev/null
+++ b/db/post_migrate/20230614181637_add_idx_issues_on_work_item_type_project_closed_at_where_closed.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIdxIssuesOnWorkItemTypeProjectClosedAtWhereClosed < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'idx_issues_on_project_work_item_type_closed_at_where_closed'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :issues, [:project_id, :work_item_type_id, :closed_at], where: 'state_id = 2', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :issues, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230615083713_replace_old_fk_ci_build_pending_states_to_builds.rb b/db/post_migrate/20230615083713_replace_old_fk_ci_build_pending_states_to_builds.rb
new file mode 100644
index 00000000000..82d88888442
--- /dev/null
+++ b/db/post_migrate/20230615083713_replace_old_fk_ci_build_pending_states_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiBuildPendingStatesToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_build_pending_states, :ci_builds,
+ name: :fk_861cd17da3_p, reverse_lock_order: true
+
+ rename_constraint :ci_build_pending_states, :temp_fk_861cd17da3_p, :fk_861cd17da3_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_build_pending_states, :ci_builds,
+ name: :temp_fk_861cd17da3_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_build_pending_states, :fk_861cd17da3_p, :temp_fk_861cd17da3_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_build_pending_states, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_build_pending_states, :p_ci_builds, name: :fk_861cd17da3_p)
+ end
+end
diff --git a/db/post_migrate/20230615083715_replace_old_fk_ci_build_trace_chunks_to_builds.rb b/db/post_migrate/20230615083715_replace_old_fk_ci_build_trace_chunks_to_builds.rb
new file mode 100644
index 00000000000..a5ca73e8124
--- /dev/null
+++ b/db/post_migrate/20230615083715_replace_old_fk_ci_build_trace_chunks_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiBuildTraceChunksToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_build_trace_chunks, :ci_builds,
+ name: :fk_89e29fa5ee_p, reverse_lock_order: true
+
+ rename_constraint :ci_build_trace_chunks, :temp_fk_89e29fa5ee_p, :fk_89e29fa5ee_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_build_trace_chunks, :ci_builds,
+ name: :temp_fk_89e29fa5ee_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_build_trace_chunks, :fk_89e29fa5ee_p, :temp_fk_89e29fa5ee_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_build_trace_chunks, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_build_trace_chunks, :p_ci_builds, name: :fk_89e29fa5ee_p)
+ end
+end
diff --git a/db/post_migrate/20230615083720_replace_old_fk_ci_unit_test_failures_to_builds.rb b/db/post_migrate/20230615083720_replace_old_fk_ci_unit_test_failures_to_builds.rb
new file mode 100644
index 00000000000..be527f7ae38
--- /dev/null
+++ b/db/post_migrate/20230615083720_replace_old_fk_ci_unit_test_failures_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiUnitTestFailuresToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_unit_test_failures, :ci_builds,
+ name: :fk_9e0fc58930_p, reverse_lock_order: true
+
+ rename_constraint :ci_unit_test_failures, :temp_fk_9e0fc58930_p, :fk_9e0fc58930_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_unit_test_failures, :ci_builds,
+ name: :temp_fk_9e0fc58930_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_unit_test_failures, :fk_9e0fc58930_p, :temp_fk_9e0fc58930_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_unit_test_failures, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_unit_test_failures, :p_ci_builds, name: :fk_9e0fc58930_p)
+ end
+end
diff --git a/db/post_migrate/20230615083725_replace_old_fk_ci_sources_pipelines_to_builds.rb b/db/post_migrate/20230615083725_replace_old_fk_ci_sources_pipelines_to_builds.rb
new file mode 100644
index 00000000000..990a4e2bbe4
--- /dev/null
+++ b/db/post_migrate/20230615083725_replace_old_fk_ci_sources_pipelines_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiSourcesPipelinesToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_sources_pipelines, :ci_builds,
+ name: :fk_be5624bf37_p, reverse_lock_order: true
+
+ rename_constraint :ci_sources_pipelines, :temp_fk_be5624bf37_p, :fk_be5624bf37_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_sources_pipelines, :ci_builds,
+ name: :temp_fk_be5624bf37_p,
+ column: [:source_partition_id, :source_job_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_sources_pipelines, :fk_be5624bf37_p, :temp_fk_be5624bf37_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_sources_pipelines, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_sources_pipelines, :p_ci_builds, name: :fk_be5624bf37_p)
+ end
+end
diff --git a/db/post_migrate/20230615083730_replace_old_fk_ci_resources_to_builds.rb b/db/post_migrate/20230615083730_replace_old_fk_ci_resources_to_builds.rb
new file mode 100644
index 00000000000..498b513c425
--- /dev/null
+++ b/db/post_migrate/20230615083730_replace_old_fk_ci_resources_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiResourcesToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_resources, :ci_builds,
+ name: :fk_e169a8e3d5_p, reverse_lock_order: true
+
+ rename_constraint :ci_resources, :temp_fk_e169a8e3d5_p, :fk_e169a8e3d5_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_resources, :ci_builds,
+ name: :temp_fk_e169a8e3d5_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :nullify,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_resources, :fk_e169a8e3d5_p, :temp_fk_e169a8e3d5_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_resources, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_resources, :p_ci_builds, name: :fk_e169a8e3d5_p)
+ end
+end
diff --git a/db/post_migrate/20230615083734_replace_old_fk_ci_build_report_results_to_builds.rb b/db/post_migrate/20230615083734_replace_old_fk_ci_build_report_results_to_builds.rb
new file mode 100644
index 00000000000..24b51a45613
--- /dev/null
+++ b/db/post_migrate/20230615083734_replace_old_fk_ci_build_report_results_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiBuildReportResultsToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_build_report_results, :ci_builds,
+ name: :fk_rails_16cb1ff064_p, reverse_lock_order: true
+
+ rename_constraint :ci_build_report_results, :temp_fk_rails_16cb1ff064_p, :fk_rails_16cb1ff064_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_build_report_results, :ci_builds,
+ name: :temp_fk_rails_16cb1ff064_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_build_report_results, :fk_rails_16cb1ff064_p, :temp_fk_rails_16cb1ff064_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_build_report_results, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_build_report_results, :p_ci_builds, name: :fk_rails_16cb1ff064_p)
+ end
+end
diff --git a/db/post_migrate/20230615083738_replace_old_fk_ci_build_needs_to_builds.rb b/db/post_migrate/20230615083738_replace_old_fk_ci_build_needs_to_builds.rb
new file mode 100644
index 00000000000..4a77ec01551
--- /dev/null
+++ b/db/post_migrate/20230615083738_replace_old_fk_ci_build_needs_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiBuildNeedsToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_build_needs, :ci_builds,
+ name: :fk_rails_3cf221d4ed_p, reverse_lock_order: true
+
+ rename_constraint :ci_build_needs, :temp_fk_rails_3cf221d4ed_p, :fk_rails_3cf221d4ed_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_build_needs, :ci_builds,
+ name: :temp_fk_rails_3cf221d4ed_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_build_needs, :fk_rails_3cf221d4ed_p, :temp_fk_rails_3cf221d4ed_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_build_needs, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_build_needs, :p_ci_builds, name: :fk_rails_3cf221d4ed_p)
+ end
+end
diff --git a/db/post_migrate/20230615083741_replace_old_fk_ci_builds_runner_session_to_builds.rb b/db/post_migrate/20230615083741_replace_old_fk_ci_builds_runner_session_to_builds.rb
new file mode 100644
index 00000000000..56a790aef62
--- /dev/null
+++ b/db/post_migrate/20230615083741_replace_old_fk_ci_builds_runner_session_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiBuildsRunnerSessionToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_builds_runner_session, :ci_builds,
+ name: :fk_rails_70707857d3_p, reverse_lock_order: true
+
+ rename_constraint :ci_builds_runner_session, :temp_fk_rails_70707857d3_p, :fk_rails_70707857d3_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_builds_runner_session, :ci_builds,
+ name: :temp_fk_rails_70707857d3_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_builds_runner_session, :fk_rails_70707857d3_p, :temp_fk_rails_70707857d3_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_builds_runner_session, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_builds_runner_session, :p_ci_builds, name: :fk_rails_70707857d3_p)
+ end
+end
diff --git a/db/post_migrate/20230615083744_replace_old_fk_ci_pending_builds_to_builds.rb b/db/post_migrate/20230615083744_replace_old_fk_ci_pending_builds_to_builds.rb
new file mode 100644
index 00000000000..42095da09e2
--- /dev/null
+++ b/db/post_migrate/20230615083744_replace_old_fk_ci_pending_builds_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiPendingBuildsToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_pending_builds, :ci_builds,
+ name: :fk_rails_725a2644a3_p, reverse_lock_order: true
+
+ rename_constraint :ci_pending_builds, :temp_fk_rails_725a2644a3_p, :fk_rails_725a2644a3_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_pending_builds, :ci_builds,
+ name: :temp_fk_rails_725a2644a3_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_pending_builds, :fk_rails_725a2644a3_p, :temp_fk_rails_725a2644a3_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_pending_builds, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_pending_builds, :p_ci_builds, name: :fk_rails_725a2644a3_p)
+ end
+end
diff --git a/db/post_migrate/20230615083748_replace_old_fk_ci_build_trace_metadata_to_builds.rb b/db/post_migrate/20230615083748_replace_old_fk_ci_build_trace_metadata_to_builds.rb
new file mode 100644
index 00000000000..72d598ae0b9
--- /dev/null
+++ b/db/post_migrate/20230615083748_replace_old_fk_ci_build_trace_metadata_to_builds.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class ReplaceOldFkCiBuildTraceMetadataToBuilds < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum
+
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+ return if new_foreign_key_exists?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists :ci_build_trace_metadata, :ci_builds,
+ name: :fk_rails_aebc78111f_p, reverse_lock_order: true
+
+ rename_constraint :ci_build_trace_metadata, :temp_fk_rails_aebc78111f_p, :fk_rails_aebc78111f_p
+ end
+ end
+
+ def down
+ return unless should_run?
+ return unless new_foreign_key_exists?
+
+ add_concurrent_foreign_key :ci_build_trace_metadata, :ci_builds,
+ name: :temp_fk_rails_aebc78111f_p,
+ column: [:partition_id, :build_id],
+ target_column: [:partition_id, :id],
+ on_update: :cascade,
+ on_delete: :cascade,
+ validate: true,
+ reverse_lock_order: true
+
+ switch_constraint_names :ci_build_trace_metadata, :fk_rails_aebc78111f_p, :temp_fk_rails_aebc78111f_p
+ end
+
+ private
+
+ def should_run?
+ can_execute_on?(:ci_build_trace_metadata, :ci_builds)
+ end
+
+ def new_foreign_key_exists?
+ foreign_key_exists?(:ci_build_trace_metadata, :p_ci_builds, name: :fk_rails_aebc78111f_p)
+ end
+end
diff --git a/db/post_migrate/20230615202125_prepare_index_issues_on_project_health_status_asc_work_item_type.rb b/db/post_migrate/20230615202125_prepare_index_issues_on_project_health_status_asc_work_item_type.rb
new file mode 100644
index 00000000000..ac8b9582fc8
--- /dev/null
+++ b/db/post_migrate/20230615202125_prepare_index_issues_on_project_health_status_asc_work_item_type.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class PrepareIndexIssuesOnProjectHealthStatusAscWorkItemType < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_issues_on_project_health_status_asc_work_item_type'
+
+ def up
+ prepare_async_index :issues,
+ [:project_id, :health_status, :id, :state_id, :work_item_type_id],
+ order: { health_status: 'ASC NULLS LAST', id: :desc },
+ name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :issues, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230615202511_prepare_index_issues_on_project_health_status_desc_work_item_type.rb b/db/post_migrate/20230615202511_prepare_index_issues_on_project_health_status_desc_work_item_type.rb
new file mode 100644
index 00000000000..1c8b6cdd3a3
--- /dev/null
+++ b/db/post_migrate/20230615202511_prepare_index_issues_on_project_health_status_desc_work_item_type.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class PrepareIndexIssuesOnProjectHealthStatusDescWorkItemType < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_issues_on_project_health_status_desc_work_item_type'
+
+ def up
+ prepare_async_index :issues,
+ [:project_id, :health_status, :id, :state_id, :work_item_type_id],
+ order: { health_status: 'DESC NULLS LAST', id: :desc },
+ name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :issues, INDEX_NAME
+ end
+end