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/20220920124709_backfill_internal_on_notes_renamed.rb (renamed from db/post_migrate/20220920124709_backfill_internal_on_notes.rb)4
-rw-r--r--db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb23
-rw-r--r--db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb23
-rw-r--r--db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb23
-rw-r--r--db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb23
-rw-r--r--db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb23
-rw-r--r--db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb23
-rw-r--r--db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb23
-rw-r--r--db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb23
-rw-r--r--db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb14
-rw-r--r--db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb27
-rw-r--r--db/post_migrate/20230703024031_cleanup_project_pipeline_status_key.rb3
-rw-r--r--db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb56
-rw-r--r--db/post_migrate/20230804122825_add_unique_index_on_uuid_convert_string_to_uuid.rb23
-rw-r--r--db/post_migrate/20230804123252_add_unique_index_on_uuid_convert_string_to_uuid_including_vulnerability_id.rb22
-rw-r--r--db/post_migrate/20230808200355_remove_application_settings_dashboard_columns.rb8
-rw-r--r--db/post_migrate/20230809170822_ensure_system_note_metadata_bigint_backfill_is_finished_for_self_managed.rb23
-rw-r--r--db/post_migrate/20230809174702_swap_system_note_metadata_note_id_to_bigint_for_self_managed.rb62
-rw-r--r--db/post_migrate/20230809203254_ensure_issue_user_mentions_bigint_backfill_is_finished_for_self_managed.rb23
-rw-r--r--db/post_migrate/20230809210550_swap_issue_user_mentions_note_id_to_bigint_for_self_managed.rb74
-rw-r--r--db/post_migrate/20230810112715_ensure_note_diff_files_bigint_backfill_is_finished_for_self_hosts.rb21
-rw-r--r--db/post_migrate/20230810113227_swap_note_diff_files_note_id_to_bigint_for_self_hosts.rb64
-rw-r--r--db/post_migrate/20230810124545_schedule_fixing_namespace_ids_of_vulnerability_reads.rb24
-rw-r--r--db/post_migrate/20230811103457_queue_backfill_nuget_normalized_version.rb25
-rw-r--r--db/post_migrate/20230811185901_remove_application_settings_dashboard_notification_limit_column.rb9
-rw-r--r--db/post_migrate/20230811211544_backfill_alert_management_prometheus_integrations.rb52
-rw-r--r--db/post_migrate/20230815140656_queue_populate_denormalized_columns_for_sbom_occurrences.rb27
-rw-r--r--db/post_migrate/20230815160428_rename_plans_titles_with_legacy_plan_names.rb18
-rw-r--r--db/post_migrate/20230816111730_ensure_id_uniqueness_for_p_ci_builds_v3.rb40
-rw-r--r--db/post_migrate/20230816152540_ensure_dum_note_id_bigint_backfill_is_finished_for_self_managed.rb24
-rw-r--r--db/post_migrate/20230816152639_swap_design_user_mentions_note_id_to_big_int_for_self_managed.rb62
-rw-r--r--db/post_migrate/20230816210503_ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_self_managed.rb23
-rw-r--r--db/post_migrate/20230816213228_swap_merge_request_user_mentions_note_id_to_bigint_for_self_managed.rb74
-rw-r--r--db/post_migrate/20230817050946_backfill_shared_runners_duration_for_project_bigint_conversion.rb16
-rw-r--r--db/post_migrate/20230817111753_ensure_events_bigint_backfill_is_finished_for_self_hosts.rb21
-rw-r--r--db/post_migrate/20230817111938_swap_events_target_id_to_bigint_for_self_hosts.rb51
-rw-r--r--db/post_migrate/20230817143507_ensure_award_emoji_bigint_backfill_is_finished_for_self_hosts.rb21
-rw-r--r--db/post_migrate/20230817143637_swap_award_emoji_note_id_to_bigint_for_self_hosts.rb58
-rw-r--r--db/post_migrate/20230818034041_prepare_removal_index_success_deployments_on_cluster_id_and_environment_id.rb17
-rw-r--r--db/post_migrate/20230818050946_backfill_shared_runners_duration_for_namespace_bigint_conversion.rb16
-rw-r--r--db/post_migrate/20230818055517_prepare_removal_index_deployments_on_id_where_cluster_id_present.rb14
-rw-r--r--db/post_migrate/20230818083610_queue_backfill_users_with_defaults.rb28
-rw-r--r--db/post_migrate/20230818085219_queue_backfill_user_preferences_with_defaults.rb28
-rw-r--r--db/post_migrate/20230818142801_queue_create_compliance_standards_adherence.rb28
-rw-r--r--db/post_migrate/20230821081603_queue_convert_credit_card_validation_data_to_hashes.rb25
-rw-r--r--db/post_migrate/20230822064841_prepare_index_for_org_id_on_projects.rb13
-rw-r--r--db/post_migrate/20230822104028_delete_project_callout_three.rb23
-rw-r--r--db/post_migrate/20230822125256_drop_temporary_index_on_vulnerability_reads_dismissal_reason.rb24
-rw-r--r--db/post_migrate/20230822153124_remove_free_user_cap_email_workers_related_columns.rb29
-rw-r--r--db/post_migrate/20230822154640_add_async_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb17
-rw-r--r--db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb13
-rw-r--r--db/post_migrate/20230823085627_add_temp_index_for_project_statistics_updated_at.rb18
-rw-r--r--db/post_migrate/20230823090001_queue_backfill_project_statistics_storage_size_with_recent_size.rb25
-rw-r--r--db/post_migrate/20230823140934_add_linked_items_widget_to_ticket_work_item_type.rb49
-rw-r--r--db/post_migrate/20230823143519_remove_users_notification_settings_user_id_fk.rb22
-rw-r--r--db/post_migrate/20230823144846_remove_users_members_user_id_fk.rb22
-rw-r--r--db/post_migrate/20230823145053_ensure_notes_bigint_backfill_is_finished_for_self_managed.rb24
-rw-r--r--db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb183
-rw-r--r--db/post_migrate/20230823161514_remove_namespaces_routes_namespace_id_fk.rb22
-rw-r--r--db/post_migrate/20230823194111_remove_pages_deployments_project_id_path_prefix_unique_index.rb14
-rw-r--r--db/post_migrate/20230825085648_ensure_backfill_for_ci_stages_pipeline_id_is_finished.rb23
-rw-r--r--db/post_migrate/20230825085719_create_async_index_for_ci_stages_pipeline_id.rb31
-rw-r--r--db/post_migrate/20230829120720_index_finding_id_for_vulnerabilities.rb14
-rw-r--r--db/post_migrate/20230830121830_queue_update_users_set_external_if_service_account.rb26
-rw-r--r--db/post_migrate/20230831084632_queue_sync_scan_result_policies.rb25
-rw-r--r--db/post_migrate/20230831101144_index_org_id_and_id_on_organization_user.rb15
-rw-r--r--db/post_migrate/20230901033401_ensure_backfill_for_ci_sources_pipelines_pipeline_id_is_finished.rb26
-rw-r--r--db/post_migrate/20230901044003_add_sync_foreign_key_for_ci_pipeline_variables_pipeline_id.rb15
-rw-r--r--db/post_migrate/20230901050458_ensure_backfill_for_ci_pipelines_auto_canceled_by_id_is_finished.rb26
-rw-r--r--db/post_migrate/20230901054536_ensure_backfill_for_ci_pipeline_chat_data_pipeline_id_is_finished.rb23
-rw-r--r--db/post_migrate/20230901064536_add_concurrent_index_for_ci_pipeline_chat_data_pipeline_id_convert_to_bigint.rb17
-rw-r--r--db/post_migrate/20230901064537_remove_namespace_details_dashboard_fields.rb10
-rw-r--r--db/post_migrate/20230902033401_create_async_index_for_ci_sources_pipelines_pipeline_id.rb25
-rw-r--r--db/post_migrate/20230902050458_create_async_index_for_ci_pipelines_auto_canceled_by_id.rb15
-rw-r--r--db/post_migrate/20230902054536_ensure_backfill_for_ci_pipeline_messages_pipeline_id_is_finished.rb23
-rw-r--r--db/post_migrate/20230903064536_concurrent_index_for_ci_pipeline_messages_pipeline_id_convert_to_bigint.rb17
-rw-r--r--db/post_migrate/20230903064537_add_ci_job_artifacts_file_final_path_index.rb17
-rw-r--r--db/post_migrate/20230904100544_drop_index_deployments_on_id_where_cluster_id_present.rb18
-rw-r--r--db/post_migrate/20230904103804_drop_index_successful_deployments_on_cluster_id_and_environment_id.rb18
-rw-r--r--db/post_migrate/20230905071915_prepare_async_foreign_key_for_ci_pipeline_messages_pipeline_id_bigint.rb15
-rw-r--r--db/post_migrate/20230905091059_sync_index_for_ci_stages_pipeline_id_bigint.rb33
-rw-r--r--db/post_migrate/20230906181457_add_index_to_violations_on_target_proj_id.rb16
-rw-r--r--db/post_migrate/20230907155247_queue_backfill_has_merge_request_of_vulnerability_reads.rb26
-rw-r--r--db/post_migrate/20230907204731_add_index_to_sbom_occurrences_licenses.rb23
-rw-r--r--db/post_migrate/20230908072558_analyze_p_ci_runner_machine_builds.rb15
-rw-r--r--db/post_migrate/20230908072612_analyze_p_ci_job_annotations.rb15
-rw-r--r--db/post_migrate/20230908072626_analyze_p_ci_builds_metadata.rb15
-rw-r--r--db/post_migrate/20230908072639_analyze_p_ci_builds.rb15
-rw-r--r--db/post_migrate/20230909120000_queue_backfill_workspace_personal_access_token.rb26
-rw-r--r--db/post_migrate/20230913100953_create_supporting_index_for_uuid_type_casting.rb23
-rw-r--r--db/post_migrate/20230913115113_add_prepared_at_created_at_index_async.rb15
-rw-r--r--db/post_migrate/20230913120111_remove_prepared_at_created_at_index_async.rb15
-rw-r--r--db/post_migrate/20230913130629_index_org_id_on_projects.rb15
-rw-r--r--db/post_migrate/20230913175529_add_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb16
-rw-r--r--db/post_migrate/20230914054914_index_finding_id_for_vulnerabilities_sync.rb15
95 files changed, 2281 insertions, 208 deletions
diff --git a/db/post_migrate/20220920124709_backfill_internal_on_notes.rb b/db/post_migrate/20220920124709_backfill_internal_on_notes_renamed.rb
index 0d737195907..a9de69243f6 100644
--- a/db/post_migrate/20220920124709_backfill_internal_on_notes.rb
+++ b/db/post_migrate/20220920124709_backfill_internal_on_notes_renamed.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
-class BackfillInternalOnNotes < Gitlab::Database::Migration[2.0]
+# Renamed from BackfillInternalOnNotes to BackfillInternalOnNotesRenamed to avoid collision with an Elasticsearch
+# migration from the same name. See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129012
+class BackfillInternalOnNotesRenamed < Gitlab::Database::Migration[2.0]
MIGRATION = 'BackfillInternalOnNotes'
DELAY_INTERVAL = 2.minutes
TABLE = :notes
diff --git a/db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb b/db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb
index aaea55ce331..c7a7d966911 100644
--- a/db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb
+++ b/db/post_migrate/20230125093723_rebalance_partition_id_ci_pipeline.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class RebalancePartitionIdCiPipeline < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes
- TABLE = :ci_pipelines
- BATCH_SIZE = 2_000
- SUB_BATCH_SIZE = 200
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb b/db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb
index 6165c266a82..a4514e958f9 100644
--- a/db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb
+++ b/db/post_migrate/20230125093840_rebalance_partition_id_ci_build.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class RebalancePartitionIdCiBuild < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes.freeze
- TABLE = :ci_builds
- BATCH_SIZE = 5_000
- SUB_BATCH_SIZE = 500
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb b/db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb
index 9901e6af4ae..8bf1239146c 100644
--- a/db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb
+++ b/db/post_migrate/20230208100917_fix_partition_ids_for_ci_pipeline_variable.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class FixPartitionIdsForCiPipelineVariable < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes.freeze
- TABLE = :ci_pipeline_variables
- BATCH_SIZE = 2_000
- SUB_BATCH_SIZE = 200
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb b/db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb
index d1b25639638..7c6ff6c3b4f 100644
--- a/db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb
+++ b/db/post_migrate/20230208103009_fix_partition_ids_for_ci_job_artifact.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class FixPartitionIdsForCiJobArtifact < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes
- TABLE = :ci_job_artifacts
- BATCH_SIZE = 5_000
- SUB_BATCH_SIZE = 500
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb b/db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb
index c3ec614a37f..f05a53dda5f 100644
--- a/db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb
+++ b/db/post_migrate/20230208132608_fix_partition_ids_for_ci_stage.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class FixPartitionIdsForCiStage < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes.freeze
- TABLE = :ci_stages
- BATCH_SIZE = 3_000
- SUB_BATCH_SIZE = 300
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb b/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb
index d21d986ee31..4ff3d1a2789 100644
--- a/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb
+++ b/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class FixPartitionIdsForCiBuildReportResult < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes.freeze
- TABLE = :ci_build_report_results
- BATCH_SIZE = 2_000
- SUB_BATCH_SIZE = 200
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :build_id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :build_id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb b/db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb
index 25087dcbfa4..f682527a296 100644
--- a/db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb
+++ b/db/post_migrate/20230209092204_fix_partition_ids_for_ci_build_trace_metadata.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class FixPartitionIdsForCiBuildTraceMetadata < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes.freeze
- TABLE = :ci_build_trace_metadata
- BATCH_SIZE = 3_000
- SUB_BATCH_SIZE = 300
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :build_id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :build_id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb b/db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb
index 07fcbcc3ad7..785db1be079 100644
--- a/db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb
+++ b/db/post_migrate/20230209140102_fix_partition_ids_for_ci_build_metadata.rb
@@ -1,30 +1,11 @@
# frozen_string_literal: true
class FixPartitionIdsForCiBuildMetadata < Gitlab::Database::Migration[2.1]
- MIGRATION = 'RebalancePartitionId'
- DELAY_INTERVAL = 2.minutes
- TABLE = :p_ci_builds_metadata
- BATCH_SIZE = 5_000
- SUB_BATCH_SIZE = 500
-
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
def up
- return unless Gitlab.com?
-
- queue_batched_background_migration(
- MIGRATION,
- TABLE,
- :id,
- job_interval: DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- sub_batch_size: SUB_BATCH_SIZE
- )
+ # no-op
end
def down
- return unless Gitlab.com?
-
- delete_batched_background_migration(MIGRATION, TABLE, :id, [])
+ # no-op
end
end
diff --git a/db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb b/db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb
index 0a201c51467..64f5bc4bb5e 100644
--- a/db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb
+++ b/db/post_migrate/20230214122717_fix_partition_ids_for_ci_job_variables.rb
@@ -1,20 +1,8 @@
# frozen_string_literal: true
class FixPartitionIdsForCiJobVariables < Gitlab::Database::Migration[2.1]
- disable_ddl_transaction!
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
- BATCH_SIZE = 50
-
def up
- return unless Gitlab.com?
-
- define_batchable_model(:ci_job_variables)
- .where(partition_id: 101)
- .each_batch(of: BATCH_SIZE) do |batch|
- batch.update_all(partition_id: 100)
- sleep 0.1
- end
+ # no-op
end
def down
diff --git a/db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb b/db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb
index c05b759c2d0..bbacd13389b 100644
--- a/db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb
+++ b/db/post_migrate/20230214154101_fix_partition_ids_on_ci_sources_pipelines.rb
@@ -1,36 +1,11 @@
# frozen_string_literal: true
class FixPartitionIdsOnCiSourcesPipelines < Gitlab::Database::Migration[2.1]
- disable_ddl_transaction!
- restrict_gitlab_migration gitlab_schema: :gitlab_ci
-
- BATCH_SIZE = 50
-
def up
- return unless Gitlab.com?
-
- model = define_batchable_model(:ci_sources_pipelines)
-
- batch_update_records(model, :partition_id, from: 101, to: 100, source_partition_id: 100)
- batch_update_records(model, :source_partition_id, from: 101, to: 100)
+ # no-op
end
def down
# no-op
end
-
- private
-
- def batch_update_records(model, column, from:, to:, **updates)
- updates.reverse_merge!(column => to)
-
- model
- .where(model.arel_table[column].eq(from))
- .each_batch(of: BATCH_SIZE) { |batch| update_records(batch, updates) }
- end
-
- def update_records(relation, updates)
- relation.update_all(updates)
- sleep 0.1
- end
end
diff --git a/db/post_migrate/20230703024031_cleanup_project_pipeline_status_key.rb b/db/post_migrate/20230703024031_cleanup_project_pipeline_status_key.rb
index cb7fc04166f..a5a78dcbbd1 100644
--- a/db/post_migrate/20230703024031_cleanup_project_pipeline_status_key.rb
+++ b/db/post_migrate/20230703024031_cleanup_project_pipeline_status_key.rb
@@ -3,6 +3,9 @@
class CleanupProjectPipelineStatusKey < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
+ # TODO: to remove after feature-flag in duplicate-jobs client middleware is removed
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
MIGRATION_WORKER_CLASS = 'BackfillProjectPipelineStatusTtl'
def up
diff --git a/db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb b/db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb
new file mode 100644
index 00000000000..958a5d6edb9
--- /dev/null
+++ b/db/post_migrate/20230802212443_add_current_user_todos_widget_to_epic_work_item_type.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class AddCurrentUserTodosWidgetToEpicWorkItemType < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ EPIC_ENUM_VALUE = 7
+ WIDGET_NAME = 'Current user todos'
+ WIDGET_ENUM_VALUE = 15
+
+ class MigrationWorkItemType < MigrationRecord
+ self.table_name = 'work_item_types'
+ end
+
+ class MigrationWidgetDefinition < MigrationRecord
+ self.table_name = 'work_item_widget_definitions'
+ end
+
+ def up
+ epic_work_item_type = MigrationWorkItemType.find_by(base_type: EPIC_ENUM_VALUE, namespace_id: nil)
+
+ # Epic type should exist in production applications, checking here to avoid failures
+ # if inconsistent data is present.
+ return say('Epic work item type does not exist, skipping widget creation') unless epic_work_item_type
+
+ widgets = [
+ {
+ work_item_type_id: epic_work_item_type.id,
+ name: WIDGET_NAME,
+ widget_type: WIDGET_ENUM_VALUE
+ }
+ ]
+
+ MigrationWidgetDefinition.upsert_all(
+ widgets,
+ unique_by: :index_work_item_widget_definitions_on_default_witype_and_name
+ )
+ end
+
+ def down
+ epic_work_item_type = MigrationWorkItemType.find_by(base_type: EPIC_ENUM_VALUE, namespace_id: nil)
+
+ return say('Epic work item type does not exist, skipping widget removal') unless epic_work_item_type
+
+ widget_definition = MigrationWidgetDefinition.find_by(
+ work_item_type_id: epic_work_item_type.id,
+ widget_type: WIDGET_ENUM_VALUE,
+ name: WIDGET_NAME,
+ namespace_id: nil
+ )
+
+ return say('Widget definition not found, skipping widget removal') unless widget_definition
+
+ widget_definition.destroy
+ end
+end
diff --git a/db/post_migrate/20230804122825_add_unique_index_on_uuid_convert_string_to_uuid.rb b/db/post_migrate/20230804122825_add_unique_index_on_uuid_convert_string_to_uuid.rb
new file mode 100644
index 00000000000..ac94bca4de4
--- /dev/null
+++ b/db/post_migrate/20230804122825_add_unique_index_on_uuid_convert_string_to_uuid.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexOnUuidConvertStringToUuid < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = "index_vulnerability_occurrences_on_uuid_1"
+
+ def up
+ add_concurrent_index(
+ :vulnerability_occurrences,
+ :uuid_convert_string_to_uuid,
+ unique: true,
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name(
+ :vulnerability_occurrences,
+ INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230804123252_add_unique_index_on_uuid_convert_string_to_uuid_including_vulnerability_id.rb b/db/post_migrate/20230804123252_add_unique_index_on_uuid_convert_string_to_uuid_including_vulnerability_id.rb
new file mode 100644
index 00000000000..7906ed48db6
--- /dev/null
+++ b/db/post_migrate/20230804123252_add_unique_index_on_uuid_convert_string_to_uuid_including_vulnerability_id.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexOnUuidConvertStringToUuidIncludingVulnerabilityId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = "index_vuln_findings_on_uuid_including_vuln_id_1"
+
+ def up
+ execute <<~SQL
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS #{INDEX_NAME}
+ ON vulnerability_occurrences(uuid_convert_string_to_uuid)
+ INCLUDE(vulnerability_id)
+ SQL
+ end
+
+ def down
+ remove_concurrent_index_by_name(
+ :vulnerability_occurrences,
+ INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230808200355_remove_application_settings_dashboard_columns.rb b/db/post_migrate/20230808200355_remove_application_settings_dashboard_columns.rb
new file mode 100644
index 00000000000..41a1074cbcf
--- /dev/null
+++ b/db/post_migrate/20230808200355_remove_application_settings_dashboard_columns.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class RemoveApplicationSettingsDashboardColumns < Gitlab::Database::Migration[2.1]
+ def change
+ remove_column :application_settings, :dashboard_enforcement_limit, :integer, default: 0, null: false
+ remove_column :application_settings, :dashboard_limit_new_namespace_creation_enforcement_date, :date
+ end
+end
diff --git a/db/post_migrate/20230809170822_ensure_system_note_metadata_bigint_backfill_is_finished_for_self_managed.rb b/db/post_migrate/20230809170822_ensure_system_note_metadata_bigint_backfill_is_finished_for_self_managed.rb
new file mode 100644
index 00000000000..cf157a8b575
--- /dev/null
+++ b/db/post_migrate/20230809170822_ensure_system_note_metadata_bigint_backfill_is_finished_for_self_managed.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureSystemNoteMetadataBigintBackfillIsFinishedForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'system_note_metadata',
+ column_name: 'id',
+ job_arguments: [['note_id'], ['note_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230809174702_swap_system_note_metadata_note_id_to_bigint_for_self_managed.rb b/db/post_migrate/20230809174702_swap_system_note_metadata_note_id_to_bigint_for_self_managed.rb
new file mode 100644
index 00000000000..65aec4dd5d9
--- /dev/null
+++ b/db/post_migrate/20230809174702_swap_system_note_metadata_note_id_to_bigint_for_self_managed.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+class SwapSystemNoteMetadataNoteIdToBigintForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'system_note_metadata'
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return if columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ end
+
+ def down
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return unless columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ end
+
+ private
+
+ def swap
+ # This will replace the existing index_system_note_metadata_on_note_id
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
+ name: 'index_system_note_metadata_on_note_id_convert_to_bigint'
+
+ # This will replace the existing fk_d83a918cb1
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
+ name: 'fk_system_note_metadata_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"
+
+ # Swap defaults
+ change_column_default TABLE_NAME, :note_id, nil
+ change_column_default TABLE_NAME, :note_id_convert_to_bigint, 0
+
+ execute 'DROP INDEX IF EXISTS index_system_note_metadata_on_note_id'
+ rename_index TABLE_NAME, 'index_system_note_metadata_on_note_id_convert_to_bigint',
+ 'index_system_note_metadata_on_note_id'
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_d83a918cb1"
+ rename_constraint(TABLE_NAME, 'fk_system_note_metadata_note_id_convert_to_bigint', 'fk_d83a918cb1')
+ end
+ end
+end
diff --git a/db/post_migrate/20230809203254_ensure_issue_user_mentions_bigint_backfill_is_finished_for_self_managed.rb b/db/post_migrate/20230809203254_ensure_issue_user_mentions_bigint_backfill_is_finished_for_self_managed.rb
new file mode 100644
index 00000000000..37d95697f56
--- /dev/null
+++ b/db/post_migrate/20230809203254_ensure_issue_user_mentions_bigint_backfill_is_finished_for_self_managed.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureIssueUserMentionsBigintBackfillIsFinishedForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'issue_user_mentions',
+ column_name: 'id',
+ job_arguments: [['note_id'], ['note_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230809210550_swap_issue_user_mentions_note_id_to_bigint_for_self_managed.rb b/db/post_migrate/20230809210550_swap_issue_user_mentions_note_id_to_bigint_for_self_managed.rb
new file mode 100644
index 00000000000..f0502a2c08a
--- /dev/null
+++ b/db/post_migrate/20230809210550_swap_issue_user_mentions_note_id_to_bigint_for_self_managed.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+class SwapIssueUserMentionsNoteIdToBigintForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'issue_user_mentions'
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return if columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ end
+
+ def down
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return unless columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ end
+
+ def swap
+ # This will replace the existing index_issue_user_mentions_on_note_id
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
+ name: 'index_issue_user_mentions_on_note_id_convert_to_bigint',
+ where: 'note_id_convert_to_bigint IS NOT NULL'
+
+ # This will replace the existing issue_user_mentions_on_issue_id_and_note_id_index
+ add_concurrent_index TABLE_NAME, [:issue_id, :note_id_convert_to_bigint], unique: true,
+ name: 'tmp_issue_user_mentions_on_issue_id_and_note_id_index'
+
+ # This will replace the existing issue_user_mentions_on_issue_id_index
+ add_concurrent_index TABLE_NAME, :issue_id, unique: true,
+ name: 'tmp_issue_user_mentions_on_issue_id_index',
+ where: 'note_id_convert_to_bigint IS NULL'
+
+ # This will replace the existing fk_rails_3861d9fefa
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
+ name: 'fk_issue_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_issue_user_mentions_on_note_id'
+ rename_index TABLE_NAME, 'index_issue_user_mentions_on_note_id_convert_to_bigint',
+ 'index_issue_user_mentions_on_note_id'
+
+ execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_and_note_id_index'
+ rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_and_note_id_index',
+ 'issue_user_mentions_on_issue_id_and_note_id_index'
+
+ execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_index'
+ rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_index',
+ 'issue_user_mentions_on_issue_id_index'
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_3861d9fefa"
+ rename_constraint(TABLE_NAME, 'fk_issue_user_mentions_note_id_convert_to_bigint', 'fk_rails_3861d9fefa')
+ end
+ end
+end
diff --git a/db/post_migrate/20230810112715_ensure_note_diff_files_bigint_backfill_is_finished_for_self_hosts.rb b/db/post_migrate/20230810112715_ensure_note_diff_files_bigint_backfill_is_finished_for_self_hosts.rb
new file mode 100644
index 00000000000..f6be8be3008
--- /dev/null
+++ b/db/post_migrate/20230810112715_ensure_note_diff_files_bigint_backfill_is_finished_for_self_hosts.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class EnsureNoteDiffFilesBigintBackfillIsFinishedForSelfHosts < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'note_diff_files',
+ column_name: 'id',
+ job_arguments: [['diff_note_id'], ['diff_note_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230810113227_swap_note_diff_files_note_id_to_bigint_for_self_hosts.rb b/db/post_migrate/20230810113227_swap_note_diff_files_note_id_to_bigint_for_self_hosts.rb
new file mode 100644
index 00000000000..682996234d6
--- /dev/null
+++ b/db/post_migrate/20230810113227_swap_note_diff_files_note_id_to_bigint_for_self_hosts.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+class SwapNoteDiffFilesNoteIdToBigintForSelfHosts < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'note_diff_files'
+
+ def up
+ return if should_skip?
+ return if temp_column_removed?(TABLE_NAME, :diff_note_id)
+ return if columns_swapped?(TABLE_NAME, :diff_note_id)
+
+ swap
+ end
+
+ def down
+ return if should_skip?
+ return if temp_column_removed?(TABLE_NAME, :diff_note_id)
+ return unless columns_swapped?(TABLE_NAME, :diff_note_id)
+
+ swap
+ end
+
+ def swap
+ # This will replace the existing index_note_diff_files_on_diff_note_id
+ add_concurrent_index TABLE_NAME, :diff_note_id_convert_to_bigint, unique: true,
+ name: 'index_note_diff_files_on_diff_note_id_convert_to_bigint'
+
+ # This will replace the existing fk_rails_3d66047aeb
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :diff_note_id_convert_to_bigint,
+ name: 'fk_note_diff_files_diff_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 diff_note_id TO diff_note_id_tmp"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN diff_note_id_convert_to_bigint TO diff_note_id"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN diff_note_id_tmp TO diff_note_id_convert_to_bigint"
+
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger
+ .on_table(TABLE_NAME, connection: connection)
+ .name(:diff_note_id, :diff_note_id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ # Swap defaults
+ change_column_default TABLE_NAME, :diff_note_id, nil
+ change_column_default TABLE_NAME, :diff_note_id_convert_to_bigint, 0
+
+ execute 'DROP INDEX IF EXISTS index_note_diff_files_on_diff_note_id'
+ rename_index TABLE_NAME, 'index_note_diff_files_on_diff_note_id_convert_to_bigint',
+ 'index_note_diff_files_on_diff_note_id'
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_3d66047aeb"
+ rename_constraint(TABLE_NAME, 'fk_note_diff_files_diff_note_id_convert_to_bigint', 'fk_rails_3d66047aeb')
+ end
+ end
+
+ def should_skip?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230810124545_schedule_fixing_namespace_ids_of_vulnerability_reads.rb b/db/post_migrate/20230810124545_schedule_fixing_namespace_ids_of_vulnerability_reads.rb
new file mode 100644
index 00000000000..0ff461cc1d1
--- /dev/null
+++ b/db/post_migrate/20230810124545_schedule_fixing_namespace_ids_of_vulnerability_reads.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class ScheduleFixingNamespaceIdsOfVulnerabilityReads < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'FixNamespaceIdsOfVulnerabilityReads'
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :vulnerability_reads,
+ :vulnerability_id,
+ job_interval: 2.minutes,
+ batch_size: 10_000,
+ sub_batch_size: 100
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :vulnerability_reads, :vulnerability_id, [])
+ end
+end
diff --git a/db/post_migrate/20230811103457_queue_backfill_nuget_normalized_version.rb b/db/post_migrate/20230811103457_queue_backfill_nuget_normalized_version.rb
new file mode 100644
index 00000000000..52e2b7c36eb
--- /dev/null
+++ b/db/post_migrate/20230811103457_queue_backfill_nuget_normalized_version.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class QueueBackfillNugetNormalizedVersion < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = "BackfillNugetNormalizedVersion"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 6000
+ SUB_BATCH_SIZE = 250
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :packages_nuget_metadata,
+ :package_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :packages_nuget_metadata, :package_id, [])
+ end
+end
diff --git a/db/post_migrate/20230811185901_remove_application_settings_dashboard_notification_limit_column.rb b/db/post_migrate/20230811185901_remove_application_settings_dashboard_notification_limit_column.rb
new file mode 100644
index 00000000000..cfd112316ee
--- /dev/null
+++ b/db/post_migrate/20230811185901_remove_application_settings_dashboard_notification_limit_column.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class RemoveApplicationSettingsDashboardNotificationLimitColumn < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def change
+ remove_column :application_settings, :dashboard_notification_limit, :integer, default: 0, null: false
+ end
+end
diff --git a/db/post_migrate/20230811211544_backfill_alert_management_prometheus_integrations.rb b/db/post_migrate/20230811211544_backfill_alert_management_prometheus_integrations.rb
new file mode 100644
index 00000000000..96d098f2f0a
--- /dev/null
+++ b/db/post_migrate/20230811211544_backfill_alert_management_prometheus_integrations.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+# Migrate Integrations::Prometheus records to 'alert_management_http_integrations',
+# corresponding to Metrics Dashboard removal in 16.0.
+# See https://gitlab.com/gitlab-org/gitlab/-/issues/338838 for more details.
+class BackfillAlertManagementPrometheusIntegrations < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ BATCH_SIZE = 10
+
+ def up
+ each_batch_range(:project_alerting_settings, of: BATCH_SIZE) do |min, max|
+ execute <<~SQL
+ INSERT INTO alert_management_http_integrations (
+ project_id,
+ encrypted_token,
+ encrypted_token_iv,
+ active,
+ name,
+ endpoint_identifier,
+ type_identifier,
+ created_at,
+ updated_at
+ ) SELECT
+ project_alerting_settings.project_id,
+ project_alerting_settings.encrypted_token,
+ project_alerting_settings.encrypted_token_iv,
+ COALESCE(integrations.active, FALSE),
+ 'Prometheus',
+ 'legacy-prometheus',
+ 1, --type_identifiers { http: 0, prometheus: 1 }
+ CURRENT_TIMESTAMP,
+ CURRENT_TIMESTAMP
+ FROM project_alerting_settings
+ LEFT JOIN integrations
+ ON project_alerting_settings.project_id = integrations.project_id
+ AND integrations.type_new = 'Integrations::Prometheus'
+ WHERE project_alerting_settings.project_id BETWEEN #{min} AND #{max}
+ ON CONFLICT DO NOTHING
+ SQL
+ end
+ end
+
+ def down
+ execute <<~SQL
+ DELETE FROM alert_management_http_integrations
+ WHERE type_identifier = 1 --type_identifiers { http: 0, prometheus: 1 }
+ AND endpoint_identifier = 'legacy-prometheus'
+ SQL
+ end
+end
diff --git a/db/post_migrate/20230815140656_queue_populate_denormalized_columns_for_sbom_occurrences.rb b/db/post_migrate/20230815140656_queue_populate_denormalized_columns_for_sbom_occurrences.rb
new file mode 100644
index 00000000000..c27b12c55f0
--- /dev/null
+++ b/db/post_migrate/20230815140656_queue_populate_denormalized_columns_for_sbom_occurrences.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class QueuePopulateDenormalizedColumnsForSbomOccurrences < Gitlab::Database::Migration[2.1]
+ MIGRATION = "PopulateDenormalizedColumnsForSbomOccurrences"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 5_000
+ SUB_BATCH_SIZE = 100
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :sbom_occurrences,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :sbom_occurrences, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230815160428_rename_plans_titles_with_legacy_plan_names.rb b/db/post_migrate/20230815160428_rename_plans_titles_with_legacy_plan_names.rb
new file mode 100644
index 00000000000..3d4a8064a89
--- /dev/null
+++ b/db/post_migrate/20230815160428_rename_plans_titles_with_legacy_plan_names.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RenamePlansTitlesWithLegacyPlanNames < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main_clusterwide
+
+ def up
+ execute "UPDATE plans SET title = 'Premium' WHERE name = 'premium'"
+ execute "UPDATE plans SET title = 'Ultimate' WHERE name = 'ultimate'"
+ end
+
+ def down
+ # no-op
+
+ # We don't know or even want to revert back to the old plan titles.
+ end
+end
diff --git a/db/post_migrate/20230816111730_ensure_id_uniqueness_for_p_ci_builds_v3.rb b/db/post_migrate/20230816111730_ensure_id_uniqueness_for_p_ci_builds_v3.rb
new file mode 100644
index 00000000000..c91525e0998
--- /dev/null
+++ b/db/post_migrate/20230816111730_ensure_id_uniqueness_for_p_ci_builds_v3.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class EnsureIdUniquenessForPCiBuildsV3 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::SchemaHelpers
+
+ enable_lock_retries!
+
+ TABLE_NAME = :p_ci_builds
+ FUNCTION_NAME = :assign_p_ci_builds_id_value
+ TRIGGER_NAME = :assign_p_ci_builds_id_trigger
+
+ def up
+ return if trigger_exists?(:ci_builds, TRIGGER_NAME)
+
+ change_column_default(TABLE_NAME, :id, nil)
+
+ create_trigger_function(FUNCTION_NAME) do
+ <<~SQL
+ IF NEW."id" IS NOT NULL THEN
+ RAISE WARNING 'Manually assigning ids is not allowed, the value will be ignored';
+ END IF;
+ NEW."id" := nextval('ci_builds_id_seq'::regclass);
+ RETURN NEW;
+ SQL
+ end
+
+ Gitlab::Database::PostgresPartitionedTable.each_partition(TABLE_NAME) do |partition|
+ create_trigger(partition.identifier, TRIGGER_NAME, FUNCTION_NAME, fires: 'BEFORE INSERT')
+ end
+ end
+
+ def down
+ execute(<<~SQL.squish)
+ ALTER TABLE #{TABLE_NAME}
+ ALTER COLUMN id SET DEFAULT nextval('ci_builds_id_seq'::regclass);
+
+ DROP FUNCTION IF EXISTS #{FUNCTION_NAME} CASCADE;
+ SQL
+ end
+end
diff --git a/db/post_migrate/20230816152540_ensure_dum_note_id_bigint_backfill_is_finished_for_self_managed.rb b/db/post_migrate/20230816152540_ensure_dum_note_id_bigint_backfill_is_finished_for_self_managed.rb
new file mode 100644
index 00000000000..2379fa93ccc
--- /dev/null
+++ b/db/post_migrate/20230816152540_ensure_dum_note_id_bigint_backfill_is_finished_for_self_managed.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class EnsureDumNoteIdBigintBackfillIsFinishedForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ disable_ddl_transaction!
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'design_user_mentions',
+ column_name: 'id',
+ job_arguments: [['note_id'], ['note_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230816152639_swap_design_user_mentions_note_id_to_big_int_for_self_managed.rb b/db/post_migrate/20230816152639_swap_design_user_mentions_note_id_to_big_int_for_self_managed.rb
new file mode 100644
index 00000000000..9c72bef752f
--- /dev/null
+++ b/db/post_migrate/20230816152639_swap_design_user_mentions_note_id_to_big_int_for_self_managed.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+class SwapDesignUserMentionsNoteIdToBigIntForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'design_user_mentions'
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return if columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ end
+
+ def down
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return unless columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ end
+
+ private
+
+ def swap
+ # This will replace the existing index_design_user_mentions_on_note_id
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
+ name: 'index_design_user_mentions_on_note_id_convert_to_bigint'
+
+ # This will replace the existing fk_rails_8de8c6d632
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
+ name: 'fk_design_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"
+
+ # Swap defaults
+ change_column_default TABLE_NAME, :note_id, nil
+ change_column_default TABLE_NAME, :note_id_convert_to_bigint, 0
+
+ execute 'DROP INDEX IF EXISTS index_design_user_mentions_on_note_id'
+ rename_index TABLE_NAME, 'index_design_user_mentions_on_note_id_convert_to_bigint',
+ 'index_design_user_mentions_on_note_id'
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_8de8c6d632"
+ rename_constraint(TABLE_NAME, 'fk_design_user_mentions_note_id_convert_to_bigint', 'fk_rails_8de8c6d632')
+ end
+ end
+end
diff --git a/db/post_migrate/20230816210503_ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_self_managed.rb b/db/post_migrate/20230816210503_ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_self_managed.rb
new file mode 100644
index 00000000000..c3971e93526
--- /dev/null
+++ b/db/post_migrate/20230816210503_ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_self_managed.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureMrUserMentionsNoteIdBigintBackfillIsFinishedForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'merge_request_user_mentions',
+ column_name: 'id',
+ job_arguments: [['note_id'], ['note_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230816213228_swap_merge_request_user_mentions_note_id_to_bigint_for_self_managed.rb b/db/post_migrate/20230816213228_swap_merge_request_user_mentions_note_id_to_bigint_for_self_managed.rb
new file mode 100644
index 00000000000..93765da66dd
--- /dev/null
+++ b/db/post_migrate/20230816213228_swap_merge_request_user_mentions_note_id_to_bigint_for_self_managed.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+class SwapMergeRequestUserMentionsNoteIdToBigintForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'merge_request_user_mentions'
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return if columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ end
+
+ def down
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :note_id)
+ return unless columns_swapped?(TABLE_NAME, :note_id)
+
+ swap
+ 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
+end
diff --git a/db/post_migrate/20230817050946_backfill_shared_runners_duration_for_project_bigint_conversion.rb b/db/post_migrate/20230817050946_backfill_shared_runners_duration_for_project_bigint_conversion.rb
new file mode 100644
index 00000000000..9ad079efb47
--- /dev/null
+++ b/db/post_migrate/20230817050946_backfill_shared_runners_duration_for_project_bigint_conversion.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class BackfillSharedRunnersDurationForProjectBigintConversion < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ TABLE_NAME = :ci_project_monthly_usages
+ COLUMN_NAMES = %i[shared_runners_duration]
+
+ def up
+ backfill_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES, sub_batch_size: 250)
+ end
+
+ def down
+ revert_backfill_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES)
+ end
+end
diff --git a/db/post_migrate/20230817111753_ensure_events_bigint_backfill_is_finished_for_self_hosts.rb b/db/post_migrate/20230817111753_ensure_events_bigint_backfill_is_finished_for_self_hosts.rb
new file mode 100644
index 00000000000..e80676253db
--- /dev/null
+++ b/db/post_migrate/20230817111753_ensure_events_bigint_backfill_is_finished_for_self_hosts.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class EnsureEventsBigintBackfillIsFinishedForSelfHosts < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'events',
+ column_name: 'id',
+ job_arguments: [['target_id'], ['target_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230817111938_swap_events_target_id_to_bigint_for_self_hosts.rb b/db/post_migrate/20230817111938_swap_events_target_id_to_bigint_for_self_hosts.rb
new file mode 100644
index 00000000000..52165bf1dd7
--- /dev/null
+++ b/db/post_migrate/20230817111938_swap_events_target_id_to_bigint_for_self_hosts.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+class SwapEventsTargetIdToBigintForSelfHosts < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'events'
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :target_id)
+ return if columns_swapped?(TABLE_NAME, :target_id)
+
+ swap
+ end
+
+ def down
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :target_id)
+ return unless columns_swapped?(TABLE_NAME, :target_id)
+
+ swap
+ end
+
+ private
+
+ def swap
+ # This will replace the existing index_events_on_target_type_and_target_id_and_fingerprint
+ add_concurrent_index TABLE_NAME, [:target_type, :target_id_convert_to_bigint, :fingerprint],
+ name: :index_events_on_target_type_and_target_id_bigint_fingerprint,
+ unique: true
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN target_id TO target_id_tmp"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN target_id_convert_to_bigint TO target_id"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN target_id_tmp TO target_id_convert_to_bigint"
+
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger
+ .on_table(TABLE_NAME, connection: connection)
+ .name(:target_id, :target_id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ execute 'DROP INDEX IF EXISTS index_events_on_target_type_and_target_id_and_fingerprint'
+ rename_index TABLE_NAME, 'index_events_on_target_type_and_target_id_bigint_fingerprint',
+ 'index_events_on_target_type_and_target_id_and_fingerprint'
+ end
+ end
+end
diff --git a/db/post_migrate/20230817143507_ensure_award_emoji_bigint_backfill_is_finished_for_self_hosts.rb b/db/post_migrate/20230817143507_ensure_award_emoji_bigint_backfill_is_finished_for_self_hosts.rb
new file mode 100644
index 00000000000..de25c03c0d5
--- /dev/null
+++ b/db/post_migrate/20230817143507_ensure_award_emoji_bigint_backfill_is_finished_for_self_hosts.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class EnsureAwardEmojiBigintBackfillIsFinishedForSelfHosts < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'award_emoji',
+ column_name: 'id',
+ job_arguments: [['awardable_id'], ['awardable_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230817143637_swap_award_emoji_note_id_to_bigint_for_self_hosts.rb b/db/post_migrate/20230817143637_swap_award_emoji_note_id_to_bigint_for_self_hosts.rb
new file mode 100644
index 00000000000..d5c28f8a066
--- /dev/null
+++ b/db/post_migrate/20230817143637_swap_award_emoji_note_id_to_bigint_for_self_hosts.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+class SwapAwardEmojiNoteIdToBigintForSelfHosts < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'award_emoji'
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :awardable_id)
+ return if columns_swapped?(TABLE_NAME, :awardable_id)
+
+ swap
+ end
+
+ def down
+ return if com_or_dev_or_test_but_not_jh?
+ return if temp_column_removed?(TABLE_NAME, :awardable_id)
+ return unless columns_swapped?(TABLE_NAME, :awardable_id)
+
+ swap
+ end
+
+ private
+
+ def swap
+ # This will replace the existing idx_award_emoji_on_user_emoji_name_awardable_type_awardable_id
+ add_concurrent_index TABLE_NAME, [:user_id, :name, :awardable_type, :awardable_id_convert_to_bigint],
+ name: 'tmp_award_emoji_on_user_emoji_name_awardable_type_awardable_id'
+
+ # This will replace the existing index_award_emoji_on_awardable_type_and_awardable_id
+ add_concurrent_index TABLE_NAME, [:awardable_type, :awardable_id_convert_to_bigint],
+ name: 'tmp_index_award_emoji_on_awardable_type_and_awardable_id'
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN awardable_id TO awardable_id_tmp"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN awardable_id_convert_to_bigint TO awardable_id"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN awardable_id_tmp TO awardable_id_convert_to_bigint"
+
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger
+ .on_table(TABLE_NAME, connection: connection)
+ .name(:awardable_id, :awardable_id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ execute 'DROP INDEX IF EXISTS idx_award_emoji_on_user_emoji_name_awardable_type_awardable_id'
+ rename_index TABLE_NAME, 'tmp_award_emoji_on_user_emoji_name_awardable_type_awardable_id',
+ 'idx_award_emoji_on_user_emoji_name_awardable_type_awardable_id'
+
+ execute 'DROP INDEX IF EXISTS index_award_emoji_on_awardable_type_and_awardable_id'
+ rename_index TABLE_NAME, 'tmp_index_award_emoji_on_awardable_type_and_awardable_id',
+ 'index_award_emoji_on_awardable_type_and_awardable_id'
+ end
+ end
+end
diff --git a/db/post_migrate/20230818034041_prepare_removal_index_success_deployments_on_cluster_id_and_environment_id.rb b/db/post_migrate/20230818034041_prepare_removal_index_success_deployments_on_cluster_id_and_environment_id.rb
new file mode 100644
index 00000000000..39a45774676
--- /dev/null
+++ b/db/post_migrate/20230818034041_prepare_removal_index_success_deployments_on_cluster_id_and_environment_id.rb
@@ -0,0 +1,17 @@
+# 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 PrepareRemovalIndexSuccessDeploymentsOnClusterIdAndEnvironmentId < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_successful_deployments_on_cluster_id_and_environment_id'
+
+ # TODO: Index to be destroyed synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/402514
+ def up
+ prepare_async_index_removal :deployments, %i[cluster_id environment_id], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :deployments, %i[cluster_id environment_id], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230818050946_backfill_shared_runners_duration_for_namespace_bigint_conversion.rb b/db/post_migrate/20230818050946_backfill_shared_runners_duration_for_namespace_bigint_conversion.rb
new file mode 100644
index 00000000000..3171008ee3a
--- /dev/null
+++ b/db/post_migrate/20230818050946_backfill_shared_runners_duration_for_namespace_bigint_conversion.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class BackfillSharedRunnersDurationForNamespaceBigintConversion < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ TABLE_NAME = :ci_namespace_monthly_usages
+ COLUMN_NAMES = %i[shared_runners_duration]
+
+ def up
+ backfill_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES, sub_batch_size: 250)
+ end
+
+ def down
+ revert_backfill_conversion_of_integer_to_bigint(TABLE_NAME, COLUMN_NAMES)
+ end
+end
diff --git a/db/post_migrate/20230818055517_prepare_removal_index_deployments_on_id_where_cluster_id_present.rb b/db/post_migrate/20230818055517_prepare_removal_index_deployments_on_id_where_cluster_id_present.rb
new file mode 100644
index 00000000000..c66143809d2
--- /dev/null
+++ b/db/post_migrate/20230818055517_prepare_removal_index_deployments_on_id_where_cluster_id_present.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class PrepareRemovalIndexDeploymentsOnIdWhereClusterIdPresent < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_deployments_on_id_where_cluster_id_present'
+
+ # TODO: Index to be destroyed synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/402510
+ def up
+ prepare_async_index_removal :deployments, :id, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :deployments, :id, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230818083610_queue_backfill_users_with_defaults.rb b/db/post_migrate/20230818083610_queue_backfill_users_with_defaults.rb
new file mode 100644
index 00000000000..b027ef10ddc
--- /dev/null
+++ b/db/post_migrate/20230818083610_queue_backfill_users_with_defaults.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class QueueBackfillUsersWithDefaults < Gitlab::Database::Migration[2.1]
+ MIGRATION = "BackfillUsersWithDefaults"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 3_000
+ SUB_BATCH_SIZE = 200
+ MAX_BATCH_SIZE = 10_000
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :users,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :users, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230818085219_queue_backfill_user_preferences_with_defaults.rb b/db/post_migrate/20230818085219_queue_backfill_user_preferences_with_defaults.rb
new file mode 100644
index 00000000000..0651f21f240
--- /dev/null
+++ b/db/post_migrate/20230818085219_queue_backfill_user_preferences_with_defaults.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class QueueBackfillUserPreferencesWithDefaults < Gitlab::Database::Migration[2.1]
+ MIGRATION = "BackfillUserPreferencesWithDefaults"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 3_000
+ SUB_BATCH_SIZE = 200
+ MAX_BATCH_SIZE = 10_000
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :user_preferences,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :user_preferences, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230818142801_queue_create_compliance_standards_adherence.rb b/db/post_migrate/20230818142801_queue_create_compliance_standards_adherence.rb
new file mode 100644
index 00000000000..33d6dd30e44
--- /dev/null
+++ b/db/post_migrate/20230818142801_queue_create_compliance_standards_adherence.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class QueueCreateComplianceStandardsAdherence < Gitlab::Database::Migration[2.1]
+ MIGRATION = "CreateComplianceStandardsAdherence"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 10_000
+ SUB_BATCH_SIZE = 500
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ return unless Gitlab.ee? # Standards adherence is available only in EE version
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :projects,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :projects, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230821081603_queue_convert_credit_card_validation_data_to_hashes.rb b/db/post_migrate/20230821081603_queue_convert_credit_card_validation_data_to_hashes.rb
new file mode 100644
index 00000000000..00a1840366b
--- /dev/null
+++ b/db/post_migrate/20230821081603_queue_convert_credit_card_validation_data_to_hashes.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class QueueConvertCreditCardValidationDataToHashes < Gitlab::Database::Migration[2.1]
+ MIGRATION = "ConvertCreditCardValidationDataToHashes"
+ 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,
+ :user_credit_card_validations,
+ :user_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :user_credit_card_validations, :user_id, [])
+ end
+end
diff --git a/db/post_migrate/20230822064841_prepare_index_for_org_id_on_projects.rb b/db/post_migrate/20230822064841_prepare_index_for_org_id_on_projects.rb
new file mode 100644
index 00000000000..1f822a440a4
--- /dev/null
+++ b/db/post_migrate/20230822064841_prepare_index_for_org_id_on_projects.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class PrepareIndexForOrgIdOnProjects < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_projects_on_organization_id'
+
+ def up
+ prepare_async_index :projects, :organization_id, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :projects, :organization_id, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230822104028_delete_project_callout_three.rb b/db/post_migrate/20230822104028_delete_project_callout_three.rb
new file mode 100644
index 00000000000..9ba9b3f806a
--- /dev/null
+++ b/db/post_migrate/20230822104028_delete_project_callout_three.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class DeleteProjectCalloutThree < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ BATCH_SIZE = 1000
+ ULTIMATE_FEATURE_REMOVAL_BANNER_FEATURE_NAME = 3
+
+ def up
+ each_batch_range('user_project_callouts', scope: ->(table) { table.all }, of: BATCH_SIZE) do |min, max|
+ execute <<~SQL
+ DELETE FROM user_project_callouts
+ WHERE feature_name = #{ULTIMATE_FEATURE_REMOVAL_BANNER_FEATURE_NAME}
+ AND id BETWEEN #{min} AND #{max}
+ SQL
+ end
+ end
+
+ def down
+ # NO-OP
+ end
+end
diff --git a/db/post_migrate/20230822125256_drop_temporary_index_on_vulnerability_reads_dismissal_reason.rb b/db/post_migrate/20230822125256_drop_temporary_index_on_vulnerability_reads_dismissal_reason.rb
new file mode 100644
index 00000000000..e1b74a1b46c
--- /dev/null
+++ b/db/post_migrate/20230822125256_drop_temporary_index_on_vulnerability_reads_dismissal_reason.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class DropTemporaryIndexOnVulnerabilityReadsDismissalReason < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = "tmp_idx_vuln_reads_where_dismissal_reason_null"
+ DISMISSED_STATE = 2
+
+ def up
+ remove_concurrent_index_by_name(
+ :vulnerability_reads,
+ INDEX_NAME
+ )
+ end
+
+ def down
+ add_concurrent_index(
+ :vulnerability_reads,
+ %i[id],
+ where: "state = #{DISMISSED_STATE} AND dismissal_reason IS NULL",
+ name: INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230822153124_remove_free_user_cap_email_workers_related_columns.rb b/db/post_migrate/20230822153124_remove_free_user_cap_email_workers_related_columns.rb
new file mode 100644
index 00000000000..3ae0459fcdc
--- /dev/null
+++ b/db/post_migrate/20230822153124_remove_free_user_cap_email_workers_related_columns.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class RemoveFreeUserCapEmailWorkersRelatedColumns < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'namespace_details'
+ OVER_LIMIT_CHECK_COLUMN_NAME = 'next_over_limit_check_at'
+ OVER_LIMIT_CHECK_INDEX = 'index_next_over_limit_check_at_asc_order'
+ OVER_LIMIT_NOTIFIED_AT_COLUMN_NAME = 'free_user_cap_over_limit_notified_at'
+ OVER_LIMIT_NOTIFIED_AT_INDEX = 'index_fuc_over_limit_notified_at'
+
+ def up
+ remove_columns TABLE_NAME, OVER_LIMIT_CHECK_COLUMN_NAME, OVER_LIMIT_NOTIFIED_AT_COLUMN_NAME
+ end
+
+ def down
+ unless column_exists?(TABLE_NAME, OVER_LIMIT_CHECK_COLUMN_NAME)
+ add_column TABLE_NAME, OVER_LIMIT_CHECK_COLUMN_NAME, :datetime_with_timezone
+ end
+
+ unless column_exists?(TABLE_NAME, OVER_LIMIT_NOTIFIED_AT_COLUMN_NAME)
+ add_column TABLE_NAME, OVER_LIMIT_NOTIFIED_AT_COLUMN_NAME, :datetime_with_timezone
+ end
+
+ add_concurrent_index TABLE_NAME, OVER_LIMIT_CHECK_COLUMN_NAME, name: OVER_LIMIT_CHECK_INDEX,
+ order: { next_over_limit_check_at: 'ASC NULLS FIRST' }
+ add_concurrent_index TABLE_NAME, OVER_LIMIT_NOTIFIED_AT_COLUMN_NAME, name: OVER_LIMIT_NOTIFIED_AT_INDEX
+ end
+end
diff --git a/db/post_migrate/20230822154640_add_async_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb b/db/post_migrate/20230822154640_add_async_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb
new file mode 100644
index 00000000000..148a9f4c073
--- /dev/null
+++ b/db/post_migrate/20230822154640_add_async_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddAsyncIndexOnMergeRequestsTargetProjectIdAndMergedCommitSha < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_merge_requests_on_target_project_id_and_merged_commit_sha'
+ INDEX_COLUMNS = %i[target_project_id merged_commit_sha]
+
+ disable_ddl_transaction!
+
+ # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/418822
+ def up
+ prepare_async_index :merge_requests, INDEX_COLUMNS, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :merge_requests, INDEX_COLUMNS, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb b/db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb
new file mode 100644
index 00000000000..9d36cbac956
--- /dev/null
+++ b/db/post_migrate/20230822195852_remove_pa_jitsu_related_settings.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RemovePaJitsuRelatedSettings < Gitlab::Database::Migration[2.1]
+ def up
+ # Changed to a no-op, this migration was reverted after
+ # an incident during a deploy to staging.gitlab.com
+ # https://gitlab.com/gitlab-com/gl-infra/production/-/issues/16274
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230823085627_add_temp_index_for_project_statistics_updated_at.rb b/db/post_migrate/20230823085627_add_temp_index_for_project_statistics_updated_at.rb
new file mode 100644
index 00000000000..a242413266d
--- /dev/null
+++ b/db/post_migrate/20230823085627_add_temp_index_for_project_statistics_updated_at.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddTempIndexForProjectStatisticsUpdatedAt < Gitlab::Database::Migration[2.1]
+ INDEX_PROJECT_STATISTICS_UPDATED_AT = 'tmp_index_project_statistics_updated_at'
+
+ disable_ddl_transaction!
+
+ def up
+ # Temporary index is to be used to trigger a refresh of project_statistics repository_size
+ add_concurrent_index :project_statistics, [:project_id, :updated_at],
+ name: INDEX_PROJECT_STATISTICS_UPDATED_AT,
+ where: "repository_size > 0"
+ end
+
+ def down
+ remove_concurrent_index_by_name :project_statistics, INDEX_PROJECT_STATISTICS_UPDATED_AT
+ end
+end
diff --git a/db/post_migrate/20230823090001_queue_backfill_project_statistics_storage_size_with_recent_size.rb b/db/post_migrate/20230823090001_queue_backfill_project_statistics_storage_size_with_recent_size.rb
new file mode 100644
index 00000000000..b841e912ebf
--- /dev/null
+++ b/db/post_migrate/20230823090001_queue_backfill_project_statistics_storage_size_with_recent_size.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class QueueBackfillProjectStatisticsStorageSizeWithRecentSize < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = "BackfillProjectStatisticsStorageSizeWithRecentSize"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 100
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :project_statistics,
+ :project_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :project_statistics, :project_id, [])
+ end
+end
diff --git a/db/post_migrate/20230823140934_add_linked_items_widget_to_ticket_work_item_type.rb b/db/post_migrate/20230823140934_add_linked_items_widget_to_ticket_work_item_type.rb
new file mode 100644
index 00000000000..9f97bd8cc0d
--- /dev/null
+++ b/db/post_migrate/20230823140934_add_linked_items_widget_to_ticket_work_item_type.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+class AddLinkedItemsWidgetToTicketWorkItemType < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ TICKET_ENUM_VALUE = 8
+ WIDGET_NAME = 'Linked items'
+ WIDGET_ENUM_VALUE = 17
+
+ class MigrationWorkItemType < MigrationRecord
+ self.table_name = 'work_item_types'
+ end
+
+ class MigrationWidgetDefinition < MigrationRecord
+ self.table_name = 'work_item_widget_definitions'
+ end
+
+ def up
+ # New instances will not run this migration and add this type via fixtures
+ # checking if record exists mostly because migration specs will run all migrations
+ # and that will conflict with the preloaded base work item types
+ ticket_work_item_type = MigrationWorkItemType.find_by(base_type: TICKET_ENUM_VALUE, namespace_id: nil)
+
+ return say('Ticket work item type does not exist, skipping widget creation') unless ticket_work_item_type
+
+ widgets = [
+ {
+ work_item_type_id: ticket_work_item_type.id,
+ name: WIDGET_NAME,
+ widget_type: WIDGET_ENUM_VALUE
+ }
+ ]
+
+ MigrationWidgetDefinition.upsert_all(
+ widgets,
+ unique_by: :index_work_item_widget_definitions_on_default_witype_and_name
+ )
+ end
+
+ def down
+ ticket_work_item_type = MigrationWorkItemType.find_by(base_type: TICKET_ENUM_VALUE, namespace_id: nil)
+
+ return say('Ticket work item type does not exist, skipping widget removal') unless ticket_work_item_type
+
+ MigrationWidgetDefinition.where(work_item_type_id: ticket_work_item_type.id, widget_type: WIDGET_ENUM_VALUE)
+ .delete_all
+ end
+end
diff --git a/db/post_migrate/20230823143519_remove_users_notification_settings_user_id_fk.rb b/db/post_migrate/20230823143519_remove_users_notification_settings_user_id_fk.rb
new file mode 100644
index 00000000000..2e8b634e108
--- /dev/null
+++ b/db/post_migrate/20230823143519_remove_users_notification_settings_user_id_fk.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class RemoveUsersNotificationSettingsUserIdFk < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ FOREIGN_KEY_NAME = "fk_0c95e91db7"
+
+ def up
+ return unless foreign_key_exists?(:notification_settings, :users, name: FOREIGN_KEY_NAME)
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(:notification_settings, :users,
+ name: FOREIGN_KEY_NAME, reverse_lock_order: true)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:notification_settings, :users,
+ name: FOREIGN_KEY_NAME, column: :user_id,
+ target_column: :id, on_delete: :cascade)
+ end
+end
diff --git a/db/post_migrate/20230823144846_remove_users_members_user_id_fk.rb b/db/post_migrate/20230823144846_remove_users_members_user_id_fk.rb
new file mode 100644
index 00000000000..59f97d7c26a
--- /dev/null
+++ b/db/post_migrate/20230823144846_remove_users_members_user_id_fk.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class RemoveUsersMembersUserIdFk < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ FOREIGN_KEY_NAME = "fk_2e88fb7ce9"
+
+ def up
+ return unless foreign_key_exists?(:members, :users, name: FOREIGN_KEY_NAME)
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(:members, :users,
+ name: FOREIGN_KEY_NAME, reverse_lock_order: true)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:members, :users,
+ name: FOREIGN_KEY_NAME, column: :user_id,
+ target_column: :id, on_delete: :cascade)
+ end
+end
diff --git a/db/post_migrate/20230823145053_ensure_notes_bigint_backfill_is_finished_for_self_managed.rb b/db/post_migrate/20230823145053_ensure_notes_bigint_backfill_is_finished_for_self_managed.rb
new file mode 100644
index 00000000000..c16313bb27d
--- /dev/null
+++ b/db/post_migrate/20230823145053_ensure_notes_bigint_backfill_is_finished_for_self_managed.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class EnsureNotesBigintBackfillIsFinishedForSelfManaged < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ return if com_or_dev_or_test_but_not_jh?
+
+ # Same as was defined in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119913
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'notes',
+ column_name: 'id',
+ job_arguments: [['id'], ['id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb b/db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb
new file mode 100644
index 00000000000..ddfaefc452b
--- /dev/null
+++ b/db/post_migrate/20230823145126_swap_notes_id_to_bigint_for_self_managed.rb
@@ -0,0 +1,183 @@
+# frozen_string_literal: true
+
+class SwapNotesIdToBigintForSelfManaged < 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 if com_or_dev_or_test_but_not_jh?
+
+ return if temp_column_removed?(TABLE_NAME, :id)
+
+ return if columns_swapped?(TABLE_NAME, :id)
+
+ swap
+ end
+
+ def down
+ return if com_or_dev_or_test_but_not_jh?
+
+ return if temp_column_removed?(TABLE_NAME, :id)
+
+ return unless columns_swapped?(TABLE_NAME, :id)
+
+ swap
+ end
+
+ private
+
+ def swap
+ create_indexes
+
+ create_referencing_foreign_keys
+
+ 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"
+
+ rename_secondary_indexes # rubocop:disable Migration/WithLockRetriesDisallowedMethod
+ end
+ end
+
+ # Copy existing indexes from the original column to the new column
+ 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
+
+ # Remove old column indexes and change new column indexes to have the original names
+ 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
+
+ # Copy existing FKs from the original column to the new column
+ #
+ # @note 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.
+ def create_referencing_foreign_keys
+ REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, on_delete)|
+ next if foreign_key_exists?(from_table, TABLE_NAME, column: column,
+ primary_key: :id_convert_to_bigint, name: name)
+
+ add_concurrent_foreign_key(
+ from_table,
+ TABLE_NAME,
+ column: column,
+ target_column: :id_convert_to_bigint,
+ name: "#{name}_tmp",
+ on_delete: on_delete,
+ reverse_lock_order: true
+ )
+ end
+ end
+
+ # Remove existing FKs from the referencing tables, so we don't have to lock on them when we drop the existing PK
+ #
+ # @note 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.
+ def replace_referencing_foreign_keys
+ REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, _)|
+ 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/20230823161514_remove_namespaces_routes_namespace_id_fk.rb b/db/post_migrate/20230823161514_remove_namespaces_routes_namespace_id_fk.rb
new file mode 100644
index 00000000000..a640ac686ed
--- /dev/null
+++ b/db/post_migrate/20230823161514_remove_namespaces_routes_namespace_id_fk.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class RemoveNamespacesRoutesNamespaceIdFk < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ FOREIGN_KEY_NAME = "fk_bb2e5b8968"
+
+ def up
+ return unless foreign_key_exists?(:routes, :namespaces, name: FOREIGN_KEY_NAME)
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(:routes, :namespaces,
+ name: FOREIGN_KEY_NAME, reverse_lock_order: true)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:routes, :namespaces,
+ name: FOREIGN_KEY_NAME, column: :namespace_id,
+ target_column: :id, on_delete: :cascade)
+ end
+end
diff --git a/db/post_migrate/20230823194111_remove_pages_deployments_project_id_path_prefix_unique_index.rb b/db/post_migrate/20230823194111_remove_pages_deployments_project_id_path_prefix_unique_index.rb
new file mode 100644
index 00000000000..9390a06b0bb
--- /dev/null
+++ b/db/post_migrate/20230823194111_remove_pages_deployments_project_id_path_prefix_unique_index.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class RemovePagesDeploymentsProjectIdPathPrefixUniqueIndex < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :pages_deployments,
+ 'index_pages_deployments_unique_path_prefix_by_project'
+ end
+
+ def down
+ # no op
+ end
+end
diff --git a/db/post_migrate/20230825085648_ensure_backfill_for_ci_stages_pipeline_id_is_finished.rb b/db/post_migrate/20230825085648_ensure_backfill_for_ci_stages_pipeline_id_is_finished.rb
new file mode 100644
index 00000000000..3dabd352a1b
--- /dev/null
+++ b/db/post_migrate/20230825085648_ensure_backfill_for_ci_stages_pipeline_id_is_finished.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureBackfillForCiStagesPipelineIdIsFinished < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_stages
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: TABLE_NAME,
+ column_name: 'id',
+ job_arguments: [['pipeline_id'], ['pipeline_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230825085719_create_async_index_for_ci_stages_pipeline_id.rb b/db/post_migrate/20230825085719_create_async_index_for_ci_stages_pipeline_id.rb
new file mode 100644
index 00000000000..a517d96815a
--- /dev/null
+++ b/db/post_migrate/20230825085719_create_async_index_for_ci_stages_pipeline_id.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class CreateAsyncIndexForCiStagesPipelineId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_stages
+ INDEXES = {
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint_and_name' => [
+ [:pipeline_id_convert_to_bigint, :name], { unique: true }
+ ],
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint' => [
+ [:pipeline_id_convert_to_bigint], {}
+ ],
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint_and_id' => [
+ [:pipeline_id_convert_to_bigint, :id], { where: 'status = ANY (ARRAY[0, 1, 2, 8, 9, 10])' }
+ ],
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint_and_position' => [
+ [:pipeline_id_convert_to_bigint, :position], {}
+ ]
+ }
+
+ def up
+ INDEXES.each do |index_name, (columns, options)|
+ prepare_async_index TABLE_NAME, columns, name: index_name, **options
+ end
+ end
+
+ def down
+ INDEXES.each do |index_name, (columns, options)|
+ unprepare_async_index TABLE_NAME, columns, name: index_name, **options
+ end
+ end
+end
diff --git a/db/post_migrate/20230829120720_index_finding_id_for_vulnerabilities.rb b/db/post_migrate/20230829120720_index_finding_id_for_vulnerabilities.rb
new file mode 100644
index 00000000000..2556134658f
--- /dev/null
+++ b/db/post_migrate/20230829120720_index_finding_id_for_vulnerabilities.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class IndexFindingIdForVulnerabilities < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_vulnerabilities_on_finding_id'
+
+ # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/423541
+ def up
+ prepare_async_index :vulnerabilities, :finding_id, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :vulnerabilities, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230830121830_queue_update_users_set_external_if_service_account.rb b/db/post_migrate/20230830121830_queue_update_users_set_external_if_service_account.rb
new file mode 100644
index 00000000000..cffc9bfba39
--- /dev/null
+++ b/db/post_migrate/20230830121830_queue_update_users_set_external_if_service_account.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class QueueUpdateUsersSetExternalIfServiceAccount < Gitlab::Database::Migration[2.1]
+ MIGRATION = "UpdateUsersSetExternalIfServiceAccount"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 100
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :users,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :users, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230831084632_queue_sync_scan_result_policies.rb b/db/post_migrate/20230831084632_queue_sync_scan_result_policies.rb
new file mode 100644
index 00000000000..983c97d75f3
--- /dev/null
+++ b/db/post_migrate/20230831084632_queue_sync_scan_result_policies.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class QueueSyncScanResultPolicies < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = "SyncScanResultPolicies"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 100
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :security_orchestration_policy_configurations,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :security_orchestration_policy_configurations, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230831101144_index_org_id_and_id_on_organization_user.rb b/db/post_migrate/20230831101144_index_org_id_and_id_on_organization_user.rb
new file mode 100644
index 00000000000..0f835e08a54
--- /dev/null
+++ b/db/post_migrate/20230831101144_index_org_id_and_id_on_organization_user.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class IndexOrgIdAndIdOnOrganizationUser < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_organization_users_on_organization_id_and_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :organization_users, %i[organization_id id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :organization_users, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230901033401_ensure_backfill_for_ci_sources_pipelines_pipeline_id_is_finished.rb b/db/post_migrate/20230901033401_ensure_backfill_for_ci_sources_pipelines_pipeline_id_is_finished.rb
new file mode 100644
index 00000000000..686dcdc3585
--- /dev/null
+++ b/db/post_migrate/20230901033401_ensure_backfill_for_ci_sources_pipelines_pipeline_id_is_finished.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class EnsureBackfillForCiSourcesPipelinesPipelineIdIsFinished < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_sources_pipelines
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: TABLE_NAME,
+ column_name: 'id',
+ job_arguments: [
+ %w[pipeline_id source_pipeline_id],
+ %w[pipeline_id_convert_to_bigint source_pipeline_id_convert_to_bigint]
+ ]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230901044003_add_sync_foreign_key_for_ci_pipeline_variables_pipeline_id.rb b/db/post_migrate/20230901044003_add_sync_foreign_key_for_ci_pipeline_variables_pipeline_id.rb
new file mode 100644
index 00000000000..d640b68c118
--- /dev/null
+++ b/db/post_migrate/20230901044003_add_sync_foreign_key_for_ci_pipeline_variables_pipeline_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddSyncForeignKeyForCiPipelineVariablesPipelineId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_pipeline_variables
+ COLUMN_NAME = :pipeline_id
+ FK_NAME = :temp_fk_rails_8d3b04e3e1
+
+ def up
+ validate_foreign_key TABLE_NAME, COLUMN_NAME, name: FK_NAME
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230901050458_ensure_backfill_for_ci_pipelines_auto_canceled_by_id_is_finished.rb b/db/post_migrate/20230901050458_ensure_backfill_for_ci_pipelines_auto_canceled_by_id_is_finished.rb
new file mode 100644
index 00000000000..ce0da3707d0
--- /dev/null
+++ b/db/post_migrate/20230901050458_ensure_backfill_for_ci_pipelines_auto_canceled_by_id_is_finished.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class EnsureBackfillForCiPipelinesAutoCanceledByIdIsFinished < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_pipelines
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: TABLE_NAME,
+ column_name: 'id',
+ job_arguments: [
+ %w[auto_canceled_by_id],
+ %w[auto_canceled_by_id_convert_to_bigint]
+ ]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230901054536_ensure_backfill_for_ci_pipeline_chat_data_pipeline_id_is_finished.rb b/db/post_migrate/20230901054536_ensure_backfill_for_ci_pipeline_chat_data_pipeline_id_is_finished.rb
new file mode 100644
index 00000000000..e600456662e
--- /dev/null
+++ b/db/post_migrate/20230901054536_ensure_backfill_for_ci_pipeline_chat_data_pipeline_id_is_finished.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureBackfillForCiPipelineChatDataPipelineIdIsFinished < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_pipeline_chat_data
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: TABLE_NAME,
+ column_name: 'id',
+ job_arguments: [['pipeline_id'], ['pipeline_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230901064536_add_concurrent_index_for_ci_pipeline_chat_data_pipeline_id_convert_to_bigint.rb b/db/post_migrate/20230901064536_add_concurrent_index_for_ci_pipeline_chat_data_pipeline_id_convert_to_bigint.rb
new file mode 100644
index 00000000000..35b5fca789b
--- /dev/null
+++ b/db/post_migrate/20230901064536_add_concurrent_index_for_ci_pipeline_chat_data_pipeline_id_convert_to_bigint.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddConcurrentIndexForCiPipelineChatDataPipelineIdConvertToBigint < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = "index_ci_pipeline_chat_data_on_pipeline_id_convert_to_bigint"
+ TABLE_NAME = :ci_pipeline_chat_data
+ COLUMN_NAME = :pipeline_id_convert_to_bigint
+
+ def up
+ add_concurrent_index TABLE_NAME, COLUMN_NAME, name: INDEX_NAME, unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name TABLE_NAME, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230901064537_remove_namespace_details_dashboard_fields.rb b/db/post_migrate/20230901064537_remove_namespace_details_dashboard_fields.rb
new file mode 100644
index 00000000000..9dca08c90ef
--- /dev/null
+++ b/db/post_migrate/20230901064537_remove_namespace_details_dashboard_fields.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class RemoveNamespaceDetailsDashboardFields < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ def change
+ remove_column :namespace_details, :dashboard_notification_at, :datetime_with_timezone
+ remove_column :namespace_details, :dashboard_enforcement_at, :datetime_with_timezone
+ end
+end
diff --git a/db/post_migrate/20230902033401_create_async_index_for_ci_sources_pipelines_pipeline_id.rb b/db/post_migrate/20230902033401_create_async_index_for_ci_sources_pipelines_pipeline_id.rb
new file mode 100644
index 00000000000..60d26bf1962
--- /dev/null
+++ b/db/post_migrate/20230902033401_create_async_index_for_ci_sources_pipelines_pipeline_id.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class CreateAsyncIndexForCiSourcesPipelinesPipelineId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_sources_pipelines
+ INDEXES = {
+ 'index_ci_sources_pipelines_on_pipeline_id_bigint' => [
+ [:pipeline_id_convert_to_bigint], {}
+ ],
+ 'index_ci_sources_pipelines_on_source_pipeline_id_bigint' => [
+ [:source_pipeline_id_convert_to_bigint], {}
+ ]
+ }
+
+ def up
+ INDEXES.each do |index_name, (columns, options)|
+ prepare_async_index TABLE_NAME, columns, name: index_name, **options
+ end
+ end
+
+ def down
+ INDEXES.each do |index_name, (columns, options)|
+ unprepare_async_index TABLE_NAME, columns, name: index_name, **options
+ end
+ end
+end
diff --git a/db/post_migrate/20230902050458_create_async_index_for_ci_pipelines_auto_canceled_by_id.rb b/db/post_migrate/20230902050458_create_async_index_for_ci_pipelines_auto_canceled_by_id.rb
new file mode 100644
index 00000000000..4eb8ea918b8
--- /dev/null
+++ b/db/post_migrate/20230902050458_create_async_index_for_ci_pipelines_auto_canceled_by_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class CreateAsyncIndexForCiPipelinesAutoCanceledById < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_pipelines
+ INDEX_NAME = 'index_ci_pipelines_on_auto_canceled_by_id_bigint'
+ COLUMN_NAME = :auto_canceled_by_id_convert_to_bigint
+
+ def up
+ prepare_async_index TABLE_NAME, COLUMN_NAME, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index TABLE_NAME, COLUMN_NAME, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230902054536_ensure_backfill_for_ci_pipeline_messages_pipeline_id_is_finished.rb b/db/post_migrate/20230902054536_ensure_backfill_for_ci_pipeline_messages_pipeline_id_is_finished.rb
new file mode 100644
index 00000000000..41806f14c3d
--- /dev/null
+++ b/db/post_migrate/20230902054536_ensure_backfill_for_ci_pipeline_messages_pipeline_id_is_finished.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class EnsureBackfillForCiPipelineMessagesPipelineIdIsFinished < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_pipeline_messages
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: TABLE_NAME,
+ column_name: 'id',
+ job_arguments: [['pipeline_id'], ['pipeline_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230903064536_concurrent_index_for_ci_pipeline_messages_pipeline_id_convert_to_bigint.rb b/db/post_migrate/20230903064536_concurrent_index_for_ci_pipeline_messages_pipeline_id_convert_to_bigint.rb
new file mode 100644
index 00000000000..0444239d934
--- /dev/null
+++ b/db/post_migrate/20230903064536_concurrent_index_for_ci_pipeline_messages_pipeline_id_convert_to_bigint.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class ConcurrentIndexForCiPipelineMessagesPipelineIdConvertToBigint < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = "index_ci_pipeline_messages_on_pipeline_id_convert_to_bigint"
+ TABLE_NAME = :ci_pipeline_messages
+ COLUMN_NAME = :pipeline_id_convert_to_bigint
+
+ def up
+ add_concurrent_index TABLE_NAME, COLUMN_NAME, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230903064537_add_ci_job_artifacts_file_final_path_index.rb b/db/post_migrate/20230903064537_add_ci_job_artifacts_file_final_path_index.rb
new file mode 100644
index 00000000000..e1e5694f4d4
--- /dev/null
+++ b/db/post_migrate/20230903064537_add_ci_job_artifacts_file_final_path_index.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddCiJobArtifactsFileFinalPathIndex < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_job_artifacts_on_file_final_path'
+ WHERE_CLAUSE = 'file_final_path IS NOT NULL'
+
+ # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/423990
+ def up
+ prepare_async_index :ci_job_artifacts, :file_final_path, name: INDEX_NAME, where: WHERE_CLAUSE
+ end
+
+ def down
+ unprepare_async_index :ci_job_artifacts, :file_final_path, name: INDEX_NAME, where: WHERE_CLAUSE
+ end
+end
diff --git a/db/post_migrate/20230904100544_drop_index_deployments_on_id_where_cluster_id_present.rb b/db/post_migrate/20230904100544_drop_index_deployments_on_id_where_cluster_id_present.rb
new file mode 100644
index 00000000000..888fb7da9c3
--- /dev/null
+++ b/db/post_migrate/20230904100544_drop_index_deployments_on_id_where_cluster_id_present.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class DropIndexDeploymentsOnIdWhereClusterIdPresent < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_deployments_on_id_where_cluster_id_present'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :deployments, name: INDEX_NAME
+ end
+
+ def down
+ # This is based on the following `CREATE INDEX` command in db/init_structure.sql:
+ # CREATE INDEX index_deployments_on_id_where_cluster_id_present ON deployments
+ # USING btree (id) WHERE (cluster_id IS NOT NULL);
+ add_concurrent_index :deployments, :id, name: INDEX_NAME, where: 'cluster_id IS NOT NULL'
+ end
+end
diff --git a/db/post_migrate/20230904103804_drop_index_successful_deployments_on_cluster_id_and_environment_id.rb b/db/post_migrate/20230904103804_drop_index_successful_deployments_on_cluster_id_and_environment_id.rb
new file mode 100644
index 00000000000..e8f0a7b30b5
--- /dev/null
+++ b/db/post_migrate/20230904103804_drop_index_successful_deployments_on_cluster_id_and_environment_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class DropIndexSuccessfulDeploymentsOnClusterIdAndEnvironmentId < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_successful_deployments_on_cluster_id_and_environment_id'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :deployments, name: INDEX_NAME
+ end
+
+ def down
+ # This is based on the following `CREATE INDEX` command in db/init_structure.sql:
+ # CREATE INDEX index_successful_deployments_on_cluster_id_and_environment_id ON deployments
+ # USING btree (cluster_id, environment_id) WHERE (status = 2);
+ add_concurrent_index :deployments, %i[cluster_id environment_id], name: INDEX_NAME, where: 'status = 2'
+ end
+end
diff --git a/db/post_migrate/20230905071915_prepare_async_foreign_key_for_ci_pipeline_messages_pipeline_id_bigint.rb b/db/post_migrate/20230905071915_prepare_async_foreign_key_for_ci_pipeline_messages_pipeline_id_bigint.rb
new file mode 100644
index 00000000000..ce576704d4c
--- /dev/null
+++ b/db/post_migrate/20230905071915_prepare_async_foreign_key_for_ci_pipeline_messages_pipeline_id_bigint.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class PrepareAsyncForeignKeyForCiPipelineMessagesPipelineIdBigint < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_pipeline_messages
+ COLUMN_NAME = :pipeline_id_convert_to_bigint
+ FK_NAME = :fk_0946fea681
+
+ def up
+ prepare_async_foreign_key_validation TABLE_NAME, COLUMN_NAME, name: FK_NAME
+ end
+
+ def down
+ unprepare_async_foreign_key_validation TABLE_NAME, COLUMN_NAME, name: FK_NAME
+ end
+end
diff --git a/db/post_migrate/20230905091059_sync_index_for_ci_stages_pipeline_id_bigint.rb b/db/post_migrate/20230905091059_sync_index_for_ci_stages_pipeline_id_bigint.rb
new file mode 100644
index 00000000000..2c42782c576
--- /dev/null
+++ b/db/post_migrate/20230905091059_sync_index_for_ci_stages_pipeline_id_bigint.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class SyncIndexForCiStagesPipelineIdBigint < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_stages
+ INDEXES = {
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint_and_name' => [
+ [:pipeline_id_convert_to_bigint, :name], { unique: true }
+ ],
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint' => [
+ [:pipeline_id_convert_to_bigint], {}
+ ],
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint_and_id' => [
+ [:pipeline_id_convert_to_bigint, :id], { where: 'status = ANY (ARRAY[0, 1, 2, 8, 9, 10])' }
+ ],
+ 'index_ci_stages_on_pipeline_id_convert_to_bigint_and_position' => [
+ [:pipeline_id_convert_to_bigint, :position], {}
+ ]
+ }
+
+ def up
+ INDEXES.each do |index_name, (columns, options)|
+ add_concurrent_index TABLE_NAME, columns, name: index_name, **options
+ end
+ end
+
+ def down
+ INDEXES.each do |index_name, (_columns, _options)|
+ remove_concurrent_index_by_name TABLE_NAME, index_name
+ end
+ end
+end
diff --git a/db/post_migrate/20230906181457_add_index_to_violations_on_target_proj_id.rb b/db/post_migrate/20230906181457_add_index_to_violations_on_target_proj_id.rb
new file mode 100644
index 00000000000..13c76a3c2de
--- /dev/null
+++ b/db/post_migrate/20230906181457_add_index_to_violations_on_target_proj_id.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddIndexToViolationsOnTargetProjId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = 'merge_requests_compliance_violations'
+ # Use funciton based naming as suggested in docs:
+ # https://docs.gitlab.com/ee/development/migration_style_guide.html#truncate-long-index-names
+ INDEX_NAME = 'i_compliance_violations_for_export'
+
+ def up
+ prepare_async_index TABLE_NAME, [:target_project_id, :id], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index TABLE_NAME, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230907155247_queue_backfill_has_merge_request_of_vulnerability_reads.rb b/db/post_migrate/20230907155247_queue_backfill_has_merge_request_of_vulnerability_reads.rb
new file mode 100644
index 00000000000..fe939b4aaa0
--- /dev/null
+++ b/db/post_migrate/20230907155247_queue_backfill_has_merge_request_of_vulnerability_reads.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class QueueBackfillHasMergeRequestOfVulnerabilityReads < Gitlab::Database::Migration[2.1]
+ MIGRATION_NAME = 'BackfillHasMergeRequestOfVulnerabilityReads'
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 10_000
+ SUB_BATCH_SIZE = 200
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION_NAME,
+ :vulnerability_reads,
+ :vulnerability_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION_NAME, :vulnerability_reads, :vulnerability_id, [])
+ end
+end
diff --git a/db/post_migrate/20230907204731_add_index_to_sbom_occurrences_licenses.rb b/db/post_migrate/20230907204731_add_index_to_sbom_occurrences_licenses.rb
new file mode 100644
index 00000000000..9ed60941c96
--- /dev/null
+++ b/db/post_migrate/20230907204731_add_index_to_sbom_occurrences_licenses.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddIndexToSbomOccurrencesLicenses < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = "index_sbom_occurrences_on_licenses_spdx_identifier"
+
+ disable_ddl_transaction!
+
+ def up
+ return if index_exists_by_name?(:sbom_occurrences, INDEX_NAME)
+
+ disable_statement_timeout do
+ execute <<~SQL
+ CREATE INDEX CONCURRENTLY #{INDEX_NAME}
+ ON sbom_occurrences
+ USING BTREE (project_id, (licenses#>'{0,spdx_identifier}'), (licenses#>'{1,spdx_identifier}'))
+ SQL
+ end
+ end
+
+ def down
+ remove_concurrent_index_by_name :sbom_occurrences, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230908072558_analyze_p_ci_runner_machine_builds.rb b/db/post_migrate/20230908072558_analyze_p_ci_runner_machine_builds.rb
new file mode 100644
index 00000000000..5fb99640764
--- /dev/null
+++ b/db/post_migrate/20230908072558_analyze_p_ci_runner_machine_builds.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AnalyzePCiRunnerMachineBuilds < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ disable_statement_timeout do
+ execute('ANALYZE VERBOSE p_ci_runner_machine_builds;')
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230908072612_analyze_p_ci_job_annotations.rb b/db/post_migrate/20230908072612_analyze_p_ci_job_annotations.rb
new file mode 100644
index 00000000000..7bdc1dcb58d
--- /dev/null
+++ b/db/post_migrate/20230908072612_analyze_p_ci_job_annotations.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AnalyzePCiJobAnnotations < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ disable_statement_timeout do
+ execute('ANALYZE VERBOSE p_ci_job_annotations;')
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230908072626_analyze_p_ci_builds_metadata.rb b/db/post_migrate/20230908072626_analyze_p_ci_builds_metadata.rb
new file mode 100644
index 00000000000..4ba75d9e6bd
--- /dev/null
+++ b/db/post_migrate/20230908072626_analyze_p_ci_builds_metadata.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AnalyzePCiBuildsMetadata < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ disable_statement_timeout do
+ execute('ANALYZE VERBOSE p_ci_builds_metadata;')
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230908072639_analyze_p_ci_builds.rb b/db/post_migrate/20230908072639_analyze_p_ci_builds.rb
new file mode 100644
index 00000000000..f1c68b657b9
--- /dev/null
+++ b/db/post_migrate/20230908072639_analyze_p_ci_builds.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AnalyzePCiBuilds < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ disable_statement_timeout do
+ execute('ANALYZE VERBOSE p_ci_builds;')
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230909120000_queue_backfill_workspace_personal_access_token.rb b/db/post_migrate/20230909120000_queue_backfill_workspace_personal_access_token.rb
new file mode 100644
index 00000000000..5a746d97493
--- /dev/null
+++ b/db/post_migrate/20230909120000_queue_backfill_workspace_personal_access_token.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class QueueBackfillWorkspacePersonalAccessToken < Gitlab::Database::Migration[2.1]
+ MIGRATION = "BackfillWorkspacePersonalAccessToken"
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 100
+ SUB_BATCH_SIZE = 10
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :workspaces,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :workspaces, :id, [])
+ end
+end
diff --git a/db/post_migrate/20230913100953_create_supporting_index_for_uuid_type_casting.rb b/db/post_migrate/20230913100953_create_supporting_index_for_uuid_type_casting.rb
new file mode 100644
index 00000000000..232aca06bb2
--- /dev/null
+++ b/db/post_migrate/20230913100953_create_supporting_index_for_uuid_type_casting.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class CreateSupportingIndexForUuidTypeCasting < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :vulnerability_occurrences
+ INDEX_NAME = "tmp_index_vulnerability_occurrences_uuid_cast"
+
+ def up
+ index_sql = <<~SQL
+ CREATE INDEX CONCURRENTLY #{INDEX_NAME}
+ ON #{TABLE_NAME}((uuid::uuid))
+ SQL
+
+ # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/425037
+ prepare_async_index_from_sql(index_sql)
+ end
+
+ def down
+ unprepare_async_index_by_name(
+ TABLE_NAME,
+ INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230913115113_add_prepared_at_created_at_index_async.rb b/db/post_migrate/20230913115113_add_prepared_at_created_at_index_async.rb
new file mode 100644
index 00000000000..2e751463f8b
--- /dev/null
+++ b/db/post_migrate/20230913115113_add_prepared_at_created_at_index_async.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddPreparedAtCreatedAtIndexAsync < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_merge_requests_id_created_at_prepared_at'
+
+ def up
+ add_concurrent_index :merge_requests, [:created_at, :id], name: INDEX_NAME, where: "prepared_at IS NULL"
+ end
+
+ def down
+ remove_concurrent_index_by_name :merge_requests, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230913120111_remove_prepared_at_created_at_index_async.rb b/db/post_migrate/20230913120111_remove_prepared_at_created_at_index_async.rb
new file mode 100644
index 00000000000..8507ebfe1ec
--- /dev/null
+++ b/db/post_migrate/20230913120111_remove_prepared_at_created_at_index_async.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemovePreparedAtCreatedAtIndexAsync < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_merge_requests_on_id_and_prepared_at'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :merge_requests, name: INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :merge_requests, :id, name: INDEX_NAME, where: "prepared_at IS NULL"
+ end
+end
diff --git a/db/post_migrate/20230913130629_index_org_id_on_projects.rb b/db/post_migrate/20230913130629_index_org_id_on_projects.rb
new file mode 100644
index 00000000000..45186b900c6
--- /dev/null
+++ b/db/post_migrate/20230913130629_index_org_id_on_projects.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class IndexOrgIdOnProjects < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_projects_on_organization_id'
+
+ def up
+ add_concurrent_index :projects, :organization_id, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :projects, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230913175529_add_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb b/db/post_migrate/20230913175529_add_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb
new file mode 100644
index 00000000000..33fe6538f9b
--- /dev/null
+++ b/db/post_migrate/20230913175529_add_index_on_merge_requests_target_project_id_and_merged_commit_sha.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddIndexOnMergeRequestsTargetProjectIdAndMergedCommitSha < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_merge_requests_on_target_project_id_and_merged_commit_sha'
+ INDEX_COLUMNS = %i[target_project_id merged_commit_sha]
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :merge_requests, INDEX_COLUMNS, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :merge_requests, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230914054914_index_finding_id_for_vulnerabilities_sync.rb b/db/post_migrate/20230914054914_index_finding_id_for_vulnerabilities_sync.rb
new file mode 100644
index 00000000000..37cd13a4dfa
--- /dev/null
+++ b/db/post_migrate/20230914054914_index_finding_id_for_vulnerabilities_sync.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class IndexFindingIdForVulnerabilitiesSync < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_vulnerabilities_on_finding_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerabilities, :finding_id, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME
+ end
+end