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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
commitb595cb0c1dec83de5bdee18284abe86614bed33b (patch)
tree8c3d4540f193c5ff98019352f554e921b3a41a72 /db/post_migrate
parent2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff)
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20220523164734_add_foreign_key_to_vulnerability_reads_casted_cluster_agent_id.rb16
-rw-r--r--db/post_migrate/20220523165734_add_index_to_vulnerability_reads_casted_cluster_agent_id.rb15
-rw-r--r--db/post_migrate/20220531035113_populate_operation_visibility_permissions.rb29
-rw-r--r--db/post_migrate/20220601151900_schedule_backfill_ci_runner_semver.rb31
-rw-r--r--db/post_migrate/20220601152916_add_user_id_and_ip_address_success_index_to_authentication_events.rb18
-rw-r--r--db/post_migrate/20220606082910_add_tmp_index_for_potentially_misassociated_vulnerability_occurrences.rb20
-rw-r--r--db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb18
-rw-r--r--db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb18
-rw-r--r--db/post_migrate/20220617123105_drop_index_on_projects_on_runners_token.rb17
-rw-r--r--db/post_migrate/20220617123113_drop_index_on_projects_on_runners_token_encrypted.rb17
-rw-r--r--db/post_migrate/20220617142124_add_index_on_installable_package_files.rb20
-rw-r--r--db/post_migrate/20220617143228_replace_packages_index_on_project_id_and_status.rb22
-rw-r--r--db/post_migrate/20220620060633_finalize_orphaned_routes_cleanup.rb22
-rw-r--r--db/post_migrate/20220620132300_update_last_run_date_for_iterations_cadences.rb19
-rw-r--r--db/post_migrate/20220620151740_add_indexes_issues_on_project_id_and_closed_at.rb31
-rw-r--r--db/post_migrate/20220621040800_backfill_imported_issue_search_data.rb11
-rw-r--r--db/post_migrate/20220621082245_remove_tmp_index_on_routes_namespace_id_column.rb18
-rw-r--r--db/post_migrate/20220621092245_validate_not_null_constraint_on_routes_namespace_id_column.rb14
-rw-r--r--db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb22
-rw-r--r--db/post_migrate/20220622080547_backfill_project_statistics_with_container_registry_size.rb33
-rw-r--r--db/post_migrate/20220624062300_delete_backfill_ci_runner_semver_migration.rb19
-rw-r--r--db/post_migrate/20220627090231_schedule_disable_legacy_open_source_license_for_inactive_public_projects.rb33
-rw-r--r--db/post_migrate/20220627152642_queue_update_delayed_project_removal_to_null_for_user_namespace.rb25
-rw-r--r--db/post_migrate/20220627223041_add_post_migrate_test_table.rb13
-rw-r--r--db/post_migrate/20220628012902_finalise_project_namespace_members.rb22
-rw-r--r--db/post_migrate/20220628110823_add_issues_namespace_id_fk_and_index.rb22
-rw-r--r--db/post_migrate/20220628111752_drop_token_index_from_ci_builds.rb17
-rw-r--r--db/post_migrate/20220628122622_rename_builds_sidekiq_queues_to_namespaces.rb22
-rw-r--r--db/post_migrate/20220629184402_unset_escalation_policies_for_alert_incidents.rb46
-rw-r--r--db/post_migrate/20220630050050_index_vulnerability_reads_on_casted_cluster_agent_id_full.rb18
-rw-r--r--db/post_migrate/20220630085003_drop_project_successfull_pages_deploy_index_from_ci_builds.rb21
-rw-r--r--db/post_migrate/20220630091409_add_index_on_events_for_contribution_analytics_optimization.rb15
-rw-r--r--db/post_migrate/20220630151641_schedule_set_correct_vulnerability_state.rb29
-rw-r--r--db/post_migrate/20220701085523_schedule_index_on_events_for_contribution_analytics_optimization.rb13
-rw-r--r--db/post_migrate/20220703182314_add_check_constraint_for_security_findings_partition_number.rb15
-rw-r--r--db/post_migrate/20220704044408_remove_foreign_key_in_project_tracing_settings.rb16
-rw-r--r--db/post_migrate/20220704045440_drop_project_tracing_settings_table.rb17
-rw-r--r--db/post_migrate/20220705114635_drop_index_on_ci_runner_versions_on_version.rb15
-rw-r--r--db/post_migrate/20220705180843_validate_requirements_issue_id_not_null.rb15
-rw-r--r--db/post_migrate/20220706065245_remove_foreign_key_in_clusters_applications_elastic_stacks.rb16
-rw-r--r--db/post_migrate/20220706065611_remove_foreign_key_in_clusters_integration_elasticstack.rb16
-rw-r--r--db/post_migrate/20220706070804_drop_clusters_applications_elastic_stacks_table.rb17
-rw-r--r--db/post_migrate/20220706071304_drop_clusters_integration_elasticstack_table.rb22
-rw-r--r--db/post_migrate/20220706115138_create_async_index_on_security_findings.rb22
-rw-r--r--db/post_migrate/20220706122719_create_index_on_security_findings_uuid_id_desc.rb23
-rw-r--r--db/post_migrate/20220706132238_add_indices_on_security_scans_info_column.rb27
-rw-r--r--db/post_migrate/20220707075300_reschedule_backfill_imported_issue_search_data.rb35
-rw-r--r--db/post_migrate/20220708100508_drop_index_on_ci_runner_versions_on_status.rb15
-rw-r--r--db/post_migrate/20220713133515_cleanup_backfill_draft_statuses_on_merge_requests.rb15
-rw-r--r--db/post_migrate/20220714122311_add_async_index_on_security_findings_id_and_partition_number.rb15
-rw-r--r--db/post_migrate/20220714122418_add_async_index_on_security_findings_unique_columns.rb15
-rw-r--r--db/post_migrate/20220715054506_add_parent_link_unique_work_item_index.rb19
-rw-r--r--db/post_migrate/20220715160023_drop_post_migration_test_table.rb13
-rw-r--r--db/post_migrate/20220715163254_update_notes_in_past.rb22
54 files changed, 1096 insertions, 0 deletions
diff --git a/db/post_migrate/20220523164734_add_foreign_key_to_vulnerability_reads_casted_cluster_agent_id.rb b/db/post_migrate/20220523164734_add_foreign_key_to_vulnerability_reads_casted_cluster_agent_id.rb
new file mode 100644
index 00000000000..364570973ab
--- /dev/null
+++ b/db/post_migrate/20220523164734_add_foreign_key_to_vulnerability_reads_casted_cluster_agent_id.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToVulnerabilityReadsCastedClusterAgentId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :vulnerability_reads, :cluster_agents,
+ column: :casted_cluster_agent_id, on_delete: :nullify
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :vulnerability_reads, :cluster_agents, column: :casted_cluster_agent_id
+ end
+ end
+end
diff --git a/db/post_migrate/20220523165734_add_index_to_vulnerability_reads_casted_cluster_agent_id.rb b/db/post_migrate/20220523165734_add_index_to_vulnerability_reads_casted_cluster_agent_id.rb
new file mode 100644
index 00000000000..51842af3f12
--- /dev/null
+++ b/db/post_migrate/20220523165734_add_index_to_vulnerability_reads_casted_cluster_agent_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexToVulnerabilityReadsCastedClusterAgentId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_cis_vulnerability_reads_on_cluster_agent_id'
+
+ def up
+ add_concurrent_index :vulnerability_reads, :casted_cluster_agent_id, name: INDEX_NAME, where: 'report_type = 7'
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerability_reads, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220531035113_populate_operation_visibility_permissions.rb b/db/post_migrate/20220531035113_populate_operation_visibility_permissions.rb
new file mode 100644
index 00000000000..1d385b13f75
--- /dev/null
+++ b/db/post_migrate/20220531035113_populate_operation_visibility_permissions.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class PopulateOperationVisibilityPermissions < Gitlab::Database::Migration[2.0]
+ BATCH_SIZE = 50_000
+ MAX_BATCH_SIZE = 50_000
+ SUB_BATCH_SIZE = 1_000
+ INTERVAL = 2.minutes
+ MIGRATION = 'PopulateOperationVisibilityPermissionsFromOperations'
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :project_features,
+ :id,
+ job_interval: INTERVAL,
+ batch_size: BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :project_features, :id, [])
+ end
+end
diff --git a/db/post_migrate/20220601151900_schedule_backfill_ci_runner_semver.rb b/db/post_migrate/20220601151900_schedule_backfill_ci_runner_semver.rb
new file mode 100644
index 00000000000..9c62ec1b87b
--- /dev/null
+++ b/db/post_migrate/20220601151900_schedule_backfill_ci_runner_semver.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class ScheduleBackfillCiRunnerSemver < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ MIGRATION = 'BackfillCiRunnerSemver'
+ INTERVAL = 2.minutes.freeze
+ BATCH_SIZE = 500
+ MAX_BATCH_SIZE = 10_000
+ SUB_BATCH_SIZE = 100
+
+ disable_ddl_transaction!
+
+ def up
+ # Disabled background migration introduced in same milestone as it was decided to change approach
+ # and the semver column will no longer be needed
+ # queue_batched_background_migration(
+ # MIGRATION,
+ # :ci_runners,
+ # :id,
+ # job_interval: INTERVAL,
+ # batch_size: BATCH_SIZE,
+ # max_batch_size: MAX_BATCH_SIZE,
+ # sub_batch_size: SUB_BATCH_SIZE
+ # )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :ci_runners, :id, [])
+ end
+end
diff --git a/db/post_migrate/20220601152916_add_user_id_and_ip_address_success_index_to_authentication_events.rb b/db/post_migrate/20220601152916_add_user_id_and_ip_address_success_index_to_authentication_events.rb
new file mode 100644
index 00000000000..aa860959c20
--- /dev/null
+++ b/db/post_migrate/20220601152916_add_user_id_and_ip_address_success_index_to_authentication_events.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddUserIdAndIpAddressSuccessIndexToAuthenticationEvents < Gitlab::Database::Migration[2.0]
+ OLD_INDEX_NAME = 'index_authentication_events_on_user_id'
+ NEW_INDEX_NAME = 'index_authentication_events_on_user_and_ip_address_and_result'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :authentication_events, [:user_id, :ip_address, :result], name: NEW_INDEX_NAME
+ remove_concurrent_index_by_name :authentication_events, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :authentication_events, :user_id, name: OLD_INDEX_NAME
+ remove_concurrent_index_by_name :authentication_events, NEW_INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220606082910_add_tmp_index_for_potentially_misassociated_vulnerability_occurrences.rb b/db/post_migrate/20220606082910_add_tmp_index_for_potentially_misassociated_vulnerability_occurrences.rb
new file mode 100644
index 00000000000..1207b51f190
--- /dev/null
+++ b/db/post_migrate/20220606082910_add_tmp_index_for_potentially_misassociated_vulnerability_occurrences.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddTmpIndexForPotentiallyMisassociatedVulnerabilityOccurrences < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = "tmp_index_vulnerability_occurrences_on_id_and_scanner_id"
+ REPORT_TYPES = { cluster_image_scanning: 7, generic: 99 }.freeze
+ CLAUSE = "report_type IN (#{REPORT_TYPES.values.join(',')})"
+
+ disable_ddl_transaction!
+
+ def up
+ prepare_async_index :vulnerability_occurrences,
+ [:id, :scanner_id],
+ where: CLAUSE,
+ name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index_by_name :vulnerability_occurrences, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb b/db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb
new file mode 100644
index 00000000000..1e0409b16ea
--- /dev/null
+++ b/db/post_migrate/20220617123022_add_unique_index_on_projects_on_runners_token.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexOnProjectsOnRunnersToken < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_uniq_projects_on_runners_token'
+
+ def up
+ add_concurrent_index :projects,
+ :runners_token,
+ name: INDEX_NAME,
+ unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name :projects, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb b/db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb
new file mode 100644
index 00000000000..b9ba570606e
--- /dev/null
+++ b/db/post_migrate/20220617123034_add_unique_index_on_projects_on_runners_token_encrypted.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddUniqueIndexOnProjectsOnRunnersTokenEncrypted < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_uniq_projects_on_runners_token_encrypted'
+
+ def up
+ add_concurrent_index :projects,
+ :runners_token_encrypted,
+ name: INDEX_NAME,
+ unique: true
+ end
+
+ def down
+ remove_concurrent_index_by_name :projects, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220617123105_drop_index_on_projects_on_runners_token.rb b/db/post_migrate/20220617123105_drop_index_on_projects_on_runners_token.rb
new file mode 100644
index 00000000000..6b76a92a9f4
--- /dev/null
+++ b/db/post_migrate/20220617123105_drop_index_on_projects_on_runners_token.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropIndexOnProjectsOnRunnersToken < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_projects_on_runners_token'
+
+ def up
+ remove_concurrent_index_by_name :projects, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :projects,
+ :runners_token,
+ name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220617123113_drop_index_on_projects_on_runners_token_encrypted.rb b/db/post_migrate/20220617123113_drop_index_on_projects_on_runners_token_encrypted.rb
new file mode 100644
index 00000000000..213f55bfcc4
--- /dev/null
+++ b/db/post_migrate/20220617123113_drop_index_on_projects_on_runners_token_encrypted.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropIndexOnProjectsOnRunnersTokenEncrypted < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_projects_on_runners_token_encrypted'
+
+ def up
+ remove_concurrent_index_by_name :projects, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :projects,
+ :runners_token_encrypted,
+ name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220617142124_add_index_on_installable_package_files.rb b/db/post_migrate/20220617142124_add_index_on_installable_package_files.rb
new file mode 100644
index 00000000000..e74c6c0935e
--- /dev/null
+++ b/db/post_migrate/20220617142124_add_index_on_installable_package_files.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddIndexOnInstallablePackageFiles < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'idx_pkgs_installable_package_files_on_package_id_id_file_name'
+ # See https://gitlab.com/gitlab-org/gitlab/-/blob/e3ed2c1f65df2e137fc714485d7d42264a137968/app/models/packages/package_file.rb#L16
+ DEFAULT_STATUS = 0
+
+ def up
+ add_concurrent_index :packages_package_files,
+ [:package_id, :id, :file_name],
+ where: "(status = #{DEFAULT_STATUS})",
+ name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :packages_package_files, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220617143228_replace_packages_index_on_project_id_and_status.rb b/db/post_migrate/20220617143228_replace_packages_index_on_project_id_and_status.rb
new file mode 100644
index 00000000000..d1e70f04468
--- /dev/null
+++ b/db/post_migrate/20220617143228_replace_packages_index_on_project_id_and_status.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class ReplacePackagesIndexOnProjectIdAndStatus < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ NEW_INDEX_NAME = 'index_packages_packages_on_project_id_and_status_and_id'
+ OLD_INDEX_NAME = 'index_packages_packages_on_project_id_and_status'
+
+ def up
+ add_concurrent_index :packages_packages,
+ [:project_id, :status, :id],
+ name: NEW_INDEX_NAME
+ remove_concurrent_index_by_name :packages_packages, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :packages_packages,
+ [:project_id, :status],
+ name: OLD_INDEX_NAME
+ remove_concurrent_index_by_name :packages_packages, NEW_INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220620060633_finalize_orphaned_routes_cleanup.rb b/db/post_migrate/20220620060633_finalize_orphaned_routes_cleanup.rb
new file mode 100644
index 00000000000..4a3218af2c0
--- /dev/null
+++ b/db/post_migrate/20220620060633_finalize_orphaned_routes_cleanup.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class FinalizeOrphanedRoutesCleanup < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'CleanupOrphanedRoutes'
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :routes,
+ column_name: :id,
+ job_arguments: []
+ )
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20220620132300_update_last_run_date_for_iterations_cadences.rb b/db/post_migrate/20220620132300_update_last_run_date_for_iterations_cadences.rb
new file mode 100644
index 00000000000..50b0b25d469
--- /dev/null
+++ b/db/post_migrate/20220620132300_update_last_run_date_for_iterations_cadences.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class UpdateLastRunDateForIterationsCadences < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ execute <<~SQL
+ UPDATE iterations_cadences SET last_run_date=CURRENT_DATE WHERE automatic=true;
+ SQL
+ end
+
+ def down
+ # no op
+ # 'last_run_date' stores the date on which the cadence record should be
+ # updated using `CreateIterationsInAdvance` service that is idempotent
+ # and the column is only useful for optimizing when to run the service
+ # ('last_run_date' is also a misnomer as it can be better-named 'next_run_date'.)
+ end
+end
diff --git a/db/post_migrate/20220620151740_add_indexes_issues_on_project_id_and_closed_at.rb b/db/post_migrate/20220620151740_add_indexes_issues_on_project_id_and_closed_at.rb
new file mode 100644
index 00000000000..066e72dce45
--- /dev/null
+++ b/db/post_migrate/20220620151740_add_indexes_issues_on_project_id_and_closed_at.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class AddIndexesIssuesOnProjectIdAndClosedAt < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ OLD_INDEX_NAME = 'index_issues_on_project_id_and_closed_at'
+ NEW_INDEX_NAME_1 = 'index_issues_on_project_id_closed_at_desc_state_id_and_id'
+ NEW_INDEX_NAME_2 = 'index_issues_on_project_id_closed_at_state_id_and_id'
+
+ def up
+ # Index to improve performance when sorting issues by closed_at desc
+ unless index_exists_by_name?(:issues, NEW_INDEX_NAME_1)
+ add_concurrent_index :issues, 'project_id, closed_at DESC NULLS LAST, state_id, id', name: NEW_INDEX_NAME_1
+ end
+
+ # Index to improve performance when sorting issues by closed_at asc
+ # This replaces the old index which didn't account for state_id and id
+ unless index_exists_by_name?(:issues, NEW_INDEX_NAME_2)
+ add_concurrent_index :issues, [:project_id, :closed_at, :state_id, :id], name: NEW_INDEX_NAME_2
+ end
+
+ remove_concurrent_index_by_name :issues, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :issues, [:project_id, :closed_at], name: OLD_INDEX_NAME
+
+ remove_concurrent_index_by_name :issues, NEW_INDEX_NAME_1
+ remove_concurrent_index_by_name :issues, NEW_INDEX_NAME_2
+ end
+end
diff --git a/db/post_migrate/20220621040800_backfill_imported_issue_search_data.rb b/db/post_migrate/20220621040800_backfill_imported_issue_search_data.rb
new file mode 100644
index 00000000000..bc7d0eb3a13
--- /dev/null
+++ b/db/post_migrate/20220621040800_backfill_imported_issue_search_data.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class BackfillImportedIssueSearchData < Gitlab::Database::Migration[2.0]
+ def up
+ # replaced by 20220707075300_reschedule_backfill_imported_issue_search_data.rb
+ end
+
+ def down
+ # replaced by 20220707075300_reschedule_backfill_imported_issue_search_data.rb
+ end
+end
diff --git a/db/post_migrate/20220621082245_remove_tmp_index_on_routes_namespace_id_column.rb b/db/post_migrate/20220621082245_remove_tmp_index_on_routes_namespace_id_column.rb
new file mode 100644
index 00000000000..4aa125d3c14
--- /dev/null
+++ b/db/post_migrate/20220621082245_remove_tmp_index_on_routes_namespace_id_column.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveTmpIndexOnRoutesNamespaceIdColumn < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'tmp_index_for_namespace_id_migration_on_routes'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :routes, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :routes,
+ :id,
+ where: "routes.namespace_id is null and routes.source_type = 'Namespace'",
+ name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220621092245_validate_not_null_constraint_on_routes_namespace_id_column.rb b/db/post_migrate/20220621092245_validate_not_null_constraint_on_routes_namespace_id_column.rb
new file mode 100644
index 00000000000..73e2f6b2b38
--- /dev/null
+++ b/db/post_migrate/20220621092245_validate_not_null_constraint_on_routes_namespace_id_column.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class ValidateNotNullConstraintOnRoutesNamespaceIdColumn < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ validate_not_null_constraint :routes, :namespace_id
+ end
+
+ def down
+ remove_not_null_constraint :routes, :namespace_id
+ add_not_null_constraint :routes, :namespace_id, validate: false
+ end
+end
diff --git a/db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb b/db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb
new file mode 100644
index 00000000000..64cdd75f5a7
--- /dev/null
+++ b/db/post_migrate/20220622070547_add_temp_index_for_container_registry_size_migration.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddTempIndexForContainerRegistrySizeMigration < Gitlab::Database::Migration[2.0]
+ INDEX_CONTAINER_REGISTRY_SIZE = 'tmp_index_migrated_container_registries'
+ INDEX_PROJECT_STATS_CONT_REG_SIZE = 'tmp_index_project_statistics_cont_registry_size'
+
+ disable_ddl_transaction!
+
+ def up
+ # Temporary index used in 20220622080547_backfill_project_statistics_with_container_registry_size
+ # Temporary index to be remove via https://gitlab.com/gitlab-org/gitlab/-/issues/366392
+ add_concurrent_index :container_repositories, [:project_id], name: INDEX_CONTAINER_REGISTRY_SIZE,
+ where: "migration_state = 'import_done' OR created_at >= '2022-01-23'"
+ add_concurrent_index :project_statistics, [:project_id], name: INDEX_PROJECT_STATS_CONT_REG_SIZE,
+ where: "container_registry_size = 0"
+ end
+
+ def down
+ remove_concurrent_index_by_name :container_repositories, INDEX_CONTAINER_REGISTRY_SIZE
+ remove_concurrent_index_by_name :project_statistics, INDEX_PROJECT_STATS_CONT_REG_SIZE
+ end
+end
diff --git a/db/post_migrate/20220622080547_backfill_project_statistics_with_container_registry_size.rb b/db/post_migrate/20220622080547_backfill_project_statistics_with_container_registry_size.rb
new file mode 100644
index 00000000000..2cab7ae25f5
--- /dev/null
+++ b/db/post_migrate/20220622080547_backfill_project_statistics_with_container_registry_size.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class BackfillProjectStatisticsWithContainerRegistrySize < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 500
+ MIGRATION_CLASS = 'BackfillProjectStatisticsContainerRepositorySize'
+ BATCH_CLASS_NAME = 'BackfillProjectStatisticsWithContainerRegistrySizeBatchingStrategy'
+ SUB_BATCH_SIZE = 100
+
+ disable_ddl_transaction!
+
+ def up
+ return unless Gitlab.dev_or_test_env? || Gitlab.com?
+
+ queue_batched_background_migration(
+ MIGRATION_CLASS,
+ :container_repositories,
+ :project_id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ batch_class_name: BATCH_CLASS_NAME,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ return unless Gitlab.dev_or_test_env? || Gitlab.com?
+
+ delete_batched_background_migration(MIGRATION_CLASS, :container_repositories, :project_id, [])
+ end
+end
diff --git a/db/post_migrate/20220624062300_delete_backfill_ci_runner_semver_migration.rb b/db/post_migrate/20220624062300_delete_backfill_ci_runner_semver_migration.rb
new file mode 100644
index 00000000000..4632d9104ea
--- /dev/null
+++ b/db/post_migrate/20220624062300_delete_backfill_ci_runner_semver_migration.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class DeleteBackfillCiRunnerSemverMigration < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ MIGRATION = 'BackfillCiRunnerSemver'
+
+ disable_ddl_transaction!
+
+ def up
+ # Disabled background migration introduced in same milestone as it was decided to change approach
+ # and the semver column will no longer be needed
+ delete_batched_background_migration(MIGRATION, :ci_runners, :id, [])
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20220627090231_schedule_disable_legacy_open_source_license_for_inactive_public_projects.rb b/db/post_migrate/20220627090231_schedule_disable_legacy_open_source_license_for_inactive_public_projects.rb
new file mode 100644
index 00000000000..06bdb78698d
--- /dev/null
+++ b/db/post_migrate/20220627090231_schedule_disable_legacy_open_source_license_for_inactive_public_projects.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class ScheduleDisableLegacyOpenSourceLicenseForInactivePublicProjects < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'DisableLegacyOpenSourceLicenseForInactivePublicProjects'
+ INTERVAL = 2.minutes
+ BATCH_SIZE = 1_000
+ MAX_BATCH_SIZE = 5_000
+ SUB_BATCH_SIZE = 200
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ return unless Gitlab.com?
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :projects,
+ :id,
+ job_interval: INTERVAL,
+ batch_size: BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ return unless Gitlab.com?
+
+ delete_batched_background_migration(MIGRATION, :projects, :id, [])
+ end
+end
diff --git a/db/post_migrate/20220627152642_queue_update_delayed_project_removal_to_null_for_user_namespace.rb b/db/post_migrate/20220627152642_queue_update_delayed_project_removal_to_null_for_user_namespace.rb
new file mode 100644
index 00000000000..2f407b78b6d
--- /dev/null
+++ b/db/post_migrate/20220627152642_queue_update_delayed_project_removal_to_null_for_user_namespace.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class QueueUpdateDelayedProjectRemovalToNullForUserNamespace < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'UpdateDelayedProjectRemovalToNullForUserNamespaces'
+ INTERVAL = 2.minutes
+ BATCH_SIZE = 10_000
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :namespace_settings,
+ :namespace_id,
+ job_interval: INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :namespace_settings, :namespace_id, [])
+ end
+end
diff --git a/db/post_migrate/20220627223041_add_post_migrate_test_table.rb b/db/post_migrate/20220627223041_add_post_migrate_test_table.rb
new file mode 100644
index 00000000000..8d97444f8c1
--- /dev/null
+++ b/db/post_migrate/20220627223041_add_post_migrate_test_table.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddPostMigrateTestTable < Gitlab::Database::Migration[2.0]
+ # Fake table to be used for testing the post-deploy pipeline,
+ # details can be seen on https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/2352.
+ #
+ # It should be deleted after the testing is completed.
+ def change
+ create_table :post_migration_test_table do |t|
+ t.integer :status, null: false
+ end
+ end
+end
diff --git a/db/post_migrate/20220628012902_finalise_project_namespace_members.rb b/db/post_migrate/20220628012902_finalise_project_namespace_members.rb
new file mode 100644
index 00000000000..29b11fb4357
--- /dev/null
+++ b/db/post_migrate/20220628012902_finalise_project_namespace_members.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class FinaliseProjectNamespaceMembers < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'BackfillProjectMemberNamespaceId'
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :members,
+ column_name: :id,
+ job_arguments: [],
+ finalize: true
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20220628110823_add_issues_namespace_id_fk_and_index.rb b/db/post_migrate/20220628110823_add_issues_namespace_id_fk_and_index.rb
new file mode 100644
index 00000000000..5a7ca428383
--- /dev/null
+++ b/db/post_migrate/20220628110823_add_issues_namespace_id_fk_and_index.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class AddIssuesNamespaceIdFkAndIndex < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+ INDEX_NAME = 'index_issues_on_namespace_id'
+
+ def up
+ add_concurrent_index :issues, :namespace_id, name: INDEX_NAME
+ add_concurrent_foreign_key :issues, :namespaces,
+ column: :namespace_id,
+ on_delete: :nullify,
+ reverse_lock_order: true
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists :issues, column: :namespace_id
+ end
+
+ remove_concurrent_index_by_name :issues, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220628111752_drop_token_index_from_ci_builds.rb b/db/post_migrate/20220628111752_drop_token_index_from_ci_builds.rb
new file mode 100644
index 00000000000..d551eeebeb6
--- /dev/null
+++ b/db/post_migrate/20220628111752_drop_token_index_from_ci_builds.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropTokenIndexFromCiBuilds < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_builds_on_token_partial'
+
+ def up
+ remove_concurrent_index_by_name :ci_builds, INDEX_NAME
+ end
+
+ # rubocop:disable Migration/PreventIndexCreation
+ def down
+ add_concurrent_index :ci_builds, :token, unique: true, where: 'token IS NOT NULL', name: INDEX_NAME
+ end
+ # rubocop:enable Migration/PreventIndexCreation
+end
diff --git a/db/post_migrate/20220628122622_rename_builds_sidekiq_queues_to_namespaces.rb b/db/post_migrate/20220628122622_rename_builds_sidekiq_queues_to_namespaces.rb
new file mode 100644
index 00000000000..f692d1476ce
--- /dev/null
+++ b/db/post_migrate/20220628122622_rename_builds_sidekiq_queues_to_namespaces.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class RenameBuildsSidekiqQueuesToNamespaces < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ BUILD_OLD_QUEUE = 'pipeline_processing:build_finished'
+ BUILD_NEW_QUEUE = 'pipeline_processing:ci_build_finished'
+
+ TRACE_OLD_QUEUE = 'pipeline_background:archive_trace'
+ TRACE_NEW_QUEUE = 'pipeline_background:ci_archive_trace'
+
+ def up
+ sidekiq_queue_migrate BUILD_OLD_QUEUE, to: BUILD_NEW_QUEUE
+ sidekiq_queue_migrate TRACE_OLD_QUEUE, to: TRACE_NEW_QUEUE
+ end
+
+ def down
+ sidekiq_queue_migrate BUILD_NEW_QUEUE, to: BUILD_OLD_QUEUE
+ sidekiq_queue_migrate TRACE_NEW_QUEUE, to: TRACE_OLD_QUEUE
+ end
+end
diff --git a/db/post_migrate/20220629184402_unset_escalation_policies_for_alert_incidents.rb b/db/post_migrate/20220629184402_unset_escalation_policies_for_alert_incidents.rb
new file mode 100644
index 00000000000..89adc4b2703
--- /dev/null
+++ b/db/post_migrate/20220629184402_unset_escalation_policies_for_alert_incidents.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+class UnsetEscalationPoliciesForAlertIncidents < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ class EscalationStatus < MigrationRecord
+ include EachBatch
+
+ self.table_name = 'incident_management_issuable_escalation_statuses'
+
+ scope :having_alert_policy, -> do
+ joins(
+ 'INNER JOIN alert_management_alerts ' \
+ 'ON alert_management_alerts.issue_id ' \
+ '= incident_management_issuable_escalation_statuses.issue_id'
+ )
+ end
+ end
+
+ def up
+ EscalationStatus.each_batch do |escalation_statuses|
+ escalation_statuses
+ .where.not(policy_id: nil)
+ .having_alert_policy
+ .update_all(policy_id: nil, escalations_started_at: nil)
+ end
+ end
+
+ def down
+ # no-op
+ #
+ # We cannot retrieve the exact nullified values. We could
+ # approximately guess what the values are via the alert's
+ # escalation policy. However, that may not be accurate
+ # in all cases, as an alert's escalation policy is implictly
+ # inferred from the project rather than explicit, like an incident.
+ # So we won't backfill potentially incorrect data.
+ #
+ # This data is functionally safe to delete, as the relevant
+ # fields are read-only, and exclusively informational.
+ #
+ # Re-running the migration will have no effect.
+ end
+end
diff --git a/db/post_migrate/20220630050050_index_vulnerability_reads_on_casted_cluster_agent_id_full.rb b/db/post_migrate/20220630050050_index_vulnerability_reads_on_casted_cluster_agent_id_full.rb
new file mode 100644
index 00000000000..58b6342e30f
--- /dev/null
+++ b/db/post_migrate/20220630050050_index_vulnerability_reads_on_casted_cluster_agent_id_full.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class IndexVulnerabilityReadsOnCastedClusterAgentIdFull < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_vuln_reads_on_casted_cluster_agent_id_where_it_is_null'
+
+ def up
+ add_concurrent_index :vulnerability_reads,
+ :casted_cluster_agent_id,
+ name: INDEX_NAME,
+ where: 'casted_cluster_agent_id IS NOT NULL'
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerability_reads, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220630085003_drop_project_successfull_pages_deploy_index_from_ci_builds.rb b/db/post_migrate/20220630085003_drop_project_successfull_pages_deploy_index_from_ci_builds.rb
new file mode 100644
index 00000000000..0810419a4e8
--- /dev/null
+++ b/db/post_migrate/20220630085003_drop_project_successfull_pages_deploy_index_from_ci_builds.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class DropProjectSuccessfullPagesDeployIndexFromCiBuilds < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_builds_on_project_id_for_successfull_pages_deploy'
+
+ def up
+ remove_concurrent_index_by_name :ci_builds, INDEX_NAME
+ end
+
+ # rubocop:disable Migration/PreventIndexCreation
+ def down
+ add_concurrent_index :ci_builds,
+ :project_id,
+ where: "(((type)::text = 'GenericCommitStatus'::text) AND ((stage)::text = 'deploy'::text) AND " \
+ "((name)::text = 'pages:deploy'::text) AND ((status)::text = 'success'::text))",
+ name: INDEX_NAME
+ end
+ # rubocop:enable Migration/PreventIndexCreation
+end
diff --git a/db/post_migrate/20220630091409_add_index_on_events_for_contribution_analytics_optimization.rb b/db/post_migrate/20220630091409_add_index_on_events_for_contribution_analytics_optimization.rb
new file mode 100644
index 00000000000..de16b17f489
--- /dev/null
+++ b/db/post_migrate/20220630091409_add_index_on_events_for_contribution_analytics_optimization.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexOnEventsForContributionAnalyticsOptimization < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_on_events_to_improve_contribution_analytics_performance'
+
+ def up
+ add_concurrent_index :events, [:project_id, :target_type, :action, :created_at, :author_id, :id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :events, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220630151641_schedule_set_correct_vulnerability_state.rb b/db/post_migrate/20220630151641_schedule_set_correct_vulnerability_state.rb
new file mode 100644
index 00000000000..7c9211ff282
--- /dev/null
+++ b/db/post_migrate/20220630151641_schedule_set_correct_vulnerability_state.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class ScheduleSetCorrectVulnerabilityState < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MAX_BATCH_SIZE = 5_000
+ JOB_INTERVAL = 2.minutes
+ MIGRATION_NAME = 'SetCorrectVulnerabilityState'
+ BATCH_CLASS_NAME = 'DismissedVulnerabilitiesStrategy'
+ SUB_BATCH_SIZE = 100
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION_NAME,
+ :vulnerabilities,
+ :id,
+ job_interval: JOB_INTERVAL,
+ batch_size: MAX_BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE,
+ batch_class_name: BATCH_CLASS_NAME,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION_NAME, :vulnerabilities, :id, [])
+ end
+end
diff --git a/db/post_migrate/20220701085523_schedule_index_on_events_for_contribution_analytics_optimization.rb b/db/post_migrate/20220701085523_schedule_index_on_events_for_contribution_analytics_optimization.rb
new file mode 100644
index 00000000000..10be7a25965
--- /dev/null
+++ b/db/post_migrate/20220701085523_schedule_index_on_events_for_contribution_analytics_optimization.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ScheduleIndexOnEventsForContributionAnalyticsOptimization < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_on_events_to_improve_contribution_analytics_performance'
+
+ def up
+ prepare_async_index :events, [:project_id, :target_type, :action, :created_at, :author_id, :id], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :events, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220703182314_add_check_constraint_for_security_findings_partition_number.rb b/db/post_migrate/20220703182314_add_check_constraint_for_security_findings_partition_number.rb
new file mode 100644
index 00000000000..82b5d0b165d
--- /dev/null
+++ b/db/post_migrate/20220703182314_add_check_constraint_for_security_findings_partition_number.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddCheckConstraintForSecurityFindingsPartitionNumber < Gitlab::Database::Migration[2.0]
+ CONSTRAINT_NAME = 'check_partition_number'
+
+ disable_ddl_transaction!
+
+ def up
+ add_check_constraint(:security_findings, 'partition_number = 1', CONSTRAINT_NAME)
+ end
+
+ def down
+ remove_check_constraint(:security_findings, CONSTRAINT_NAME)
+ end
+end
diff --git a/db/post_migrate/20220704044408_remove_foreign_key_in_project_tracing_settings.rb b/db/post_migrate/20220704044408_remove_foreign_key_in_project_tracing_settings.rb
new file mode 100644
index 00000000000..95eb461238f
--- /dev/null
+++ b/db/post_migrate/20220704044408_remove_foreign_key_in_project_tracing_settings.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeyInProjectTracingSettings < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:project_tracing_settings, column: :project_id)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :project_tracing_settings, :projects,
+ column: :project_id, on_delete: :cascade, name: 'fk_rails_fe56f57fc6'
+ end
+end
diff --git a/db/post_migrate/20220704045440_drop_project_tracing_settings_table.rb b/db/post_migrate/20220704045440_drop_project_tracing_settings_table.rb
new file mode 100644
index 00000000000..1ce8b05a08d
--- /dev/null
+++ b/db/post_migrate/20220704045440_drop_project_tracing_settings_table.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropProjectTracingSettingsTable < Gitlab::Database::Migration[2.0]
+ def up
+ drop_table :project_tracing_settings
+ end
+
+ def down
+ create_table :project_tracing_settings, id: :bigserial do |t|
+ t.timestamps_with_timezone null: false
+
+ t.references :project, type: :integer, null: false, index: { unique: true }
+
+ t.string :external_url, null: false
+ end
+ end
+end
diff --git a/db/post_migrate/20220705114635_drop_index_on_ci_runner_versions_on_version.rb b/db/post_migrate/20220705114635_drop_index_on_ci_runner_versions_on_version.rb
new file mode 100644
index 00000000000..22ff65f6fc3
--- /dev/null
+++ b/db/post_migrate/20220705114635_drop_index_on_ci_runner_versions_on_version.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DropIndexOnCiRunnerVersionsOnVersion < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_runner_versions_on_version'
+
+ def up
+ remove_concurrent_index_by_name :ci_runner_versions, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :ci_runner_versions, :version, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220705180843_validate_requirements_issue_id_not_null.rb b/db/post_migrate/20220705180843_validate_requirements_issue_id_not_null.rb
new file mode 100644
index 00000000000..a0c8954b481
--- /dev/null
+++ b/db/post_migrate/20220705180843_validate_requirements_issue_id_not_null.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class ValidateRequirementsIssueIdNotNull < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ constraint_name = 'check_requirement_issue_not_null'
+
+ validate_not_null_constraint(:requirements, :issue_id, constraint_name: constraint_name)
+ end
+
+ def down
+ # No op
+ end
+end
diff --git a/db/post_migrate/20220706065245_remove_foreign_key_in_clusters_applications_elastic_stacks.rb b/db/post_migrate/20220706065245_remove_foreign_key_in_clusters_applications_elastic_stacks.rb
new file mode 100644
index 00000000000..bfe60099bfa
--- /dev/null
+++ b/db/post_migrate/20220706065245_remove_foreign_key_in_clusters_applications_elastic_stacks.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeyInClustersApplicationsElasticStacks < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:clusters_applications_elastic_stacks, column: :cluster_id)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :clusters_applications_elastic_stacks, :clusters,
+ column: :cluster_id, on_delete: :cascade, name: 'fk_rails_026f219f46'
+ end
+end
diff --git a/db/post_migrate/20220706065611_remove_foreign_key_in_clusters_integration_elasticstack.rb b/db/post_migrate/20220706065611_remove_foreign_key_in_clusters_integration_elasticstack.rb
new file mode 100644
index 00000000000..eeec465f6b9
--- /dev/null
+++ b/db/post_migrate/20220706065611_remove_foreign_key_in_clusters_integration_elasticstack.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeyInClustersIntegrationElasticstack < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:clusters_integration_elasticstack, column: :cluster_id)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :clusters_integration_elasticstack, :clusters,
+ column: :cluster_id, on_delete: :cascade, name: 'fk_rails_cc5ba8f658'
+ end
+end
diff --git a/db/post_migrate/20220706070804_drop_clusters_applications_elastic_stacks_table.rb b/db/post_migrate/20220706070804_drop_clusters_applications_elastic_stacks_table.rb
new file mode 100644
index 00000000000..cedf666e428
--- /dev/null
+++ b/db/post_migrate/20220706070804_drop_clusters_applications_elastic_stacks_table.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropClustersApplicationsElasticStacksTable < Gitlab::Database::Migration[2.0]
+ def up
+ drop_table :clusters_applications_elastic_stacks
+ end
+
+ def down
+ create_table :clusters_applications_elastic_stacks do |t|
+ t.timestamps_with_timezone null: false
+ t.references :cluster, type: :bigint, null: false, index: { unique: true }
+ t.integer :status, null: false
+ t.string :version, null: false, limit: 255
+ t.text :status_reason
+ end
+ end
+end
diff --git a/db/post_migrate/20220706071304_drop_clusters_integration_elasticstack_table.rb b/db/post_migrate/20220706071304_drop_clusters_integration_elasticstack_table.rb
new file mode 100644
index 00000000000..206652b5dcf
--- /dev/null
+++ b/db/post_migrate/20220706071304_drop_clusters_integration_elasticstack_table.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class DropClustersIntegrationElasticstackTable < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_clusters_integration_elasticstack_enabled'
+
+ def up
+ drop_table :clusters_integration_elasticstack
+ end
+
+ def down
+ create_table :clusters_integration_elasticstack, id: false do |t|
+ t.timestamps_with_timezone null: false
+ t.references :cluster, primary_key: true, type: :bigint, default: nil, index: false
+ t.boolean :enabled, null: false, default: false
+ t.text :chart_version, limit: 10
+ end
+
+ add_concurrent_index(:clusters_integration_elasticstack, [:enabled, :created_at, :cluster_id], name: INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20220706115138_create_async_index_on_security_findings.rb b/db/post_migrate/20220706115138_create_async_index_on_security_findings.rb
new file mode 100644
index 00000000000..30baa1af91c
--- /dev/null
+++ b/db/post_migrate/20220706115138_create_async_index_on_security_findings.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class CreateAsyncIndexOnSecurityFindings < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_on_security_findings_uuid_and_id_order_desc'
+
+ def up
+ prepare_async_index(
+ :security_findings,
+ %i[uuid id],
+ order: { id: :desc },
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ unprepare_async_index(
+ :security_findings,
+ %i[uuid id],
+ name: INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20220706122719_create_index_on_security_findings_uuid_id_desc.rb b/db/post_migrate/20220706122719_create_index_on_security_findings_uuid_id_desc.rb
new file mode 100644
index 00000000000..0c2e2cb4b70
--- /dev/null
+++ b/db/post_migrate/20220706122719_create_index_on_security_findings_uuid_id_desc.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class CreateIndexOnSecurityFindingsUuidIdDesc < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_on_security_findings_uuid_and_id_order_desc'
+
+ def up
+ add_concurrent_index(
+ :security_findings,
+ %i[uuid id],
+ order: { id: :desc },
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name(
+ :security_findings,
+ INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20220706132238_add_indices_on_security_scans_info_column.rb b/db/post_migrate/20220706132238_add_indices_on_security_scans_info_column.rb
new file mode 100644
index 00000000000..48dc5b5d84a
--- /dev/null
+++ b/db/post_migrate/20220706132238_add_indices_on_security_scans_info_column.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class AddIndicesOnSecurityScansInfoColumn < Gitlab::Database::Migration[2.0]
+ INDEX_NAME_ON_ERRORS = :index_security_scans_on_length_of_errors
+ INDEX_NAME_ON_WARNINGS = :index_security_scans_on_length_of_warnings
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(
+ :security_scans,
+ "pipeline_id, jsonb_array_length(COALESCE((security_scans.info -> 'errors'::text), '[]'::jsonb))",
+ name: INDEX_NAME_ON_ERRORS
+ )
+
+ add_concurrent_index(
+ :security_scans,
+ "pipeline_id, jsonb_array_length(COALESCE((security_scans.info -> 'warnings'::text), '[]'::jsonb))",
+ name: INDEX_NAME_ON_WARNINGS
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name :security_scans, INDEX_NAME_ON_ERRORS
+ remove_concurrent_index_by_name :security_scans, INDEX_NAME_ON_WARNINGS
+ end
+end
diff --git a/db/post_migrate/20220707075300_reschedule_backfill_imported_issue_search_data.rb b/db/post_migrate/20220707075300_reschedule_backfill_imported_issue_search_data.rb
new file mode 100644
index 00000000000..b5124ce667c
--- /dev/null
+++ b/db/post_migrate/20220707075300_reschedule_backfill_imported_issue_search_data.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class RescheduleBackfillImportedIssueSearchData < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ MIGRATION = 'BackfillImportedIssueSearchData'
+ DELAY_INTERVAL = 120.seconds
+ BATCH_SIZE = 50_000
+ SUB_BATCH_SIZE = 1_000
+
+ def up
+ # remove the original migration
+ delete_batched_background_migration(MIGRATION, :issues, :id, [])
+
+ # reschedule the migration
+ min_value = Gitlab::Database::BackgroundMigration::BatchedMigration.find_by(
+ job_class_name: "BackfillIssueSearchData"
+ )&.max_value || BATCH_MIN_VALUE
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :issues,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_min_value: min_value,
+ batch_size: BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :issues, :id, [])
+ end
+end
diff --git a/db/post_migrate/20220708100508_drop_index_on_ci_runner_versions_on_status.rb b/db/post_migrate/20220708100508_drop_index_on_ci_runner_versions_on_status.rb
new file mode 100644
index 00000000000..71eb5a0867e
--- /dev/null
+++ b/db/post_migrate/20220708100508_drop_index_on_ci_runner_versions_on_status.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DropIndexOnCiRunnerVersionsOnStatus < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_runner_versions_on_status'
+
+ def up
+ remove_concurrent_index_by_name :ci_runner_versions, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :ci_runner_versions, :version, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220713133515_cleanup_backfill_draft_statuses_on_merge_requests.rb b/db/post_migrate/20220713133515_cleanup_backfill_draft_statuses_on_merge_requests.rb
new file mode 100644
index 00000000000..eb612a98ae6
--- /dev/null
+++ b/db/post_migrate/20220713133515_cleanup_backfill_draft_statuses_on_merge_requests.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class CleanupBackfillDraftStatusesOnMergeRequests < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ MIGRATION = 'BackfillDraftStatusOnMergeRequests'
+
+ def up
+ finalize_background_migration(MIGRATION)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20220714122311_add_async_index_on_security_findings_id_and_partition_number.rb b/db/post_migrate/20220714122311_add_async_index_on_security_findings_id_and_partition_number.rb
new file mode 100644
index 00000000000..02d18ba8b40
--- /dev/null
+++ b/db/post_migrate/20220714122311_add_async_index_on_security_findings_id_and_partition_number.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddAsyncIndexOnSecurityFindingsIdAndPartitionNumber < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'security_findings_partitioned_pkey'
+
+ disable_ddl_transaction!
+
+ def up
+ prepare_async_index :security_findings, [:id, :partition_number], unique: true, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index_by_name :security_findings, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220714122418_add_async_index_on_security_findings_unique_columns.rb b/db/post_migrate/20220714122418_add_async_index_on_security_findings_unique_columns.rb
new file mode 100644
index 00000000000..e21d3db6798
--- /dev/null
+++ b/db/post_migrate/20220714122418_add_async_index_on_security_findings_unique_columns.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddAsyncIndexOnSecurityFindingsUniqueColumns < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_security_findings_on_unique_columns'
+
+ disable_ddl_transaction!
+
+ def up
+ prepare_async_index :security_findings, [:uuid, :scan_id, :partition_number], unique: true, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index_by_name :security_findings, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220715054506_add_parent_link_unique_work_item_index.rb b/db/post_migrate/20220715054506_add_parent_link_unique_work_item_index.rb
new file mode 100644
index 00000000000..ed5b85b711c
--- /dev/null
+++ b/db/post_migrate/20220715054506_add_parent_link_unique_work_item_index.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddParentLinkUniqueWorkItemIndex < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_work_item_parent_links_on_work_item_id'
+ OLD_INDEX_NAME = 'index_parent_links_on_work_item_id_and_work_item_parent_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :work_item_parent_links, :work_item_id, unique: true, name: INDEX_NAME
+ remove_concurrent_index_by_name :work_item_parent_links, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :work_item_parent_links, [:work_item_id, :work_item_parent_id],
+ unique: true, name: OLD_INDEX_NAME
+ remove_concurrent_index_by_name :work_item_parent_links, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220715160023_drop_post_migration_test_table.rb b/db/post_migrate/20220715160023_drop_post_migration_test_table.rb
new file mode 100644
index 00000000000..98b4cbcf972
--- /dev/null
+++ b/db/post_migrate/20220715160023_drop_post_migration_test_table.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class DropPostMigrationTestTable < Gitlab::Database::Migration[2.0]
+ def up
+ drop_table :post_migration_test_table
+ end
+
+ def down
+ create_table :post_migration_test_table do |t|
+ t.integer :status, null: false
+ end
+ end
+end
diff --git a/db/post_migrate/20220715163254_update_notes_in_past.rb b/db/post_migrate/20220715163254_update_notes_in_past.rb
new file mode 100644
index 00000000000..1c46a3bc9dc
--- /dev/null
+++ b/db/post_migrate/20220715163254_update_notes_in_past.rb
@@ -0,0 +1,22 @@
+# 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 UpdateNotesInPast < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ loop do
+ update_count = define_batchable_model('notes')
+ .where('created_at < ?', '1970-01-01').limit(100)
+ .update_all(created_at: '1970-01-01 00:00:00')
+
+ break if update_count == 0
+ end
+ end
+
+ def down
+ # no op
+ end
+end