summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb29
-rw-r--r--db/post_migrate/20210302150310_schedule_migrate_pages_to_zip_storage.rb17
-rw-r--r--db/post_migrate/20210303064112_add_not_null_constraints_to_gitlab_subscriptions_namespace_id.rb19
-rw-r--r--db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb24
-rw-r--r--db/post_migrate/20210303121224_update_gitlab_subscriptions_start_at_post_eoa.rb54
-rw-r--r--db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb25
-rw-r--r--db/post_migrate/20210304133508_schedule_remove_duplicate_vulnerabilities_findings2.rb32
-rw-r--r--db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb17
-rw-r--r--db/post_migrate/20210311045138_set_traversal_ids_for_gitlab_org_group_staging.rb88
-rw-r--r--db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb88
-rw-r--r--db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb30
-rw-r--r--db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb31
-rw-r--r--db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb32
-rw-r--r--db/post_migrate/20210317104032_set_iteration_cadence_automatic_to_false.rb17
-rw-r--r--db/post_migrate/20210317155207_validate_not_null_constraint_on_cluster_token_name.rb16
-rw-r--r--db/post_migrate/20210322115438_validate_not_null_constraint_on_gitlab_subscriptions_namespace_id.rb17
-rw-r--r--db/post_migrate/20210326121537_backfill_cleanup_for_partitioned_web_hook_logs.rb17
-rw-r--r--db/post_migrate/20210328214434_remove_temporary_index_from_vulnerabilities_table.rb18
-rw-r--r--db/post_migrate/20210329102724_add_new_trail_plans.rb41
-rw-r--r--db/post_migrate/20210330091751_remove_records_without_group_from_webhooks_table.rb30
-rw-r--r--db/post_migrate/20210330130420_drop_finding_fingerprint_table.rb40
-rw-r--r--db/post_migrate/20210331105335_drop_non_partitioned_audit_events.rb44
-rw-r--r--db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb29
-rw-r--r--db/post_migrate/20210402005225_add_source_and_level_index_on_notification_settings.rb24
-rw-r--r--db/post_migrate/20210403022952_remove_notes_delete_cascade_timelogs.rb26
-rw-r--r--db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb27
-rw-r--r--db/post_migrate/20210407150240_confirm_support_bot_user.rb23
-rw-r--r--db/post_migrate/20210409185501_index_members_on_user_id_source_id_source_type.rb17
-rw-r--r--db/post_migrate/20210409185531_remove_members_index_on_user_id.rb17
-rw-r--r--db/post_migrate/20210413092922_add_index_to_packages_maven_metadata_path.rb17
-rw-r--r--db/post_migrate/20210413130011_add_partitioned_web_hook_log_fk.rb22
-rw-r--r--db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb14
-rw-r--r--db/post_migrate/20210415074645_index_members_on_user_id_access_level_requested_at_is_null.rb17
-rw-r--r--db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb32
-rw-r--r--db/post_migrate/20210415155043_move_container_registry_enabled_to_project_features3.rb35
-rw-r--r--db/post_migrate/20210420103955_remove_hipchat_service_records.rb21
-rw-r--r--db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb31
-rw-r--r--db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb15
-rw-r--r--db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb30
-rw-r--r--db/post_migrate/20210423124223_remove_proxy_settings_to_jira_tracker_data.rb14
-rw-r--r--db/post_migrate/20210423160427_schedule_drop_invalid_vulnerabilities.rb26
-rw-r--r--db/post_migrate/20210426094549_backfill_ci_builds_for_bigint_conversion.rb30
-rw-r--r--db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb12
-rw-r--r--db/post_migrate/20210427045711_backfill_ci_build_trace_chunks_for_bigint_conversion.rb28
-rw-r--r--db/post_migrate/20210427085020_backfill_ci_builds_runner_session_for_bigint_conversion.rb28
-rw-r--r--db/post_migrate/20210427212034_schedule_update_timelogs_project_id.rb32
-rw-r--r--db/post_migrate/20210429143649_add_new_issues_index_for_relative_position.rb17
-rw-r--r--db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb19
-rw-r--r--db/post_migrate/20210430130259_remove_obsolete_segments_field.rb18
-rw-r--r--db/post_migrate/20210430134202_copy_adoption_snapshot_namespace.rb16
-rw-r--r--db/post_migrate/20210430135954_copy_adoption_segments_namespace.rb14
-rw-r--r--db/post_migrate/20210505092746_create_partial_covering_index_for_pending_builds.rb24
-rw-r--r--db/post_migrate/20210506064413_create_namespaces_id_parent_id_inverse_partial_index.rb18
-rw-r--r--db/post_migrate/20210506065000_schedule_backfill_traversal_ids.rb38
-rw-r--r--db/post_migrate/20210511095657_add_temporary_index_for_project_topics_to_taggings.rb19
-rw-r--r--db/post_migrate/20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics.rb30
-rw-r--r--db/post_migrate/20210511142748_schedule_drop_invalid_vulnerabilities2.rb25
-rw-r--r--db/post_migrate/20210513155447_add_temporary_package_index_for_nuget_data_migration.rb19
-rw-r--r--db/post_migrate/20210513155546_backfill_nuget_temporary_packages_to_processing_status.rb29
-rw-r--r--db/post_migrate/20210513155635_remove_temporary_package_index_for_nuget_data_migration.rb19
-rw-r--r--db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb36
-rw-r--r--db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb27
-rw-r--r--db/post_migrate/20210517075444_remove_temporary_index_for_project_topics_to_taggings.rb19
-rw-r--r--db/post_migrate/20210518001450_backfill_clusters_integration_elastic_stack_enabled.rb34
-rw-r--r--db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb29
-rw-r--r--db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb42
-rw-r--r--db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb18
-rw-r--r--db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb89
-rw-r--r--db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb46
-rw-r--r--db/post_migrate/20210525075724_clean_up_pending_builds_table.rb28
-rw-r--r--db/post_migrate/20210526160133_remove_segment_selections_table.rb26
-rw-r--r--db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb17
-rw-r--r--db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb15
-rw-r--r--db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb13
-rw-r--r--db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb27
-rw-r--r--db/post_migrate/20211004120135_schedule_add_primary_email_to_emails_if_user_confirmed.rb30
-rw-r--r--db/post_migrate/20211206162601_cleanup_after_add_primary_email_to_emails_if_user_confirmed.rb59
-rw-r--r--db/post_migrate/20220826152430_remove_container_repository_deprecated_geo_fields.rb28
-rw-r--r--db/post_migrate/20220826152432_remove_container_repository_updated_events.rb22
-rw-r--r--db/post_migrate/20221102231131_remove_temp_index_for_user_details_fields.rb26
-rw-r--r--db/post_migrate/20221110100600_add_temp_index_on_overlong_vulnerability_html_title.rb18
-rw-r--r--db/post_migrate/20221110100602_queue_truncate_overlong_vulnerability_html_titles.rb29
-rw-r--r--db/post_migrate/20221209235939_add_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb16
-rw-r--r--db/post_migrate/20221209235940_cleanup_o_auth_access_tokens_with_null_expires_in.rb25
-rw-r--r--db/post_migrate/20221214095129_second_recount_epic_cache_counts.rb29
-rw-r--r--db/post_migrate/20221214105307_add_token_encrypted_partition_id_index_to_ci_build.rb23
-rw-r--r--db/post_migrate/20221215151822_schedule_backfill_releases_author_id.rb59
-rw-r--r--db/post_migrate/20221216131710_add_index_to_ci_unit_test_failure.rb17
-rw-r--r--db/post_migrate/20221216131935_add_index_to_ci_build_pending_state.rb17
-rw-r--r--db/post_migrate/20221216131958_add_index_to_ci_build_trace_chunk.rb17
-rw-r--r--db/post_migrate/20221216144854_add_foreign_key_to_ci_unit_test_failure.rb30
-rw-r--r--db/post_migrate/20221216150304_add_foreign_key_to_ci_build_pending_state.rb30
-rw-r--r--db/post_migrate/20221216150321_add_foreign_key_to_ci_build_trace_chunk.rb30
-rw-r--r--db/post_migrate/20221216150919_validate_foreign_key_on_ci_unit_test_failure_partition_id_build_id.rb16
-rw-r--r--db/post_migrate/20221216151459_validate_foreign_key_on_ci_build_pending_state_partition_id_build_id.rb16
-rw-r--r--db/post_migrate/20221216151649_validate_foreign_key_on_ci_build_trace_chunk_partition_id_build_id.rb16
-rw-r--r--db/post_migrate/20221216232658_index_members_on_member_namespace_id_compound.rb19
-rw-r--r--db/post_migrate/20221216232659_index_members_on_member_namespace_id_compound_sync.rb19
-rw-r--r--db/post_migrate/20221220075936_add_query_index_for_ci_pipeline_schedules.rb18
-rw-r--r--db/post_migrate/20221220131020_bump_default_partition_id_value_for_ci_tables.rb56
-rw-r--r--db/post_migrate/20221221110733_remove_temp_index_for_project_statistics_upload_size_migration.rb17
-rw-r--r--db/post_migrate/20221221150123_update_billable_users_index.rb27
-rw-r--r--db/post_migrate/20221222092958_sync_new_amount_used_with_amount_used.rb17
-rw-r--r--db/post_migrate/20221223123019_delete_queued_jobs_for_vulnerabilities_feedback_migration.rb23
-rw-r--r--db/post_migrate/20221226153240_remove_chat_names_integration_id_foreign_key.rb27
-rw-r--r--db/post_migrate/20221226154458_drop_index_on_chat_names_on_integration_id_and_team_id_and_chat_id.rb15
-rw-r--r--db/post_migrate/20221227100751_add_user_index_to_chat_names.rb15
-rw-r--r--db/post_migrate/20221227101436_drop_index_on_chat_names_on_user_id_and_integration_id.rb15
-rw-r--r--db/post_migrate/20221228103133_queue_backfill_admin_mode_scope_for_personal_access_tokens.rb21
-rw-r--r--db/post_migrate/20221228163035_cleanup_appearances_short_title_rename.rb13
-rw-r--r--db/post_migrate/20221228210616_add_index_on_ci_runners_on_runner_type_and_id.rb18
-rw-r--r--db/post_migrate/20230104103748_remove_new_amount_used_column.rb20
-rw-r--r--db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb36
-rw-r--r--db/post_migrate/20230104220137_reindex_vuln_reads_on_default_branch_with_common_query.rb26
-rw-r--r--db/post_migrate/20230104224020_drop_vuln_reads_on_default_branch_index.rb19
-rw-r--r--db/post_migrate/20230105172120_sync_new_amount_used_with_amount_used_on_ci_namespace_monthly_usages_table.rb19
-rw-r--r--db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb22
-rw-r--r--db/post_migrate/20230106124332_change_keys_relation_to_ssh_signatures.rb41
-rw-r--r--db/post_migrate/20230110172751_add_partial_index_on_group_path_id.rb15
-rw-r--r--db/post_migrate/20230111125148_add_user_id_and_source_id_and_source_type_and_member_role_id_index_to_members.rb15
-rw-r--r--db/post_migrate/20230111125150_drop_user_id_and_source_id_and_source_type_index_from_members.rb15
-rw-r--r--db/post_migrate/20230112085143_add_index_environments_on_project_id_and_id.rb15
-rw-r--r--db/post_migrate/20230113003255_remove_atlassian_refresh_token_constraint.rb20
-rw-r--r--db/post_migrate/20230116083826_drop_index_on_ci_build_token_encrypted.rb17
-rw-r--r--db/post_migrate/20230116090630_add_index_for_group_activity_events.rb15
-rw-r--r--db/post_migrate/20230116090852_add_index_for_project_activity_events.rb15
-rw-r--r--db/post_migrate/20230116090920_add_index_to_events_on_group_id_and_id.rb15
-rw-r--r--db/post_migrate/20230116091626_add_index_for_events_followed_users.rb15
-rw-r--r--db/post_migrate/20230116111252_finalize_todo_sanitization.rb22
-rw-r--r--db/post_migrate/20230117113719_add_tmp_index_to_ci_sources_pipelines_on_partition_id.rb29
-rw-r--r--db/post_migrate/20230117145628_add_token_encrypted_and_partition_id_index_to_ci_build.rb17
131 files changed, 1192 insertions, 2153 deletions
diff --git a/db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb b/db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb
deleted file mode 100644
index e04f69f4206..00000000000
--- a/db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillNamespaceStatisticsWithWikiSize < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 500
- MIGRATION = 'PopulateNamespaceStatistics'
-
- disable_ddl_transaction!
-
- def up
- return unless Gitlab.ee?
-
- groups = exec_query <<~SQL
- SELECT group_wiki_repositories.group_id
- FROM group_wiki_repositories
- SQL
-
- groups.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |group_ids, index|
- migrate_in(index * DELAY_INTERVAL, MIGRATION, [group_ids, [:wiki_size]])
- end
- end
-
- def down
- # No-op
- end
-end
diff --git a/db/post_migrate/20210302150310_schedule_migrate_pages_to_zip_storage.rb b/db/post_migrate/20210302150310_schedule_migrate_pages_to_zip_storage.rb
deleted file mode 100644
index 87c7d373329..00000000000
--- a/db/post_migrate/20210302150310_schedule_migrate_pages_to_zip_storage.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleMigratePagesToZipStorage < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- MIGRATION = 'MigratePagesToZipStorage'
- BATCH_SIZE = 10
- BATCH_TIME = 5.minutes
-
- disable_ddl_transaction!
-
- def up
- # no-op
- end
-end
diff --git a/db/post_migrate/20210303064112_add_not_null_constraints_to_gitlab_subscriptions_namespace_id.rb b/db/post_migrate/20210303064112_add_not_null_constraints_to_gitlab_subscriptions_namespace_id.rb
deleted file mode 100644
index f1d2d80a0f3..00000000000
--- a/db/post_migrate/20210303064112_add_not_null_constraints_to_gitlab_subscriptions_namespace_id.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class AddNotNullConstraintsToGitlabSubscriptionsNamespaceId < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- # This will add the `NOT NULL` constraint WITHOUT validating it
- add_not_null_constraint :gitlab_subscriptions, :namespace_id, validate: false
- end
-
- def down
- # Down is required as `add_not_null_constraint` is not reversible
- remove_not_null_constraint :gitlab_subscriptions, :namespace_id
- end
-end
diff --git a/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb b/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb
deleted file mode 100644
index 2250d4c0c8a..00000000000
--- a/db/post_migrate/20210303064142_cleanup_gitlab_subscriptions_with_null_namespace_id.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupGitlabSubscriptionsWithNullNamespaceId < ActiveRecord::Migration[6.0]
- disable_ddl_transaction!
-
- class GitlabSubscription < ActiveRecord::Base
- self.table_name = 'gitlab_subscriptions'
- end
-
- def up
- # As of today, there is 0 records whose namespace_id is null on GitLab.com.
- # And we expect no such records on non GitLab.com instance.
- # So this post-migration cleanup script is just for extra safe.
- #
- # This will be fast on GitLab.com, because:
- # - gitlab_subscriptions.count=5021850
- # - namespace_id is indexed, so the query is pretty fast. Try on database-lab, this uses 5.931 ms
- GitlabSubscription.where(namespace_id: nil).delete_all
- end
-
- def down
- # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint
- end
-end
diff --git a/db/post_migrate/20210303121224_update_gitlab_subscriptions_start_at_post_eoa.rb b/db/post_migrate/20210303121224_update_gitlab_subscriptions_start_at_post_eoa.rb
deleted file mode 100644
index 69d99704469..00000000000
--- a/db/post_migrate/20210303121224_update_gitlab_subscriptions_start_at_post_eoa.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-# frozen_string_literal: true
-
-class UpdateGitlabSubscriptionsStartAtPostEoa < ActiveRecord::Migration[6.0]
- UPDATE_BATCH_SIZE = 100
-
- disable_ddl_transaction!
-
- class Plan < ActiveRecord::Base
- self.table_name = 'plans'
- self.inheritance_column = :_type_disabled
- end
-
- class GitlabSubscription < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'gitlab_subscriptions'
- self.inheritance_column = :_type_disabled
-
- EOA_ROLLOUT_DATE = '2021-01-26'
-
- scope :with_plan, -> (from_plan) do
- where("start_date >= ? AND hosted_plan_id = ?", EOA_ROLLOUT_DATE, from_plan.id)
- end
- end
-
- def up
- return unless Gitlab.com?
-
- silver_plan = Plan.find_by(name: 'silver')
- gold_plan = Plan.find_by(name: 'gold')
- premium_plan = Plan.find_by(name: 'premium')
- ultimate_plan = Plan.find_by(name: 'ultimate')
-
- # Silver to Premium
- update_hosted_plan_for_subscription(from_plan: silver_plan, to_plan: premium_plan)
-
- # Gold to Ultimate
- update_hosted_plan_for_subscription(from_plan: gold_plan, to_plan: ultimate_plan)
- end
-
- def down
- # no-op
- end
-
- private
-
- def update_hosted_plan_for_subscription(from_plan:, to_plan:)
- return unless from_plan && to_plan
-
- GitlabSubscription.with_plan(from_plan).each_batch(of: UPDATE_BATCH_SIZE) do |batch|
- batch.update_all(hosted_plan_id: to_plan.id)
- end
- end
-end
diff --git a/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb b/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb
deleted file mode 100644
index 6553036792c..00000000000
--- a/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupClusterTokensWithNullName < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- BATCH_SIZE = 1000
-
- disable_ddl_transaction!
-
- class AgentToken < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'cluster_agent_tokens'
- end
-
- def up
- AgentToken.each_batch(of: BATCH_SIZE) do |relation|
- relation.where(name: nil).update_all("name = 'agent-token-' || id")
- end
- end
-
- def down
- # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint
- end
-end
diff --git a/db/post_migrate/20210304133508_schedule_remove_duplicate_vulnerabilities_findings2.rb b/db/post_migrate/20210304133508_schedule_remove_duplicate_vulnerabilities_findings2.rb
deleted file mode 100644
index 78574921fea..00000000000
--- a/db/post_migrate/20210304133508_schedule_remove_duplicate_vulnerabilities_findings2.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleRemoveDuplicateVulnerabilitiesFindings2 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- MIGRATION = 'RemoveDuplicateVulnerabilitiesFindings'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 5_000
-
- disable_ddl_transaction!
-
- class VulnerabilitiesFinding < ActiveRecord::Base
- include ::EachBatch
- self.table_name = "vulnerability_occurrences"
- end
-
- def up
- say "Scheduling #{MIGRATION} jobs"
- queue_background_migration_jobs_by_range_at_intervals(
- VulnerabilitiesFinding,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb b/db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb
deleted file mode 100644
index 3a37d8a8510..00000000000
--- a/db/post_migrate/20210306121310_backfill_partitioned_web_hook_logs.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillPartitionedWebHookLogs < ActiveRecord::Migration[6.0]
- include Gitlab::Database::PartitioningMigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- enqueue_partitioning_data_migration :web_hook_logs
- end
-
- def down
- cleanup_partitioning_data_migration :web_hook_logs
- end
-end
diff --git a/db/post_migrate/20210311045138_set_traversal_ids_for_gitlab_org_group_staging.rb b/db/post_migrate/20210311045138_set_traversal_ids_for_gitlab_org_group_staging.rb
deleted file mode 100644
index bcf872ded54..00000000000
--- a/db/post_migrate/20210311045138_set_traversal_ids_for_gitlab_org_group_staging.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# frozen_string_literal: true
-
-class SetTraversalIdsForGitlabOrgGroupStaging < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- def up
- return unless Gitlab.staging?
-
- # namespace ID 9970 is gitlab-org on staging.
- with_lock_retries do
- execute(<<~SQL)
- UPDATE
- namespaces
- SET
- traversal_ids = cte.traversal_ids
- FROM
- (
- WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
- VALUES
- (9970, ARRAY[9970], false)
- UNION ALL
- SELECT
- n.id,
- cte.traversal_ids || n.id,
- n.id = ANY(cte.traversal_ids)
- FROM
- namespaces n,
- cte
- WHERE
- n.parent_id = cte.id
- AND NOT cycle
- )
- SELECT
- id,
- traversal_ids
- FROM
- cte FOR
- UPDATE
- ) as cte
- WHERE
- namespaces.id = cte.id
- AND namespaces.traversal_ids <> cte.traversal_ids
- SQL
- end
- end
-
- def down
- return unless Gitlab.staging?
-
- # namespace ID 9970 is gitlab-org on staging.
- with_lock_retries do
- execute(<<~SQL)
- UPDATE
- namespaces
- SET
- traversal_ids = '{}'
- FROM
- (
- WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
- VALUES
- (9970, ARRAY[9970], false)
- UNION ALL
- SELECT
- n.id,
- cte.traversal_ids || n.id,
- n.id = ANY(cte.traversal_ids)
- FROM
- namespaces n,
- cte
- WHERE
- n.parent_id = cte.id
- AND NOT cycle
- )
- SELECT
- id,
- traversal_ids
- FROM
- cte FOR
- UPDATE
- ) as cte
- WHERE
- namespaces.id = cte.id
- SQL
- end
- end
-end
diff --git a/db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb b/db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb
deleted file mode 100644
index 8cef1f1cc2b..00000000000
--- a/db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# frozen_string_literal: true
-
-class SetTraversalIdsForGitlabOrgGroupCom < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- def up
- return unless Gitlab.com?
-
- # namespace ID 9970 is gitlab-org on .com
- with_lock_retries do
- execute(<<~SQL)
- UPDATE
- namespaces
- SET
- traversal_ids = cte.traversal_ids
- FROM
- (
- WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
- VALUES
- (9970, ARRAY[9970], false)
- UNION ALL
- SELECT
- n.id,
- cte.traversal_ids || n.id,
- n.id = ANY(cte.traversal_ids)
- FROM
- namespaces n,
- cte
- WHERE
- n.parent_id = cte.id
- AND NOT cycle
- )
- SELECT
- id,
- traversal_ids
- FROM
- cte FOR
- UPDATE
- ) as cte
- WHERE
- namespaces.id = cte.id
- AND namespaces.traversal_ids <> cte.traversal_ids
- SQL
- end
- end
-
- def down
- return unless Gitlab.com?
-
- # namespace ID 9970 is gitlab-org on .com
- with_lock_retries do
- execute(<<~SQL)
- UPDATE
- namespaces
- SET
- traversal_ids = '{}'
- FROM
- (
- WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
- VALUES
- (9970, ARRAY[9970], false)
- UNION ALL
- SELECT
- n.id,
- cte.traversal_ids || n.id,
- n.id = ANY(cte.traversal_ids)
- FROM
- namespaces n,
- cte
- WHERE
- n.parent_id = cte.id
- AND NOT cycle
- )
- SELECT
- id,
- traversal_ids
- FROM
- cte FOR
- UPDATE
- ) as cte
- WHERE
- namespaces.id = cte.id
- SQL
- end
- end
-end
diff --git a/db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb b/db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb
deleted file mode 100644
index 176548be6e6..00000000000
--- a/db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class AddPartialIndexOnCiPipelinesByCancelableStatusAndUsers < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- INDEX_NAME = 'index_ci_pipelines_on_user_id_and_id_and_cancelable_status'
- INDEX_FILTER_CONDITION = <<~SQL
- ((status)::text = ANY (
- ARRAY[
- ('running'::character varying)::text,
- ('waiting_for_resource'::character varying)::text,
- ('preparing'::character varying)::text,
- ('pending'::character varying)::text,
- ('created'::character varying)::text,
- ('scheduled'::character varying)::text
- ]
- ))
- SQL
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :ci_pipelines, [:user_id, :id], where: INDEX_FILTER_CONDITION, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :ci_pipelines, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb b/db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb
deleted file mode 100644
index 5d31cdb05e6..00000000000
--- a/db/post_migrate/20210311120155_backfill_events_id_for_bigint_conversion.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillEventsIdForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- DOWNTIME = false
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint :events, :id, batch_size: 15000, sub_batch_size: 100
- end
-
- def down
- return unless should_run?
-
- Gitlab::Database::BackgroundMigration::BatchedMigration
- .where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
- .where(table_name: 'events', column_name: 'id')
- .where(job_arguments: Gitlab::Json.dump(%w[id id_convert_to_bigint]))
- .delete_all
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb b/db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb
deleted file mode 100644
index b64282fe0d3..00000000000
--- a/db/post_migrate/20210311120156_backfill_push_event_payload_event_id_for_bigint_conversion.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillPushEventPayloadEventIdForBigintConversion < ActiveRecord::Migration[6.0]
- disable_ddl_transaction!
-
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint :push_event_payloads, :event_id, primary_key: :event_id,
- batch_size: 15000, sub_batch_size: 100
- end
-
- def down
- return unless should_run?
-
- Gitlab::Database::BackgroundMigration::BatchedMigration
- .where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
- .where(table_name: 'push_event_payloads', column_name: 'event_id')
- .where(job_arguments: Gitlab::Json.dump(%w[event_id event_id_convert_to_bigint]))
- .delete_all
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210317104032_set_iteration_cadence_automatic_to_false.rb b/db/post_migrate/20210317104032_set_iteration_cadence_automatic_to_false.rb
deleted file mode 100644
index c151551ae64..00000000000
--- a/db/post_migrate/20210317104032_set_iteration_cadence_automatic_to_false.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class SetIterationCadenceAutomaticToFalse < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def up
- ActiveRecord::Base.connection.execute <<~SQL
- UPDATE iterations_cadences
- SET automatic = FALSE
- WHERE iterations_cadences.automatic = TRUE
- SQL
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210317155207_validate_not_null_constraint_on_cluster_token_name.rb b/db/post_migrate/20210317155207_validate_not_null_constraint_on_cluster_token_name.rb
deleted file mode 100644
index b77523c3a44..00000000000
--- a/db/post_migrate/20210317155207_validate_not_null_constraint_on_cluster_token_name.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class ValidateNotNullConstraintOnClusterTokenName < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- validate_not_null_constraint :cluster_agent_tokens, :name
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210322115438_validate_not_null_constraint_on_gitlab_subscriptions_namespace_id.rb b/db/post_migrate/20210322115438_validate_not_null_constraint_on_gitlab_subscriptions_namespace_id.rb
deleted file mode 100644
index 96d9f383406..00000000000
--- a/db/post_migrate/20210322115438_validate_not_null_constraint_on_gitlab_subscriptions_namespace_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class ValidateNotNullConstraintOnGitlabSubscriptionsNamespaceId < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- validate_not_null_constraint :gitlab_subscriptions, :namespace_id
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210326121537_backfill_cleanup_for_partitioned_web_hook_logs.rb b/db/post_migrate/20210326121537_backfill_cleanup_for_partitioned_web_hook_logs.rb
deleted file mode 100644
index 5816d02561e..00000000000
--- a/db/post_migrate/20210326121537_backfill_cleanup_for_partitioned_web_hook_logs.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCleanupForPartitionedWebHookLogs < ActiveRecord::Migration[6.0]
- include Gitlab::Database::PartitioningMigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- finalize_backfilling_partitioned_table :web_hook_logs
- end
-
- def down
- # no op
- end
-end
diff --git a/db/post_migrate/20210328214434_remove_temporary_index_from_vulnerabilities_table.rb b/db/post_migrate/20210328214434_remove_temporary_index_from_vulnerabilities_table.rb
deleted file mode 100644
index f3da1cc69c4..00000000000
--- a/db/post_migrate/20210328214434_remove_temporary_index_from_vulnerabilities_table.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveTemporaryIndexFromVulnerabilitiesTable < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- INDEX_NAME = 'temporary_index_vulnerabilities_on_id'
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME
- end
-
- def down
- add_concurrent_index :vulnerabilities, :id, where: "state = 2 AND (dismissed_at IS NULL OR dismissed_by_id IS NULL)", name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20210329102724_add_new_trail_plans.rb b/db/post_migrate/20210329102724_add_new_trail_plans.rb
deleted file mode 100644
index 37c64bbd42d..00000000000
--- a/db/post_migrate/20210329102724_add_new_trail_plans.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-class AddNewTrailPlans < ActiveRecord::Migration[6.0]
- class Plan < ActiveRecord::Base
- self.inheritance_column = :_type_disabled
-
- has_one :limits, class_name: 'PlanLimits'
-
- def actual_limits
- self.limits || self.build_limits
- end
- end
-
- class PlanLimits < ActiveRecord::Base
- self.inheritance_column = :_type_disabled
-
- belongs_to :plan
- end
-
- def create_plan_limits(plan_limit_name, plan)
- plan_limit = Plan.find_or_initialize_by(name: plan_limit_name).actual_limits.dup
- plan_limit.plan = plan
- plan_limit.save!
- end
-
- def up
- return unless Gitlab.com?
-
- ultimate_trial = Plan.create!(name: 'ultimate_trial', title: 'Ultimate Trial')
- premium_trial = Plan.create!(name: 'premium_trial', title: 'Premium Trial')
-
- create_plan_limits('gold', ultimate_trial)
- create_plan_limits('silver', premium_trial)
- end
-
- def down
- return unless Gitlab.com?
-
- Plan.where(name: %w(ultimate_trial premium_trial)).delete_all
- end
-end
diff --git a/db/post_migrate/20210330091751_remove_records_without_group_from_webhooks_table.rb b/db/post_migrate/20210330091751_remove_records_without_group_from_webhooks_table.rb
deleted file mode 100644
index c384aa25ac4..00000000000
--- a/db/post_migrate/20210330091751_remove_records_without_group_from_webhooks_table.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveRecordsWithoutGroupFromWebhooksTable < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- class WebHook < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'web_hooks'
- end
-
- class Group < ActiveRecord::Base
- self.inheritance_column = :_type_disabled
- self.table_name = 'namespaces'
- end
-
- def up
- subquery = Group.select(1).where(Group.arel_table[:id].eq(WebHook.arel_table[:group_id]))
-
- WebHook.each_batch(of: 500, column: :id) do |relation|
- relation.where(type: 'GroupHook').where.not('EXISTS (?)', subquery).delete_all
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210330130420_drop_finding_fingerprint_table.rb b/db/post_migrate/20210330130420_drop_finding_fingerprint_table.rb
deleted file mode 100644
index fd77d4d7a4b..00000000000
--- a/db/post_migrate/20210330130420_drop_finding_fingerprint_table.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-class DropFindingFingerprintTable < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- FINGERPRINT_IDX = :idx_vuln_fingerprints_on_occurrences_id_and_fingerprint_sha256
- UNIQ_IDX = :idx_vuln_fingerprints_uniqueness_fingerprint_sha256
-
- def up
- with_lock_retries do
- drop_table :vulnerability_finding_fingerprints
- end
- end
-
- def down
- with_lock_retries do
- create_table :vulnerability_finding_fingerprints do |t|
- t.references :finding,
- index: true,
- null: false,
- foreign_key: { to_table: :vulnerability_occurrences, column: :finding_id, on_delete: :cascade }
-
- t.timestamps_with_timezone null: false
-
- t.integer :algorithm_type, null: false, limit: 2
- t.binary :fingerprint_sha256, null: false
-
- t.index %i[finding_id fingerprint_sha256],
- name: FINGERPRINT_IDX,
- unique: true # only one link should exist between occurrence and the fingerprint
-
- t.index %i[finding_id algorithm_type fingerprint_sha256],
- name: UNIQ_IDX,
- unique: true # these should be unique
- end
- end
- end
-end
diff --git a/db/post_migrate/20210331105335_drop_non_partitioned_audit_events.rb b/db/post_migrate/20210331105335_drop_non_partitioned_audit_events.rb
deleted file mode 100644
index 7c32fc61711..00000000000
--- a/db/post_migrate/20210331105335_drop_non_partitioned_audit_events.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-# frozen_string_literal: true
-
-class DropNonPartitionedAuditEvents < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
- include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
-
- DOWNTIME = false
-
- def up
- drop_nonpartitioned_archive_table(:audit_events)
- end
-
- def down
- execute(<<~SQL)
- CREATE TABLE audit_events_archived (
- id integer NOT NULL,
- author_id integer NOT NULL,
- entity_id integer NOT NULL,
- entity_type character varying NOT NULL,
- details text,
- created_at timestamp without time zone,
- ip_address inet,
- author_name text,
- entity_path text,
- target_details text,
- target_type text,
- target_id bigint,
- CONSTRAINT check_492aaa021d CHECK ((char_length(entity_path) <= 5500)),
- CONSTRAINT check_82294106dd CHECK ((char_length(target_type) <= 255)),
- CONSTRAINT check_83ff8406e2 CHECK ((char_length(author_name) <= 255)),
- CONSTRAINT check_d493ec90b5 CHECK ((char_length(target_details) <= 5500))
- );
-
- ALTER TABLE ONLY audit_events_archived ADD CONSTRAINT audit_events_archived_pkey PRIMARY KEY (id);
-
- CREATE INDEX analytics_index_audit_events_on_created_at_and_author_id ON audit_events_archived USING btree (created_at, author_id);
- CREATE INDEX idx_audit_events_on_entity_id_desc_author_id_created_at ON audit_events_archived USING btree (entity_id, entity_type, id DESC, author_id, created_at);
- SQL
-
- with_lock_retries do
- create_trigger_to_sync_tables(:audit_events, :audit_events_archived, 'id')
- end
- end
-end
diff --git a/db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb b/db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb
deleted file mode 100644
index ee118371fb8..00000000000
--- a/db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class MoveContainerRegistryEnabledToProjectFeatures2 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- BATCH_SIZE = 21_000
- MIGRATION = 'MoveContainerRegistryEnabledToProjectFeature'
-
- disable_ddl_transaction!
-
- class Project < ActiveRecord::Base
- include EachBatch
- self.table_name = 'projects'
- end
-
- def up
- # Superceded by db/post_migrate/20210415155043_move_container_registry_enabled_to_project_features3.rb.
-
- # delete_queued_jobs('MoveContainerRegistryEnabledToProjectFeature')
-
- # queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE, track_jobs: true)
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210402005225_add_source_and_level_index_on_notification_settings.rb b/db/post_migrate/20210402005225_add_source_and_level_index_on_notification_settings.rb
deleted file mode 100644
index a29babca93e..00000000000
--- a/db/post_migrate/20210402005225_add_source_and_level_index_on_notification_settings.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class AddSourceAndLevelIndexOnNotificationSettings < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- INDEX_WITH_SOURCE_LEVEL_USER_NAME = 'index_notification_settings_on_source_and_level_and_user'
- INDEX_WITH_SOURCE_NAME = 'index_notification_settings_on_source_id_and_source_type'
- INDEX_WITH_USER_NAME = 'index_notification_settings_on_user_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :notification_settings, [:source_id, :source_type, :level, :user_id], name: INDEX_WITH_SOURCE_LEVEL_USER_NAME
- remove_concurrent_index_by_name :notification_settings, INDEX_WITH_SOURCE_NAME # Above index expands this index
- remove_concurrent_index_by_name :notification_settings, INDEX_WITH_USER_NAME # It is redundant as we already have unique index on (user_id, source_id, source_type)
- end
-
- def down
- add_concurrent_index :notification_settings, [:source_id, :source_type], name: INDEX_WITH_SOURCE_NAME
- add_concurrent_index :notification_settings, [:user_id], name: INDEX_WITH_USER_NAME
- remove_concurrent_index_by_name :notification_settings, INDEX_WITH_SOURCE_LEVEL_USER_NAME
- end
-end
diff --git a/db/post_migrate/20210403022952_remove_notes_delete_cascade_timelogs.rb b/db/post_migrate/20210403022952_remove_notes_delete_cascade_timelogs.rb
deleted file mode 100644
index 832ba584931..00000000000
--- a/db/post_migrate/20210403022952_remove_notes_delete_cascade_timelogs.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveNotesDeleteCascadeTimelogs < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- CONSTRAINT_NAME = 'fk_timelogs_note_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_foreign_key :timelogs, :notes, column: :note_id, on_delete: :nullify, name: CONSTRAINT_NAME
-
- with_lock_retries do
- remove_foreign_key_if_exists :timelogs, :notes, column: :note_id, on_delete: :cascade
- end
- end
-
- def down
- add_concurrent_foreign_key :timelogs, :notes, column: :note_id, on_delete: :cascade
-
- with_lock_retries do
- remove_foreign_key_if_exists :timelogs, :notes, column: :note_id, on_delete: :nullify, name: CONSTRAINT_NAME
- end
- end
-end
diff --git a/db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb b/db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb
deleted file mode 100644
index 5fc5a5b2b6e..00000000000
--- a/db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillTotalTupleCountForBatchedMigrations < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def up
- return unless should_run?
-
- Gitlab::Database::BackgroundMigration::BatchedMigration.all.each do |migration|
- total_tuple_count = Gitlab::Database::PgClass.for_table(migration.table_name)&.cardinality_estimate
-
- migration.update(total_tuple_count: total_tuple_count)
- end
- end
-
- def down
- return unless should_run?
-
- Gitlab::Database::BackgroundMigration::BatchedMigration.update_all(total_tuple_count: nil)
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210407150240_confirm_support_bot_user.rb b/db/post_migrate/20210407150240_confirm_support_bot_user.rb
deleted file mode 100644
index c26ae153128..00000000000
--- a/db/post_migrate/20210407150240_confirm_support_bot_user.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class ConfirmSupportBotUser < ActiveRecord::Migration[6.0]
- SUPPORT_BOT_TYPE = 1
-
- def up
- users = Arel::Table.new(:users)
- um = Arel::UpdateManager.new
- um.table(users)
- .where(users[:user_type].eq(SUPPORT_BOT_TYPE))
- .where(users[:confirmed_at].eq(nil))
- .set([[users[:confirmed_at], Arel::Nodes::NamedFunction.new('COALESCE', [users[:created_at], Arel::Nodes::SqlLiteral.new('NOW()')])]])
- connection.execute(um.to_sql)
- end
-
- def down
- # no op
-
- # The up migration allows for the possibility that the support user might
- # have already been manually confirmed. It's not reversible as this data is
- # subsequently lost.
- end
-end
diff --git a/db/post_migrate/20210409185501_index_members_on_user_id_source_id_source_type.rb b/db/post_migrate/20210409185501_index_members_on_user_id_source_id_source_type.rb
deleted file mode 100644
index d20eb5e4ea3..00000000000
--- a/db/post_migrate/20210409185501_index_members_on_user_id_source_id_source_type.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class IndexMembersOnUserIdSourceIdSourceType < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_members_on_user_id_source_id_source_type'
-
- def up
- add_concurrent_index(:members, [:user_id, :source_id, :source_type], name: INDEX_NAME)
- end
-
- def down
- remove_concurrent_index_by_name(:members, INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20210409185531_remove_members_index_on_user_id.rb b/db/post_migrate/20210409185531_remove_members_index_on_user_id.rb
deleted file mode 100644
index 3f330e44408..00000000000
--- a/db/post_migrate/20210409185531_remove_members_index_on_user_id.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveMembersIndexOnUserId < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_members_on_user_id'
-
- def up
- remove_concurrent_index_by_name(:members, INDEX_NAME)
- end
-
- def down
- add_concurrent_index(:members, :user_id, name: INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20210413092922_add_index_to_packages_maven_metadata_path.rb b/db/post_migrate/20210413092922_add_index_to_packages_maven_metadata_path.rb
deleted file mode 100644
index 697b9f9cbf7..00000000000
--- a/db/post_migrate/20210413092922_add_index_to_packages_maven_metadata_path.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddIndexToPackagesMavenMetadataPath < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_packages_maven_metadata_on_path'
-
- def up
- add_concurrent_index :packages_maven_metadata, :path, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index :packages_maven_metadata, :path, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20210413130011_add_partitioned_web_hook_log_fk.rb b/db/post_migrate/20210413130011_add_partitioned_web_hook_log_fk.rb
deleted file mode 100644
index 6453993bd51..00000000000
--- a/db/post_migrate/20210413130011_add_partitioned_web_hook_log_fk.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class AddPartitionedWebHookLogFk < ActiveRecord::Migration[6.0]
- include Gitlab::Database::PartitioningMigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_partitioned_foreign_key :web_hook_logs_part_0c5294f417,
- :web_hooks,
- column: :web_hook_id,
- on_delete: :cascade
- end
-
- def down
- with_lock_retries do
- remove_foreign_key_if_exists :web_hook_logs_part_0c5294f417, column: :web_hook_id
- end
- end
-end
diff --git a/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb b/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb
deleted file mode 100644
index 0377df7a46b..00000000000
--- a/db/post_migrate/20210413132500_reschedule_artifact_expiry_backfill_again.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class RescheduleArtifactExpiryBackfillAgain < ActiveRecord::Migration[6.0]
- # This migration has been disabled as it was causing a regression bug for self instances
- # preventing artifact deletion, see https://gitlab.com/gitlab-org/gitlab/-/issues/355955
-
- def up
- # no-op
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210415074645_index_members_on_user_id_access_level_requested_at_is_null.rb b/db/post_migrate/20210415074645_index_members_on_user_id_access_level_requested_at_is_null.rb
deleted file mode 100644
index fb379d48b2a..00000000000
--- a/db/post_migrate/20210415074645_index_members_on_user_id_access_level_requested_at_is_null.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class IndexMembersOnUserIdAccessLevelRequestedAtIsNull < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- INDEX_NAME = 'index_members_on_user_id_and_access_level_requested_at_is_null'
-
- def up
- add_concurrent_index(:members, [:user_id, :access_level], where: 'requested_at IS NULL', name: INDEX_NAME)
- end
-
- def down
- remove_concurrent_index_by_name(:members, INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb b/db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb
deleted file mode 100644
index 8fcaeb3fb04..00000000000
--- a/db/post_migrate/20210415101228_backfill_ci_build_needs_for_bigint_conversion.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCiBuildNeedsForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- DOWNTIME = false
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint :ci_build_needs, :build_id,
- batch_size: 15000, sub_batch_size: 100
- end
-
- def down
- return unless should_run?
-
- Gitlab::Database::BackgroundMigration::BatchedMigration
- .where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
- .where(table_name: 'ci_build_needs', column_name: 'build_id')
- .where(job_arguments: Gitlab::Json.dump(%w[build_id build_id_convert_to_bigint]))
- .delete_all
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210415155043_move_container_registry_enabled_to_project_features3.rb b/db/post_migrate/20210415155043_move_container_registry_enabled_to_project_features3.rb
deleted file mode 100644
index f63d7c5138b..00000000000
--- a/db/post_migrate/20210415155043_move_container_registry_enabled_to_project_features3.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# frozen_string_literal: true
-
-class MoveContainerRegistryEnabledToProjectFeatures3 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- BATCH_SIZE = 21_000
- MIGRATION = 'MoveContainerRegistryEnabledToProjectFeature'
-
- disable_ddl_transaction!
-
- def up
- # Delete any existing jobs from the queue
- delete_queued_jobs(MIGRATION)
-
- # Delete existing rows in background_migration_jobs table
- bg_migration_job_class = define_model('background_migration_jobs')
- bg_migration_job_class.where(class_name: MIGRATION).delete_all
-
- batchable_project_class = define_batchable_model('projects')
- queue_background_migration_jobs_by_range_at_intervals(batchable_project_class, MIGRATION, 2.minutes, batch_size: BATCH_SIZE, track_jobs: true)
- end
-
- def down
- # no-op
- end
-
- private
-
- def define_model(table_name)
- Class.new(ActiveRecord::Base) do
- self.table_name = table_name
- self.inheritance_column = :_type_disabled
- end
- end
-end
diff --git a/db/post_migrate/20210420103955_remove_hipchat_service_records.rb b/db/post_migrate/20210420103955_remove_hipchat_service_records.rb
deleted file mode 100644
index 5ad34cfad22..00000000000
--- a/db/post_migrate/20210420103955_remove_hipchat_service_records.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveHipchatServiceRecords < ActiveRecord::Migration[6.0]
- disable_ddl_transaction!
-
- class Service < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'services'
- end
-
- def up
- Service.each_batch(of: 100_000, column: :id) do |relation|
- relation.delete_by(type: 'HipchatService')
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb b/db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb
deleted file mode 100644
index 0c68834f723..00000000000
--- a/db/post_migrate/20210420121149_backfill_conversion_of_ci_job_artifacts.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillConversionOfCiJobArtifacts < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint :ci_job_artifacts, %i(id job_id), batch_size: 15000, sub_batch_size: 100
- end
-
- def down
- return unless should_run?
-
- Gitlab::Database::BackgroundMigration::BatchedMigration
- .where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
- .where(table_name: 'ci_job_artifacts', column_name: 'id')
- .where(job_arguments: Gitlab::Json.dump([%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]]))
- .delete_all
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb b/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb
deleted file mode 100644
index 0f6cf970778..00000000000
--- a/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleUpdateJiraTrackerDataDeploymentTypeBasedOnUrl < ActiveRecord::Migration[6.0]
- def up
- # no-op (being re-run in 20220324152945_update_jira_tracker_data_deployment_type_based_on_url.rb)
- # due to this migration causing this issue: https://gitlab.com/gitlab-org/gitlab/-/issues/336849
- # The migration is rescheduled in
- # db/post_migrate/20220725150127_update_jira_tracker_data_deployment_type_based_on_url.rb
- # Related discussion: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82103#note_862401816
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb b/db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb
deleted file mode 100644
index 3c6f2385f1d..00000000000
--- a/db/post_migrate/20210422023046_backfill_ci_sources_pipelines_source_job_id_for_bigint_conversion.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCiSourcesPipelinesSourceJobIdForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint :ci_sources_pipelines, :source_job_id,
- batch_size: 15000, sub_batch_size: 100
- end
-
- def down
- return unless should_run?
-
- Gitlab::Database::BackgroundMigration::BatchedMigration
- .where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
- .where(table_name: 'ci_sources_pipelines', column_name: 'id')
- .where(job_arguments: Gitlab::Json.dump([%w[source_job_id], %w[source_job_id_convert_to_bigint]]))
- .delete_all
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210423124223_remove_proxy_settings_to_jira_tracker_data.rb b/db/post_migrate/20210423124223_remove_proxy_settings_to_jira_tracker_data.rb
deleted file mode 100644
index 43ab965d79c..00000000000
--- a/db/post_migrate/20210423124223_remove_proxy_settings_to_jira_tracker_data.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveProxySettingsToJiraTrackerData < ActiveRecord::Migration[6.0]
- def change
- remove_column :jira_tracker_data, :encrypted_proxy_address, :text
- remove_column :jira_tracker_data, :encrypted_proxy_address_iv, :text
- remove_column :jira_tracker_data, :encrypted_proxy_port, :text
- remove_column :jira_tracker_data, :encrypted_proxy_port_iv, :text
- remove_column :jira_tracker_data, :encrypted_proxy_username, :text
- remove_column :jira_tracker_data, :encrypted_proxy_username_iv, :text
- remove_column :jira_tracker_data, :encrypted_proxy_password, :text
- remove_column :jira_tracker_data, :encrypted_proxy_password_iv, :text
- end
-end
diff --git a/db/post_migrate/20210423160427_schedule_drop_invalid_vulnerabilities.rb b/db/post_migrate/20210423160427_schedule_drop_invalid_vulnerabilities.rb
deleted file mode 100644
index 8199da937d3..00000000000
--- a/db/post_migrate/20210423160427_schedule_drop_invalid_vulnerabilities.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleDropInvalidVulnerabilities < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION = 'DropInvalidVulnerabilities'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 10_000
-
- disable_ddl_transaction!
-
- def up
- say "Scheduling #{MIGRATION} jobs"
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('vulnerabilities'),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210426094549_backfill_ci_builds_for_bigint_conversion.rb b/db/post_migrate/20210426094549_backfill_ci_builds_for_bigint_conversion.rb
deleted file mode 100644
index fd071ec9a1a..00000000000
--- a/db/post_migrate/20210426094549_backfill_ci_builds_for_bigint_conversion.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCiBuildsForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- DOWNTIME = false
-
- TABLE = :ci_builds
- COLUMNS = %i(id stage_id).freeze
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint TABLE, COLUMNS, batch_size: 15000, sub_batch_size: 100
- end
-
- def down
- return unless should_run?
-
- revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMNS
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb b/db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb
deleted file mode 100644
index 0e85fb40a36..00000000000
--- a/db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleRecalculateUuidOnVulnerabilitiesOccurrences2 < ActiveRecord::Migration[6.0]
- def up
- # no-op
- # superseded by db/post_migrate/20211207125231_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210427045711_backfill_ci_build_trace_chunks_for_bigint_conversion.rb b/db/post_migrate/20210427045711_backfill_ci_build_trace_chunks_for_bigint_conversion.rb
deleted file mode 100644
index 7e11d38868b..00000000000
--- a/db/post_migrate/20210427045711_backfill_ci_build_trace_chunks_for_bigint_conversion.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCiBuildTraceChunksForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- TABLE = :ci_build_trace_chunks
- COLUMNS = %i(build_id)
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS)
- end
-
- def down
- return unless should_run?
-
- revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS)
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210427085020_backfill_ci_builds_runner_session_for_bigint_conversion.rb b/db/post_migrate/20210427085020_backfill_ci_builds_runner_session_for_bigint_conversion.rb
deleted file mode 100644
index fa0420fe426..00000000000
--- a/db/post_migrate/20210427085020_backfill_ci_builds_runner_session_for_bigint_conversion.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCiBuildsRunnerSessionForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- TABLE = :ci_builds_runner_session
- COLUMNS = %i(build_id)
-
- def up
- return unless should_run?
-
- backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS)
- end
-
- def down
- return unless should_run?
-
- revert_backfill_conversion_of_integer_to_bigint(TABLE, COLUMNS)
- end
-
- private
-
- def should_run?
- Gitlab.dev_or_test_env? || Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210427212034_schedule_update_timelogs_project_id.rb b/db/post_migrate/20210427212034_schedule_update_timelogs_project_id.rb
deleted file mode 100644
index 13b802f7cb4..00000000000
--- a/db/post_migrate/20210427212034_schedule_update_timelogs_project_id.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleUpdateTimelogsProjectId < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- BATCH_SIZE = 50_000
- DELAY_INTERVAL = 2.minutes
- MIGRATION = 'UpdateTimelogsProjectId'
-
- disable_ddl_transaction!
-
- class Timelog < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'timelogs'
- self.inheritance_column = :_type_disabled
- end
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- Timelog.all,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210429143649_add_new_issues_index_for_relative_position.rb b/db/post_migrate/20210429143649_add_new_issues_index_for_relative_position.rb
deleted file mode 100644
index 50785fa94f8..00000000000
--- a/db/post_migrate/20210429143649_add_new_issues_index_for_relative_position.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class AddNewIssuesIndexForRelativePosition < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- INDEX_NAME = 'idx_issues_on_project_id_and_rel_asc_and_id'
-
- def up
- add_concurrent_index :issues, [:project_id, :relative_position, :id], name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name(:issues, INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb b/db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb
deleted file mode 100644
index 340dceda254..00000000000
--- a/db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCiBuildTraceSectionsForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- TABLE = :ci_build_trace_sections
- COLUMN = :build_id
-
- def up
- # No-op to disable the migration:
- # backfill_conversion_of_integer_to_bigint TABLE, COLUMN, batch_size: 15000, sub_batch_size: 100, primary_key: COLUMN
- end
-
- def down
- revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMN, primary_key: COLUMN
- end
-end
diff --git a/db/post_migrate/20210430130259_remove_obsolete_segments_field.rb b/db/post_migrate/20210430130259_remove_obsolete_segments_field.rb
deleted file mode 100644
index ffdd84582cb..00000000000
--- a/db/post_migrate/20210430130259_remove_obsolete_segments_field.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveObsoleteSegmentsField < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_column :analytics_devops_adoption_segments, :name
- end
- end
-
- def down
- add_column :analytics_devops_adoption_segments, :name, :text
- add_text_limit :analytics_devops_adoption_segments, :name, 255
- end
-end
diff --git a/db/post_migrate/20210430134202_copy_adoption_snapshot_namespace.rb b/db/post_migrate/20210430134202_copy_adoption_snapshot_namespace.rb
deleted file mode 100644
index d0a72ff2c43..00000000000
--- a/db/post_migrate/20210430134202_copy_adoption_snapshot_namespace.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class CopyAdoptionSnapshotNamespace < ActiveRecord::Migration[6.0]
- def up
- execute <<-SQL
- UPDATE analytics_devops_adoption_snapshots snapshots
- SET namespace_id = segments.namespace_id
- FROM analytics_devops_adoption_segments segments
- WHERE snapshots.namespace_id IS NULL AND segments.id = snapshots.segment_id
- SQL
- end
-
- def down
- execute 'UPDATE analytics_devops_adoption_snapshots SET namespace_id = NULL'
- end
-end
diff --git a/db/post_migrate/20210430135954_copy_adoption_segments_namespace.rb b/db/post_migrate/20210430135954_copy_adoption_segments_namespace.rb
deleted file mode 100644
index 04f454bea37..00000000000
--- a/db/post_migrate/20210430135954_copy_adoption_segments_namespace.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class CopyAdoptionSegmentsNamespace < ActiveRecord::Migration[6.0]
- def up
- execute <<-SQL
- UPDATE analytics_devops_adoption_segments SET display_namespace_id = namespace_id
- WHERE display_namespace_id IS NULL
- SQL
- end
-
- def down
- execute 'UPDATE analytics_devops_adoption_segments SET display_namespace_id = NULL'
- end
-end
diff --git a/db/post_migrate/20210505092746_create_partial_covering_index_for_pending_builds.rb b/db/post_migrate/20210505092746_create_partial_covering_index_for_pending_builds.rb
deleted file mode 100644
index 81fe65c1945..00000000000
--- a/db/post_migrate/20210505092746_create_partial_covering_index_for_pending_builds.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-class CreatePartialCoveringIndexForPendingBuilds < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- EXISTING_INDEX = 'index_ci_builds_runner_id_pending'
- NEW_INDEX = 'index_ci_builds_runner_id_pending_covering'
-
- def up
- disable_statement_timeout do
- execute "CREATE INDEX CONCURRENTLY #{NEW_INDEX} ON ci_builds (runner_id, id) INCLUDE (project_id) WHERE status = 'pending' AND type = 'Ci::Build'" unless index_exists_by_name?(:ci_builds, NEW_INDEX)
- end
-
- remove_concurrent_index_by_name :ci_builds, EXISTING_INDEX
- end
-
- def down
- add_concurrent_index :ci_builds, :runner_id, where: "status = 'pending' AND type = 'Ci::Build'", name: EXISTING_INDEX
-
- remove_concurrent_index_by_name :ci_builds, NEW_INDEX
- end
-end
diff --git a/db/post_migrate/20210506064413_create_namespaces_id_parent_id_inverse_partial_index.rb b/db/post_migrate/20210506064413_create_namespaces_id_parent_id_inverse_partial_index.rb
deleted file mode 100644
index 151b0f64e80..00000000000
--- a/db/post_migrate/20210506064413_create_namespaces_id_parent_id_inverse_partial_index.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class CreateNamespacesIdParentIdInversePartialIndex < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- NAME = 'index_namespaces_id_parent_id_is_not_null'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :namespaces, :id, where: 'parent_id IS NOT NULL', name: NAME
- end
-
- def down
- remove_concurrent_index :namespaces, :id, name: NAME
- end
-end
diff --git a/db/post_migrate/20210506065000_schedule_backfill_traversal_ids.rb b/db/post_migrate/20210506065000_schedule_backfill_traversal_ids.rb
deleted file mode 100644
index 5ae80c1da80..00000000000
--- a/db/post_migrate/20210506065000_schedule_backfill_traversal_ids.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleBackfillTraversalIds < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- ROOTS_MIGRATION = 'BackfillNamespaceTraversalIdsRoots'
- CHILDREN_MIGRATION = 'BackfillNamespaceTraversalIdsChildren'
- DOWNTIME = false
- BATCH_SIZE = 1_000
- SUB_BATCH_SIZE = 100
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
- def up
- # Personal namespaces and top-level groups
- final_delay = queue_background_migration_jobs_by_range_at_intervals(
- ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsRoots::Namespace.base_query,
- ROOTS_MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- other_job_arguments: [SUB_BATCH_SIZE],
- track_jobs: true
- )
- final_delay += DELAY_INTERVAL
-
- # Subgroups
- queue_background_migration_jobs_by_range_at_intervals(
- ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsChildren::Namespace.base_query,
- CHILDREN_MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- initial_delay: final_delay,
- other_job_arguments: [SUB_BATCH_SIZE],
- track_jobs: true
- )
- end
-end
diff --git a/db/post_migrate/20210511095657_add_temporary_index_for_project_topics_to_taggings.rb b/db/post_migrate/20210511095657_add_temporary_index_for_project_topics_to_taggings.rb
deleted file mode 100644
index 0d807df614c..00000000000
--- a/db/post_migrate/20210511095657_add_temporary_index_for_project_topics_to_taggings.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class AddTemporaryIndexForProjectTopicsToTaggings < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- INDEX_NAME = 'tmp_index_taggings_on_id_where_taggable_type_project_and_tags'
- INDEX_CONDITION = "taggable_type = 'Project' AND context = 'tags'"
-
- disable_ddl_transaction!
-
- def up
- # this index is used in 20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics
- add_concurrent_index :taggings, :id, where: INDEX_CONDITION, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :taggings, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics.rb b/db/post_migrate/20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics.rb
deleted file mode 100644
index 25d23b771d5..00000000000
--- a/db/post_migrate/20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleMigrateProjectTaggingsContextFromTagsToTopics < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- BATCH_SIZE = 30_000
- DELAY_INTERVAL = 2.minutes
- MIGRATION = 'MigrateProjectTaggingsContextFromTagsToTopics'
-
- disable_ddl_transaction!
-
- class Tagging < ActiveRecord::Base
- include ::EachBatch
-
- self.table_name = 'taggings'
- end
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- Tagging.where(taggable_type: 'Project', context: 'tags'),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- end
-end
diff --git a/db/post_migrate/20210511142748_schedule_drop_invalid_vulnerabilities2.rb b/db/post_migrate/20210511142748_schedule_drop_invalid_vulnerabilities2.rb
deleted file mode 100644
index 09886b85571..00000000000
--- a/db/post_migrate/20210511142748_schedule_drop_invalid_vulnerabilities2.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleDropInvalidVulnerabilities2 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- MIGRATION = 'DropInvalidVulnerabilities'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 10_000
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('vulnerabilities'),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210513155447_add_temporary_package_index_for_nuget_data_migration.rb b/db/post_migrate/20210513155447_add_temporary_package_index_for_nuget_data_migration.rb
deleted file mode 100644
index b43abab2a96..00000000000
--- a/db/post_migrate/20210513155447_add_temporary_package_index_for_nuget_data_migration.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class AddTemporaryPackageIndexForNugetDataMigration < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- INDEX_NAME = 'tmp_index_packages_on_id_where_nuget_default_temp_package'
- INDEX_CONDITION = "package_type = 4 AND name = 'NuGet.Temporary.Package' AND status = 0"
-
- disable_ddl_transaction!
-
- def up
- # this index is used in 20210513155546_backfill_nuget_temporary_packages_to_processing_status
- add_concurrent_index :packages_packages, :id, where: INDEX_CONDITION, name: INDEX_NAME
- end
-
- def down
- remove_concurrent_index_by_name :packages_packages, INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20210513155546_backfill_nuget_temporary_packages_to_processing_status.rb b/db/post_migrate/20210513155546_backfill_nuget_temporary_packages_to_processing_status.rb
deleted file mode 100644
index 8124f94b519..00000000000
--- a/db/post_migrate/20210513155546_backfill_nuget_temporary_packages_to_processing_status.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillNugetTemporaryPackagesToProcessingStatus < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- class Package < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'packages_packages'
-
- scope :nuget_temporary_packages, -> do
- # 4 is nuget package type, 0 is default status
- where(package_type: 4, name: 'NuGet.Temporary.Package', status: 0)
- end
- end
-
- def up
- Package.nuget_temporary_packages.each_batch(of: 100) do |batch|
- # 2 is processing status
- batch.update_all(status: 2)
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210513155635_remove_temporary_package_index_for_nuget_data_migration.rb b/db/post_migrate/20210513155635_remove_temporary_package_index_for_nuget_data_migration.rb
deleted file mode 100644
index eb0abba5112..00000000000
--- a/db/post_migrate/20210513155635_remove_temporary_package_index_for_nuget_data_migration.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveTemporaryPackageIndexForNugetDataMigration < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- INDEX_NAME = 'tmp_index_packages_on_id_where_nuget_default_temp_package'
- INDEX_CONDITION = "package_type = 4 AND name = 'NuGet.Temporary.Package' AND status = 0"
-
- disable_ddl_transaction!
-
- def up
- # this index was used in 20210513155546_backfill_nuget_temporary_packages_to_processing_status
- remove_concurrent_index_by_name :packages_packages, INDEX_NAME
- end
-
- def down
- add_concurrent_index :packages_packages, :id, where: INDEX_CONDITION, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb b/db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb
deleted file mode 100644
index 665d274a0ee..00000000000
--- a/db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupMoveContainerRegistryEnabledToProjectFeature < ActiveRecord::Migration[6.0]
- MIGRATION = 'MoveContainerRegistryEnabledToProjectFeature'
-
- disable_ddl_transaction!
-
- def up
- Gitlab::BackgroundMigration.steal(MIGRATION)
-
- bg_migration_job_class = define_background_migration_jobs_class
- bg_migration_job_class.where(class_name: MIGRATION, status: bg_migration_job_class.statuses['pending']).each do |job|
- Gitlab::BackgroundMigration::MoveContainerRegistryEnabledToProjectFeature.new.perform(*job.arguments)
- end
-
- bg_migration_job_class.where(class_name: MIGRATION).delete_all
- end
-
- def down
- # no-op
- end
-
- private
-
- def define_background_migration_jobs_class
- Class.new(ActiveRecord::Base) do
- self.table_name = 'background_migration_jobs'
- self.inheritance_column = :_type_disabled
-
- enum status: {
- pending: 0,
- succeeded: 1
- }
- end
- end
-end
diff --git a/db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb b/db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb
deleted file mode 100644
index 76e4a0a95bb..00000000000
--- a/db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleCleanupOrphanedLfsObjectsProjects < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- MIGRATION = 'CleanupOrphanedLfsObjectsProjects'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 50_000
-
- disable_ddl_transaction!
-
- class LfsObjectsProject < ActiveRecord::Base
- self.table_name = 'lfs_objects_projects'
-
- include ::EachBatch
- end
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(LfsObjectsProject, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
- end
-
- def down
- # NOOP
- end
-end
diff --git a/db/post_migrate/20210517075444_remove_temporary_index_for_project_topics_to_taggings.rb b/db/post_migrate/20210517075444_remove_temporary_index_for_project_topics_to_taggings.rb
deleted file mode 100644
index bfd09653695..00000000000
--- a/db/post_migrate/20210517075444_remove_temporary_index_for_project_topics_to_taggings.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveTemporaryIndexForProjectTopicsToTaggings < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- INDEX_NAME = 'tmp_index_taggings_on_id_where_taggable_type_project_and_tags'
- INDEX_CONDITION = "taggable_type = 'Project' AND context = 'tags'"
-
- disable_ddl_transaction!
-
- def up
- # this index was used in 20210511095658_schedule_migrate_project_taggings_context_from_tags_to_topics
- remove_concurrent_index_by_name :taggings, INDEX_NAME
- end
-
- def down
- add_concurrent_index :taggings, :id, where: INDEX_CONDITION, name: INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20210518001450_backfill_clusters_integration_elastic_stack_enabled.rb b/db/post_migrate/20210518001450_backfill_clusters_integration_elastic_stack_enabled.rb
deleted file mode 100644
index 6d21945af00..00000000000
--- a/db/post_migrate/20210518001450_backfill_clusters_integration_elastic_stack_enabled.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillClustersIntegrationElasticStackEnabled < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- def up
- ApplicationRecord.connection.execute(<<~SQL.squish)
- INSERT INTO clusters_integration_elasticstack(
- cluster_id,
- enabled,
- chart_version,
- created_at,
- updated_at
- )
- SELECT
- cluster_id,
- true,
- version,
- TIMEZONE('UTC', NOW()),
- TIMEZONE('UTC', NOW())
- FROM clusters_applications_elastic_stacks
- WHERE status IN (3, 11)
- ON CONFLICT(cluster_id) DO UPDATE SET
- enabled = true,
- updated_at = TIMEZONE('UTC', NOW())
- SQL
- end
-
- def down
- # Irreversible
- end
-end
diff --git a/db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb b/db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb
deleted file mode 100644
index 8583f8541c7..00000000000
--- a/db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleDisableExpirationPoliciesLinkedToNoContainerImages < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- BATCH_SIZE = 30_000
- DELAY = 2.minutes.freeze
- DOWNTIME = false
- MIGRATION = 'DisableExpirationPoliciesLinkedToNoContainerImages'
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('container_expiration_policies').where(enabled: true),
- MIGRATION,
- DELAY,
- batch_size: BATCH_SIZE,
- track_jobs: false,
- primary_column_name: :project_id
- )
- end
-
- def down
- # this migration is irreversible
-
- # we can't accuretaly know which policies were previously enabled during the background migration
- end
-end
diff --git a/db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb b/db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb
deleted file mode 100644
index 6cd9b1173b6..00000000000
--- a/db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillClustersIntegrationPrometheusEnabled < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- def up
- ApplicationRecord.connection.execute(<<~SQL.squish)
- WITH executed_at AS (VALUES (TIMEZONE('UTC', NOW())))
- INSERT INTO clusters_integration_prometheus(
- cluster_id,
- enabled,
- encrypted_alert_manager_token,
- encrypted_alert_manager_token_iv,
- created_at,
- updated_at
- )
- SELECT
- cluster_id,
- true,
- encrypted_alert_manager_token,
- encrypted_alert_manager_token_iv,
- (table executed_at),
- (table executed_at)
- FROM clusters_applications_prometheus
- WHERE status IN (
- 3, /* installed */
- 11 /* externally installed */
- )
- ON CONFLICT(cluster_id) DO UPDATE SET
- enabled = true,
- encrypted_alert_manager_token = EXCLUDED.encrypted_alert_manager_token,
- encrypted_alert_manager_token_iv = EXCLUDED.encrypted_alert_manager_token_iv,
- updated_at = (table executed_at)
- SQL
- end
-
- def down
- # Irreversible
- end
-end
diff --git a/db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb b/db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb
deleted file mode 100644
index 39dd78975da..00000000000
--- a/db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillCiBuildsMetadataForBigintConversion < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- TABLE = :ci_builds_metadata
- COLUMN = :build_id
-
- def up
- backfill_conversion_of_integer_to_bigint TABLE, COLUMN, batch_size: 15000, sub_batch_size: 100
- end
-
- def down
- revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMN
- end
-end
diff --git a/db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb b/db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb
deleted file mode 100644
index f972815cf67..00000000000
--- a/db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillEscalationPoliciesForOncallSchedules < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- # Creates a single new escalation policy for projects which have
- # existing on-call schedules. Only one schedule is expected
- # per project, but it is possible to have multiple.
- #
- # An escalation rule is created for each existing schedule,
- # configured to immediately notify the schedule of an incoming
- # alert payload unless the alert has already been acknowledged.
- # For projects with multiple schedules, the name of the first saved
- # schedule will be used for the policy's description.
- #
- # Skips projects which already have escalation policies & schedules.
- #
- # EX)
- # For these existing records:
- # Project #3
- # IncidentManagement::OncallSchedules #13
- # project_id: 3
- # name: 'Awesome Schedule'
- # description: null
- # IncidentManagement::OncallSchedules #14
- # project_id: 3
- # name: '2ndary sched'
- # description: 'Backup on-call'
- #
- # These will be inserted:
- # EscalationPolicy #1
- # project_id: 3
- # name: 'On-call Escalation Policy'
- # description: 'Immediately notify Awesome Schedule'
- # EscalationRule #1
- # policy_id: 1,
- # oncall_schedule_id: 13
- # status: 1 # Acknowledged status
- # elapsed_time_seconds: 0
- # EscalationRule #2
- # policy_id: 1,
- # oncall_schedule_id: 14
- # status: 1 # Acknowledged status
- # elapsed_time_seconds: 0
- def up
- ApplicationRecord.connection.exec_query(<<~SQL.squish)
- WITH new_escalation_policies AS (
- INSERT INTO incident_management_escalation_policies (
- project_id,
- name,
- description
- )
- SELECT
- DISTINCT ON (project_id) project_id,
- 'On-call Escalation Policy',
- CONCAT('Immediately notify ', name)
- FROM incident_management_oncall_schedules
- WHERE project_id NOT IN (
- SELECT DISTINCT project_id
- FROM incident_management_escalation_policies
- )
- ORDER BY project_id, id
- RETURNING id, project_id
- )
-
- INSERT INTO incident_management_escalation_rules (
- policy_id,
- oncall_schedule_id,
- status,
- elapsed_time_seconds
- )
- SELECT
- new_escalation_policies.id,
- incident_management_oncall_schedules.id,
- 1,
- 0
- FROM new_escalation_policies
- INNER JOIN incident_management_oncall_schedules
- ON new_escalation_policies.project_id = incident_management_oncall_schedules.project_id
- SQL
- end
-
- # There is no way to distinguish between policies created
- # via the backfill or as a result of a user creating a new
- # on-call schedule.
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb b/db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb
deleted file mode 100644
index 68bc82059bc..00000000000
--- a/db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillPkConversionForSelfManaged < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- CONVERSIONS = [
- { table: :events, columns: %i(id), sub_batch_size: 500 },
- { table: :push_event_payloads, columns: %i(event_id), sub_batch_size: 2500, primary_key: :event_id },
- { table: :ci_job_artifacts, columns: %i(id job_id), sub_batch_size: 2000 },
- { table: :ci_sources_pipelines, columns: %i(source_job_id), sub_batch_size: 100 },
- { table: :ci_build_needs, columns: %i(build_id), sub_batch_size: 1000 },
- { table: :ci_builds, columns: %i(id stage_id), sub_batch_size: 250 },
- { table: :ci_builds_runner_session, columns: %i(build_id), sub_batch_size: 5000 },
- { table: :ci_build_trace_chunks, columns: %i(build_id), sub_batch_size: 1000 }
- ]
-
- def up
- return unless should_run?
-
- CONVERSIONS.each do |conversion|
- backfill_conversion_of_integer_to_bigint(
- conversion[:table], conversion[:columns],
- sub_batch_size: conversion[:sub_batch_size], primary_key: conversion.fetch(:primary_key, :id)
- )
- end
- end
-
- def down
- return unless should_run?
-
- CONVERSIONS.each do |conversion|
- revert_backfill_conversion_of_integer_to_bigint(
- conversion[:table], conversion[:columns],
- primary_key: conversion.fetch(:primary_key, :id)
- )
- end
- end
-
- private
-
- def should_run?
- !Gitlab.com?
- end
-end
diff --git a/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb b/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb
deleted file mode 100644
index 59b41dd2008..00000000000
--- a/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class CleanUpPendingBuildsTable < ActiveRecord::Migration[6.0]
- include ::Gitlab::Database::DynamicModelHelpers
-
- BATCH_SIZE = 1000
-
- disable_ddl_transaction!
-
- def up
- return unless Gitlab.dev_or_test_env? || Gitlab.com?
-
- each_batch_range('ci_pending_builds', connection: connection, of: BATCH_SIZE) do |min, max|
- execute <<~SQL
- DELETE FROM ci_pending_builds
- USING ci_builds
- WHERE ci_builds.id = ci_pending_builds.build_id
- AND ci_builds.status != 'pending'
- AND ci_builds.type = 'Ci::Build'
- AND ci_pending_builds.id BETWEEN #{min} AND #{max}
- SQL
- end
- end
-
- def down
- # noop
- end
-end
diff --git a/db/post_migrate/20210526160133_remove_segment_selections_table.rb b/db/post_migrate/20210526160133_remove_segment_selections_table.rb
deleted file mode 100644
index 02e981b40ba..00000000000
--- a/db/post_migrate/20210526160133_remove_segment_selections_table.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveSegmentSelectionsTable < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- def up
- drop_table :analytics_devops_adoption_segment_selections
- end
-
- def down
- create_table :analytics_devops_adoption_segment_selections do |t|
- t.references :segment, index: { name: 'index_on_segment_selections_segment_id' }, null: false, foreign_key: { to_table: :analytics_devops_adoption_segments, on_delete: :cascade }
- t.bigint :group_id
- t.bigint :project_id
- t.index [:group_id, :segment_id], unique: true, name: 'index_on_segment_selections_group_id_segment_id'
- t.index [:project_id, :segment_id], unique: true, name: 'index_on_segment_selections_project_id_segment_id'
-
- t.timestamps_with_timezone
- end
- add_concurrent_foreign_key(:analytics_devops_adoption_segment_selections, :projects, column: :project_id, on_delete: :cascade)
- add_concurrent_foreign_key(:analytics_devops_adoption_segment_selections, :namespaces, column: :group_id, on_delete: :cascade)
- add_check_constraint :analytics_devops_adoption_segment_selections, '(project_id != NULL AND group_id IS NULL) OR (group_id != NULL AND project_id IS NULL)', 'segment_selection_project_id_or_group_id_required'
- end
-end
diff --git a/db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb b/db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb
deleted file mode 100644
index 8ff0e306ad5..00000000000
--- a/db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillDraftStatusOnMergeRequests < ActiveRecord::Migration[6.0]
- # include Gitlab::Database::MigrationHelpers
-
- # Marking these as no-op as the original contents caused timeouts on
- # staging. Removing the code here per
- # #https://docs.gitlab.com/ee/development/deleting_migrations.html#how-to-disable-a-data-migration
- # =>
- def up
- # no-op
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb b/db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb
deleted file mode 100644
index 6dec99c8acd..00000000000
--- a/db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class CleanUpRenameExperimentSubjectsGroupIdToNamespaceId < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers::V2
-
- disable_ddl_transaction!
-
- def up
- cleanup_concurrent_column_rename :experiment_subjects, :group_id, :namespace_id
- end
-
- def down
- undo_cleanup_concurrent_column_rename :experiment_subjects, :group_id, :namespace_id
- end
-end
diff --git a/db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb b/db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb
deleted file mode 100644
index 7aac4446c0c..00000000000
--- a/db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class FinalizeRenameInstanceStatisticsMeasurements < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- def up
- finalize_table_rename(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements)
- end
-
- def down
- undo_finalize_table_rename(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements)
- end
-end
diff --git a/db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb b/db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb
deleted file mode 100644
index 85302ee1d20..00000000000
--- a/db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-class FixTotalStageInVsa < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- disable_ddl_transaction!
-
- TOTAL_STAGE = 'Total'
-
- class GroupStage < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'analytics_cycle_analytics_group_stages'
- end
-
- def up
- GroupStage.reset_column_information
-
- GroupStage.each_batch(of: 100) do |relation|
- relation.where(name: TOTAL_STAGE, custom: false).update_all(custom: true)
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20211004120135_schedule_add_primary_email_to_emails_if_user_confirmed.rb b/db/post_migrate/20211004120135_schedule_add_primary_email_to_emails_if_user_confirmed.rb
deleted file mode 100644
index d7b213b384a..00000000000
--- a/db/post_migrate/20211004120135_schedule_add_primary_email_to_emails_if_user_confirmed.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleAddPrimaryEmailToEmailsIfUserConfirmed < Gitlab::Database::Migration[1.0]
- INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 10_000
- MIGRATION = 'AddPrimaryEmailToEmailsIfUserConfirmed'
-
- disable_ddl_transaction!
-
- class User < ActiveRecord::Base
- include ::EachBatch
-
- self.table_name = 'users'
- self.inheritance_column = :_type_disabled
- end
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- User,
- MIGRATION,
- INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
- end
-
- def down
- # intentionally blank
- end
-end
diff --git a/db/post_migrate/20211206162601_cleanup_after_add_primary_email_to_emails_if_user_confirmed.rb b/db/post_migrate/20211206162601_cleanup_after_add_primary_email_to_emails_if_user_confirmed.rb
deleted file mode 100644
index 14f6c751e4d..00000000000
--- a/db/post_migrate/20211206162601_cleanup_after_add_primary_email_to_emails_if_user_confirmed.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupAfterAddPrimaryEmailToEmailsIfUserConfirmed < Gitlab::Database::Migration[1.0]
- disable_ddl_transaction!
-
- MIGRATION_NAME = 'AddPrimaryEmailToEmailsIfUserConfirmed'
- BATCH_SIZE = 10_000
-
- # Stubbed class to access the User table
- class User < ActiveRecord::Base
- include ::EachBatch
-
- self.table_name = 'users'
- self.inheritance_column = :_type_disabled
-
- scope :confirmed, -> { where.not(confirmed_at: nil) }
-
- has_many :emails
- end
-
- # Stubbed class to access the Emails table
- class Email < ActiveRecord::Base
- self.table_name = 'emails'
- self.inheritance_column = :_type_disabled
-
- belongs_to :user
- end
-
- def up
- finalize_background_migration(MIGRATION_NAME)
-
- # Select confirmed users that do not have their primary email in the emails table,
- # and create the email record. There should be none if the background migration
- # completed, but in case there is any leftover, we deal with it synchronously.
- not_exists_condition = 'NOT EXISTS (SELECT 1 FROM emails WHERE emails.email = users.email AND emails.user_id = users.id)'
-
- User.confirmed.each_batch(of: BATCH_SIZE) do |user_batch|
- user_batch.select(:id, :email, :confirmed_at).where(not_exists_condition).each do |user|
- current_time = Time.now.utc
-
- begin
- Email.create(
- user_id: user.id,
- email: user.email,
- confirmed_at: user.confirmed_at,
- created_at: current_time,
- updated_at: current_time
- )
- rescue StandardError => error
- Gitlab::AppLogger.error("Could not add primary email #{user.email} to emails for user with ID #{user.id} due to #{error}")
- end
- end
- end
- end
-
- def down
- # Intentionally left blank
- end
-end
diff --git a/db/post_migrate/20220826152430_remove_container_repository_deprecated_geo_fields.rb b/db/post_migrate/20220826152430_remove_container_repository_deprecated_geo_fields.rb
new file mode 100644
index 00000000000..f5cb2be4ebe
--- /dev/null
+++ b/db/post_migrate/20220826152430_remove_container_repository_deprecated_geo_fields.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class RemoveContainerRepositoryDeprecatedGeoFields < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_column :geo_event_log, :container_repository_updated_event_id, :bigint
+ end
+ end
+
+ def down
+ with_lock_retries do
+ unless column_exists?(:geo_event_log, :container_repository_updated_event_id)
+ add_column(:geo_event_log, :container_repository_updated_event_id, :bigint)
+ end
+ end
+
+ add_concurrent_foreign_key :geo_event_log, :geo_container_repository_updated_events,
+ column: :container_repository_updated_event_id,
+ name: 'fk_6ada82d42a',
+ on_delete: :cascade
+
+ add_concurrent_index :geo_event_log,
+ :container_repository_updated_event_id,
+ name: 'index_geo_event_log_on_container_repository_updated_event_id'
+ end
+end
diff --git a/db/post_migrate/20220826152432_remove_container_repository_updated_events.rb b/db/post_migrate/20220826152432_remove_container_repository_updated_events.rb
new file mode 100644
index 00000000000..edce7b4e891
--- /dev/null
+++ b/db/post_migrate/20220826152432_remove_container_repository_updated_events.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class RemoveContainerRepositoryUpdatedEvents < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ drop_table :geo_container_repository_updated_events
+ end
+
+ def down
+ create_table :geo_container_repository_updated_events, id: :bigserial do |t|
+ t.integer :container_repository_id,
+ null: false,
+ index: { name: :idx_geo_con_rep_updated_events_on_container_repository_id }
+ end
+
+ add_concurrent_foreign_key :geo_container_repository_updated_events, :container_repositories,
+ column: :container_repository_id,
+ name: 'fk_212c89c706',
+ on_delete: :cascade
+ end
+end
diff --git a/db/post_migrate/20221102231131_remove_temp_index_for_user_details_fields.rb b/db/post_migrate/20221102231131_remove_temp_index_for_user_details_fields.rb
new file mode 100644
index 00000000000..340d1205ef7
--- /dev/null
+++ b/db/post_migrate/20221102231131_remove_temp_index_for_user_details_fields.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class RemoveTempIndexForUserDetailsFields < Gitlab::Database::Migration[2.0]
+ BACKFILL_MIGRATION = 'BackfillUserDetailsFields'
+ INDEX_NAME = 'tmp_idx_where_user_details_fields_filled'
+
+ disable_ddl_transaction!
+
+ def up
+ finalize_background_migration BACKFILL_MIGRATION
+ remove_concurrent_index_by_name :users, INDEX_NAME
+ end
+
+ def down
+ # rubocop:disable Migration/PreventIndexCreation
+ add_concurrent_index :users, :id, name: INDEX_NAME, where: <<~QUERY
+ (COALESCE(linkedin, '') IS DISTINCT FROM '')
+ OR (COALESCE(twitter, '') IS DISTINCT FROM '')
+ OR (COALESCE(skype, '') IS DISTINCT FROM '')
+ OR (COALESCE(website_url, '') IS DISTINCT FROM '')
+ OR (COALESCE(location, '') IS DISTINCT FROM '')
+ OR (COALESCE(organization, '') IS DISTINCT FROM '')
+ QUERY
+ # rubocop:enable Migration/PreventIndexCreation
+ end
+end
diff --git a/db/post_migrate/20221110100600_add_temp_index_on_overlong_vulnerability_html_title.rb b/db/post_migrate/20221110100600_add_temp_index_on_overlong_vulnerability_html_title.rb
new file mode 100644
index 00000000000..5ff56874e11
--- /dev/null
+++ b/db/post_migrate/20221110100600_add_temp_index_on_overlong_vulnerability_html_title.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddTempIndexOnOverlongVulnerabilityHtmlTitle < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'tmp_index_vulnerability_overlong_title_html'
+
+ disable_ddl_transaction!
+
+ def up
+ # Temporary index to speed up the truncation of vulnerabilities with invalid html title length
+ add_concurrent_index :vulnerabilities, [:id],
+ name: INDEX_NAME,
+ where: "LENGTH(title_html) > 800"
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221110100602_queue_truncate_overlong_vulnerability_html_titles.rb b/db/post_migrate/20221110100602_queue_truncate_overlong_vulnerability_html_titles.rb
new file mode 100644
index 00000000000..48301498c5a
--- /dev/null
+++ b/db/post_migrate/20221110100602_queue_truncate_overlong_vulnerability_html_titles.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class QueueTruncateOverlongVulnerabilityHtmlTitles < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'TruncateOverlongVulnerabilityHtmlTitles'
+ INTERVAL = 2.minutes
+ BATCH_SIZE = 1_000
+ MAX_BATCH_SIZE = 10_000
+ SUB_BATCH_SIZE = 200
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :vulnerabilities,
+ :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, :vulnerabilities, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221209235939_add_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb b/db/post_migrate/20221209235939_add_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb
new file mode 100644
index 00000000000..0f313f420f0
--- /dev/null
+++ b/db/post_migrate/20221209235939_add_tmp_index_oauth_access_tokens_on_id_where_expires_in_null.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddTmpIndexOauthAccessTokensOnIdWhereExpiresInNull < Gitlab::Database::Migration[2.1]
+ TMP_INDEX = 'tmp_index_oauth_access_tokens_on_id_where_expires_in_null'
+
+ disable_ddl_transaction!
+
+ def up
+ # Temporary index to be removed in %15.9 or later https://gitlab.com/gitlab-org/gitlab/-/issues/385343
+ add_concurrent_index :oauth_access_tokens, :id, where: "expires_in IS NULL", name: TMP_INDEX
+ end
+
+ def down
+ remove_concurrent_index_by_name :oauth_access_tokens, TMP_INDEX
+ end
+end
diff --git a/db/post_migrate/20221209235940_cleanup_o_auth_access_tokens_with_null_expires_in.rb b/db/post_migrate/20221209235940_cleanup_o_auth_access_tokens_with_null_expires_in.rb
new file mode 100644
index 00000000000..8daf5bf4d93
--- /dev/null
+++ b/db/post_migrate/20221209235940_cleanup_o_auth_access_tokens_with_null_expires_in.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class CleanupOAuthAccessTokensWithNullExpiresIn < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'ReExpireOAuthTokens'
+ INTERVAL = 2.minutes
+ MAX_BATCH_SIZE = 50_000
+
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :oauth_access_tokens,
+ :id,
+ job_interval: INTERVAL,
+ max_batch_size: MAX_BATCH_SIZE
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :oauth_access_tokens, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221214095129_second_recount_epic_cache_counts.rb b/db/post_migrate/20221214095129_second_recount_epic_cache_counts.rb
new file mode 100644
index 00000000000..608e27c344e
--- /dev/null
+++ b/db/post_migrate/20221214095129_second_recount_epic_cache_counts.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class SecondRecountEpicCacheCounts < Gitlab::Database::Migration[2.0]
+ MIGRATION = 'SecondRecountEpicCacheCounts'
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 200
+ MAX_BATCH_SIZE = 1000
+ SUB_BATCH_SIZE = 20
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :epics,
+ :id,
+ job_interval: DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ max_batch_size: MAX_BATCH_SIZE,
+ sub_batch_size: SUB_BATCH_SIZE,
+ gitlab_schema: :gitlab_main
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :epics, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221214105307_add_token_encrypted_partition_id_index_to_ci_build.rb b/db/post_migrate/20221214105307_add_token_encrypted_partition_id_index_to_ci_build.rb
new file mode 100644
index 00000000000..4c64e9b0e70
--- /dev/null
+++ b/db/post_migrate/20221214105307_add_token_encrypted_partition_id_index_to_ci_build.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AddTokenEncryptedPartitionIdIndexToCiBuild < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_builds
+ INDEX_NAME = :unique_ci_builds_token_encrypted_and_partition_id
+ COLUMNS = %i[token_encrypted partition_id].freeze
+
+ def up
+ prepare_async_index(
+ TABLE_NAME,
+ COLUMNS,
+ where: 'token_encrypted IS NOT NULL',
+ unique: true,
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ unprepare_async_index(TABLE_NAME, COLUMNS, name: INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20221215151822_schedule_backfill_releases_author_id.rb b/db/post_migrate/20221215151822_schedule_backfill_releases_author_id.rb
new file mode 100644
index 00000000000..4d8343ca2dd
--- /dev/null
+++ b/db/post_migrate/20221215151822_schedule_backfill_releases_author_id.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+class ScheduleBackfillReleasesAuthorId < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'BackfillReleasesAuthorId'
+ JOB_DELAY_INTERVAL = 2.minutes
+ GHOST_USER_TYPE = 5
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ class User < MigrationRecord
+ self.table_name = 'users'
+ end
+
+ class Release < MigrationRecord
+ self.table_name = 'releases'
+ end
+
+ def up
+ unless release_with_empty_author_exists?
+ say "There are no releases with empty author_id, so skipping migration #{self.class.name}"
+ return
+ end
+
+ create_ghost_user if ghost_user_id.nil?
+
+ queue_batched_background_migration(
+ MIGRATION,
+ :releases,
+ :id,
+ ghost_user_id,
+ job_interval: JOB_DELAY_INTERVAL
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :releases, :id, [ghost_user_id])
+ end
+
+ private
+
+ def ghost_user_id
+ User.find_by(user_type: GHOST_USER_TYPE)&.id
+ end
+
+ def create_ghost_user
+ user = User.new
+ user.name = 'Ghost User'
+ user.username = 'ghost'
+ user.email = 'ghost@example.com'
+ user.user_type = GHOST_USER_TYPE
+ user.projects_limit = 100000
+
+ user.save!
+ end
+
+ def release_with_empty_author_exists?
+ Release.exists?(author_id: nil)
+ end
+end
diff --git a/db/post_migrate/20221216131710_add_index_to_ci_unit_test_failure.rb b/db/post_migrate/20221216131710_add_index_to_ci_unit_test_failure.rb
new file mode 100644
index 00000000000..f99d2914aa4
--- /dev/null
+++ b/db/post_migrate/20221216131710_add_index_to_ci_unit_test_failure.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToCiUnitTestFailure < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = :index_ci_unit_test_failures_on_partition_id_build_id
+ TABLE_NAME = :ci_unit_test_failures
+ COLUMNS = [:partition_id, :build_id]
+
+ def up
+ add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20221216131935_add_index_to_ci_build_pending_state.rb b/db/post_migrate/20221216131935_add_index_to_ci_build_pending_state.rb
new file mode 100644
index 00000000000..4fec5e016a4
--- /dev/null
+++ b/db/post_migrate/20221216131935_add_index_to_ci_build_pending_state.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToCiBuildPendingState < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = :index_ci_build_pending_states_on_partition_id_build_id
+ TABLE_NAME = :ci_build_pending_states
+ COLUMNS = [:partition_id, :build_id]
+
+ def up
+ add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20221216131958_add_index_to_ci_build_trace_chunk.rb b/db/post_migrate/20221216131958_add_index_to_ci_build_trace_chunk.rb
new file mode 100644
index 00000000000..5577a18c144
--- /dev/null
+++ b/db/post_migrate/20221216131958_add_index_to_ci_build_trace_chunk.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToCiBuildTraceChunk < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = :index_ci_build_trace_chunks_on_partition_id_build_id
+ TABLE_NAME = :ci_build_trace_chunks
+ COLUMNS = [:partition_id, :build_id]
+
+ def up
+ add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20221216144854_add_foreign_key_to_ci_unit_test_failure.rb b/db/post_migrate/20221216144854_add_foreign_key_to_ci_unit_test_failure.rb
new file mode 100644
index 00000000000..e04647d7c92
--- /dev/null
+++ b/db/post_migrate/20221216144854_add_foreign_key_to_ci_unit_test_failure.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToCiUnitTestFailure < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ SOURCE_TABLE_NAME = :ci_unit_test_failures
+ TARGET_TABLE_NAME = :ci_builds
+ COLUMN = :build_id
+ TARGET_COLUMN = :id
+ FK_NAME = :fk_0f09856e1f_p
+ PARTITION_COLUMN = :partition_id
+
+ def up
+ add_concurrent_foreign_key(
+ SOURCE_TABLE_NAME,
+ TARGET_TABLE_NAME,
+ column: [PARTITION_COLUMN, COLUMN],
+ target_column: [PARTITION_COLUMN, TARGET_COLUMN],
+ validate: false,
+ reverse_lock_order: true,
+ name: FK_NAME
+ )
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME)
+ end
+ end
+end
diff --git a/db/post_migrate/20221216150304_add_foreign_key_to_ci_build_pending_state.rb b/db/post_migrate/20221216150304_add_foreign_key_to_ci_build_pending_state.rb
new file mode 100644
index 00000000000..ef9ecc3033f
--- /dev/null
+++ b/db/post_migrate/20221216150304_add_foreign_key_to_ci_build_pending_state.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToCiBuildPendingState < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ SOURCE_TABLE_NAME = :ci_build_pending_states
+ TARGET_TABLE_NAME = :ci_builds
+ COLUMN = :build_id
+ TARGET_COLUMN = :id
+ FK_NAME = :fk_rails_0bbbfeaf9d_p
+ PARTITION_COLUMN = :partition_id
+
+ def up
+ add_concurrent_foreign_key(
+ SOURCE_TABLE_NAME,
+ TARGET_TABLE_NAME,
+ column: [PARTITION_COLUMN, COLUMN],
+ target_column: [PARTITION_COLUMN, TARGET_COLUMN],
+ validate: false,
+ reverse_lock_order: true,
+ name: FK_NAME
+ )
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME)
+ end
+ end
+end
diff --git a/db/post_migrate/20221216150321_add_foreign_key_to_ci_build_trace_chunk.rb b/db/post_migrate/20221216150321_add_foreign_key_to_ci_build_trace_chunk.rb
new file mode 100644
index 00000000000..dd16d3d7787
--- /dev/null
+++ b/db/post_migrate/20221216150321_add_foreign_key_to_ci_build_trace_chunk.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToCiBuildTraceChunk < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ SOURCE_TABLE_NAME = :ci_build_trace_chunks
+ TARGET_TABLE_NAME = :ci_builds
+ COLUMN = :build_id
+ TARGET_COLUMN = :id
+ FK_NAME = :fk_rails_1013b761f2_p
+ PARTITION_COLUMN = :partition_id
+
+ def up
+ add_concurrent_foreign_key(
+ SOURCE_TABLE_NAME,
+ TARGET_TABLE_NAME,
+ column: [PARTITION_COLUMN, COLUMN],
+ target_column: [PARTITION_COLUMN, TARGET_COLUMN],
+ validate: false,
+ reverse_lock_order: true,
+ name: FK_NAME
+ )
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME)
+ end
+ end
+end
diff --git a/db/post_migrate/20221216150919_validate_foreign_key_on_ci_unit_test_failure_partition_id_build_id.rb b/db/post_migrate/20221216150919_validate_foreign_key_on_ci_unit_test_failure_partition_id_build_id.rb
new file mode 100644
index 00000000000..a886949aea7
--- /dev/null
+++ b/db/post_migrate/20221216150919_validate_foreign_key_on_ci_unit_test_failure_partition_id_build_id.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class ValidateForeignKeyOnCiUnitTestFailurePartitionIdBuildId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_unit_test_failures
+ FK_NAME = :fk_0f09856e1f_p
+ PARTITION_COLUMN = :partition_id
+ COLUMN = :build_id
+
+ def up
+ validate_foreign_key(TABLE_NAME, [PARTITION_COLUMN, COLUMN], name: FK_NAME)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221216151459_validate_foreign_key_on_ci_build_pending_state_partition_id_build_id.rb b/db/post_migrate/20221216151459_validate_foreign_key_on_ci_build_pending_state_partition_id_build_id.rb
new file mode 100644
index 00000000000..6ea8cb213ab
--- /dev/null
+++ b/db/post_migrate/20221216151459_validate_foreign_key_on_ci_build_pending_state_partition_id_build_id.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class ValidateForeignKeyOnCiBuildPendingStatePartitionIdBuildId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_build_pending_states
+ FK_NAME = :fk_rails_0bbbfeaf9d_p
+ PARTITION_COLUMN = :partition_id
+ COLUMN = :build_id
+
+ def up
+ validate_foreign_key(TABLE_NAME, [PARTITION_COLUMN, COLUMN], name: FK_NAME)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221216151649_validate_foreign_key_on_ci_build_trace_chunk_partition_id_build_id.rb b/db/post_migrate/20221216151649_validate_foreign_key_on_ci_build_trace_chunk_partition_id_build_id.rb
new file mode 100644
index 00000000000..8afd7de808b
--- /dev/null
+++ b/db/post_migrate/20221216151649_validate_foreign_key_on_ci_build_trace_chunk_partition_id_build_id.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class ValidateForeignKeyOnCiBuildTraceChunkPartitionIdBuildId < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_build_trace_chunks
+ FK_NAME = :fk_rails_1013b761f2_p
+ PARTITION_COLUMN = :partition_id
+ COLUMN = :build_id
+
+ def up
+ validate_foreign_key(TABLE_NAME, [PARTITION_COLUMN, COLUMN], name: FK_NAME)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221216232658_index_members_on_member_namespace_id_compound.rb b/db/post_migrate/20221216232658_index_members_on_member_namespace_id_compound.rb
new file mode 100644
index 00000000000..56adad1e4a5
--- /dev/null
+++ b/db/post_migrate/20221216232658_index_members_on_member_namespace_id_compound.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class IndexMembersOnMemberNamespaceIdCompound < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_members_on_member_namespace_id_compound'
+
+ disable_ddl_transaction!
+
+ def up
+ prepare_async_index(
+ :members,
+ [:member_namespace_id, :type, :requested_at, :id],
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name :members, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221216232659_index_members_on_member_namespace_id_compound_sync.rb b/db/post_migrate/20221216232659_index_members_on_member_namespace_id_compound_sync.rb
new file mode 100644
index 00000000000..f37a1b694b4
--- /dev/null
+++ b/db/post_migrate/20221216232659_index_members_on_member_namespace_id_compound_sync.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class IndexMembersOnMemberNamespaceIdCompoundSync < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_members_on_member_namespace_id_compound'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(
+ :members,
+ [:member_namespace_id, :type, :requested_at, :id],
+ name: INDEX_NAME
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name :members, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20221220075936_add_query_index_for_ci_pipeline_schedules.rb b/db/post_migrate/20221220075936_add_query_index_for_ci_pipeline_schedules.rb
new file mode 100644
index 00000000000..4fc64f66a83
--- /dev/null
+++ b/db/post_migrate/20221220075936_add_query_index_for_ci_pipeline_schedules.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddQueryIndexForCiPipelineSchedules < Gitlab::Database::Migration[2.1]
+ TABLE_NAME = :ci_pipeline_schedules
+ INDEX_NAME = :index_ci_pipeline_schedules_on_id_and_next_run_at_and_active
+ COLUMNS = %i[id next_run_at].freeze
+ INDEX_CONDITION = 'active = TRUE'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME, where: INDEX_CONDITION)
+ end
+
+ def down
+ remove_concurrent_index(TABLE_NAME, COLUMNS, name: INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20221220131020_bump_default_partition_id_value_for_ci_tables.rb b/db/post_migrate/20221220131020_bump_default_partition_id_value_for_ci_tables.rb
new file mode 100644
index 00000000000..3d06f02a6d6
--- /dev/null
+++ b/db/post_migrate/20221220131020_bump_default_partition_id_value_for_ci_tables.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class BumpDefaultPartitionIdValueForCiTables < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLES = {
+ ci_build_needs: [:partition_id],
+ ci_build_pending_states: [:partition_id],
+ ci_build_report_results: [:partition_id],
+ ci_build_trace_chunks: [:partition_id],
+ ci_build_trace_metadata: [:partition_id],
+ ci_builds: [:partition_id],
+ ci_builds_runner_session: [:partition_id],
+ ci_job_artifacts: [:partition_id],
+ ci_job_variables: [:partition_id],
+ ci_pending_builds: [:partition_id],
+ ci_pipeline_variables: [:partition_id],
+ ci_pipelines: [:partition_id],
+ ci_running_builds: [:partition_id],
+ ci_sources_pipelines: [:partition_id, :source_partition_id],
+ ci_stages: [:partition_id],
+ ci_unit_test_failures: [:partition_id],
+ p_ci_builds_metadata: [:partition_id]
+ }
+
+ def up
+ change_partitions_default_value(from: 100, to: 101)
+ end
+
+ def down
+ change_partitions_default_value(from: 101, to: 100)
+ end
+
+ private
+
+ def change_partitions_default_value(from:, to:)
+ return unless Gitlab.com?
+
+ TABLES.each do |table_name, columns|
+ next if columns.all? { |column_name| default_value_for(table_name, column_name) == to }
+
+ with_lock_retries do
+ columns.each do |column_name| # rubocop:disable Migration/WithLockRetriesDisallowedMethod
+ change_column_default(table_name, column_name, from: from, to: to)
+ end
+ end
+ end
+ end
+
+ def default_value_for(table_name, column_name)
+ connection
+ .columns(table_name)
+ .find { |column| column.name == column_name.to_s }
+ .default&.to_i
+ end
+end
diff --git a/db/post_migrate/20221221110733_remove_temp_index_for_project_statistics_upload_size_migration.rb b/db/post_migrate/20221221110733_remove_temp_index_for_project_statistics_upload_size_migration.rb
new file mode 100644
index 00000000000..1df6ad274f9
--- /dev/null
+++ b/db/post_migrate/20221221110733_remove_temp_index_for_project_statistics_upload_size_migration.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveTempIndexForProjectStatisticsUploadSizeMigration < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'tmp_index_project_statistics_uploads_size'
+ TABLE_NAME = 'project_statistics'
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :project_statistics, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :project_statistics, [:project_id],
+ name: INDEX_NAME,
+ where: "uploads_size <> 0"
+ end
+end
diff --git a/db/post_migrate/20221221150123_update_billable_users_index.rb b/db/post_migrate/20221221150123_update_billable_users_index.rb
new file mode 100644
index 00000000000..d2f55e06b0b
--- /dev/null
+++ b/db/post_migrate/20221221150123_update_billable_users_index.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class UpdateBillableUsersIndex < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ NEW_INDEX = 'index_users_for_billable_users'
+ OLD_INDEX = 'index_users_for_active_billable'
+
+ OLD_INDEX_CONDITION = <<~QUERY
+ ((state)::text = 'active'::text) AND ((user_type IS NULL)
+ OR (user_type = ANY (ARRAY[NULL::integer, 6, 4]))) AND ((user_type IS NULL)
+ OR (user_type <> ALL ('{1,2,3,4,5,6,7,8,9,11}'::smallint[])))
+ QUERY
+ NEW_INDEX_CONDITION = <<~QUERY
+ state = 'active' AND (user_type IS NULL OR user_type IN (6, 4)) AND (user_type IS NULL OR user_type IN (4, 5))
+ QUERY
+
+ def up
+ add_concurrent_index(:users, :id, where: NEW_INDEX_CONDITION, name: NEW_INDEX)
+ remove_concurrent_index_by_name(:users, OLD_INDEX)
+ end
+
+ def down
+ add_concurrent_index(:users, :id, where: OLD_INDEX_CONDITION, name: OLD_INDEX)
+ remove_concurrent_index_by_name(:users, NEW_INDEX)
+ end
+end
diff --git a/db/post_migrate/20221222092958_sync_new_amount_used_with_amount_used.rb b/db/post_migrate/20221222092958_sync_new_amount_used_with_amount_used.rb
new file mode 100644
index 00000000000..9d8e2ee54d6
--- /dev/null
+++ b/db/post_migrate/20221222092958_sync_new_amount_used_with_amount_used.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class SyncNewAmountUsedWithAmountUsed < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ def up
+ # This migration will only run on rollback, there is no need for the positive case
+ end
+
+ def down
+ project_usages = define_batchable_model('ci_project_monthly_usages')
+
+ project_usages.each_batch(of: 500) do |batch|
+ batch.where('amount_used > 0').update_all('new_amount_used = amount_used')
+ end
+ end
+end
diff --git a/db/post_migrate/20221223123019_delete_queued_jobs_for_vulnerabilities_feedback_migration.rb b/db/post_migrate/20221223123019_delete_queued_jobs_for_vulnerabilities_feedback_migration.rb
new file mode 100644
index 00000000000..e5822d2d7a2
--- /dev/null
+++ b/db/post_migrate/20221223123019_delete_queued_jobs_for_vulnerabilities_feedback_migration.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class DeleteQueuedJobsForVulnerabilitiesFeedbackMigration < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'MigrateVulnerabilitiesFeedbackToVulnerabilitiesStateTransition'
+ TABLE_NAME = :vulnerability_feedback
+ BATCH_COLUMN = :id
+
+ disable_ddl_transaction!
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ delete_batched_background_migration(
+ MIGRATION,
+ TABLE_NAME,
+ BATCH_COLUMN,
+ []
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20221226153240_remove_chat_names_integration_id_foreign_key.rb b/db/post_migrate/20221226153240_remove_chat_names_integration_id_foreign_key.rb
new file mode 100644
index 00000000000..51baa9c9f57
--- /dev/null
+++ b/db/post_migrate/20221226153240_remove_chat_names_integration_id_foreign_key.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class RemoveChatNamesIntegrationIdForeignKey < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ SOURCE_TABLE_NAME = :chat_names
+ TARGET_TABLE_NAME = :integrations
+ COLUMN = :integration_id
+ TARGET_COLUMN = :id
+ FK_NAME = :fk_99a1348daf
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(
+ SOURCE_TABLE_NAME,
+ TARGET_TABLE_NAME,
+ column: COLUMN,
+ name: FK_NAME,
+ on_delete: :cascade
+ )
+ end
+end
diff --git a/db/post_migrate/20221226154458_drop_index_on_chat_names_on_integration_id_and_team_id_and_chat_id.rb b/db/post_migrate/20221226154458_drop_index_on_chat_names_on_integration_id_and_team_id_and_chat_id.rb
new file mode 100644
index 00000000000..d5aeb704983
--- /dev/null
+++ b/db/post_migrate/20221226154458_drop_index_on_chat_names_on_integration_id_and_team_id_and_chat_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DropIndexOnChatNamesOnIntegrationIdAndTeamIdAndChatId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_chat_names_on_integration_id_and_team_id_and_chat_id'
+
+ def up
+ remove_concurrent_index_by_name(:chat_names, INDEX_NAME)
+ end
+
+ def down
+ add_concurrent_index(:chat_names, [:integration_id, :team_id, :chat_id], name: INDEX_NAME, unique: true)
+ end
+end
diff --git a/db/post_migrate/20221227100751_add_user_index_to_chat_names.rb b/db/post_migrate/20221227100751_add_user_index_to_chat_names.rb
new file mode 100644
index 00000000000..7be671b2cbd
--- /dev/null
+++ b/db/post_migrate/20221227100751_add_user_index_to_chat_names.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddUserIndexToChatNames < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_chat_names_on_user_id'
+
+ def up
+ add_concurrent_index(:chat_names, :user_id, name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index_by_name(:chat_names, name: INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20221227101436_drop_index_on_chat_names_on_user_id_and_integration_id.rb b/db/post_migrate/20221227101436_drop_index_on_chat_names_on_user_id_and_integration_id.rb
new file mode 100644
index 00000000000..ab2842ea775
--- /dev/null
+++ b/db/post_migrate/20221227101436_drop_index_on_chat_names_on_user_id_and_integration_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DropIndexOnChatNamesOnUserIdAndIntegrationId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_chat_names_on_user_id_and_integration_id'
+
+ def up
+ remove_concurrent_index_by_name(:chat_names, INDEX_NAME)
+ end
+
+ def down
+ add_concurrent_index(:chat_names, [:user_id, :integration_id], name: INDEX_NAME, unique: true)
+ end
+end
diff --git a/db/post_migrate/20221228103133_queue_backfill_admin_mode_scope_for_personal_access_tokens.rb b/db/post_migrate/20221228103133_queue_backfill_admin_mode_scope_for_personal_access_tokens.rb
new file mode 100644
index 00000000000..c111d5090e1
--- /dev/null
+++ b/db/post_migrate/20221228103133_queue_backfill_admin_mode_scope_for_personal_access_tokens.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class QueueBackfillAdminModeScopeForPersonalAccessTokens < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'BackfillAdminModeScopeForPersonalAccessTokens'
+ DELAY_INTERVAL = 2.minutes
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :personal_access_tokens,
+ :id,
+ job_interval: DELAY_INTERVAL
+ )
+ end
+
+ def down
+ delete_batched_background_migration(MIGRATION, :personal_access_tokens, :id, [])
+ end
+end
diff --git a/db/post_migrate/20221228163035_cleanup_appearances_short_title_rename.rb b/db/post_migrate/20221228163035_cleanup_appearances_short_title_rename.rb
new file mode 100644
index 00000000000..300d53f227a
--- /dev/null
+++ b/db/post_migrate/20221228163035_cleanup_appearances_short_title_rename.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class CleanupAppearancesShortTitleRename < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ def up
+ cleanup_concurrent_column_rename :appearances, :short_title, :pwa_short_name
+ end
+
+ def down
+ undo_cleanup_concurrent_column_rename :appearances, :short_title, :pwa_short_name
+ end
+end
diff --git a/db/post_migrate/20221228210616_add_index_on_ci_runners_on_runner_type_and_id.rb b/db/post_migrate/20221228210616_add_index_on_ci_runners_on_runner_type_and_id.rb
new file mode 100644
index 00000000000..62c40b78945
--- /dev/null
+++ b/db/post_migrate/20221228210616_add_index_on_ci_runners_on_runner_type_and_id.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddIndexOnCiRunnersOnRunnerTypeAndId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ OLD_INDEX_NAME = 'index_ci_runners_on_runner_type'
+ NEW_INDEX_NAME = 'index_ci_runners_on_runner_type_and_id'
+
+ def up
+ add_concurrent_index :ci_runners, [:runner_type, :id], name: NEW_INDEX_NAME
+ remove_concurrent_index_by_name :ci_runners, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :ci_runners, :runner_type, name: OLD_INDEX_NAME
+ remove_concurrent_index_by_name :ci_runners, NEW_INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230104103748_remove_new_amount_used_column.rb b/db/post_migrate/20230104103748_remove_new_amount_used_column.rb
new file mode 100644
index 00000000000..0aaa7c1bd8f
--- /dev/null
+++ b/db/post_migrate/20230104103748_remove_new_amount_used_column.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class RemoveNewAmountUsedColumn < Gitlab::Database::Migration[2.1]
+ TRIGGER_NAME = 'sync_projects_amount_used_columns'
+ def up
+ remove_rename_triggers :ci_project_monthly_usages, TRIGGER_NAME
+ remove_column :ci_project_monthly_usages, :new_amount_used
+ end
+
+ def down
+ return if column_exists?(:ci_project_monthly_usages, :new_amount_used)
+
+ # rubocop:disable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ add_column :ci_project_monthly_usages, :new_amount_used, :decimal, default: 0.0,
+ precision: 18, scale: 2, null: false
+ # rubocop:enable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+
+ install_rename_triggers :ci_project_monthly_usages, :amount_used, :new_amount_used, trigger_name: TRIGGER_NAME
+ end
+end
diff --git a/db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb b/db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb
new file mode 100644
index 00000000000..83dfe62ad71
--- /dev/null
+++ b/db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class PrepareBuildsMetadataAsyncIdx < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'p_ci_builds_metadata_on_runner_machine_id_idx'
+
+ def up
+ # Break up the logic from add_concurrent_partitioned_index so that the partition indices can be created async
+ # A follow-up migration will complete the index creation by creating the index on the metadata table, and
+ # creating the concurrent foreign key
+ each_partition(:p_ci_builds_metadata) do |partition, partition_index_name|
+ prepare_async_index(partition.identifier, :runner_machine_id,
+ name: partition_index_name, where: 'runner_machine_id IS NOT NULL')
+ end
+ end
+
+ def down
+ each_partition(:p_ci_builds_metadata) do |partition, partition_index_name|
+ unprepare_async_index_by_name(partition.identifier, partition_index_name)
+ end
+ end
+
+ private
+
+ def each_partition(table_name)
+ partitioned_table = find_partitioned_table(table_name)
+ partitioned_table.postgres_partitions.order(:name).each do |partition|
+ partition_index_name = generated_index_name(partition.identifier, INDEX_NAME)
+
+ yield partition, partition_index_name
+ end
+ end
+end
diff --git a/db/post_migrate/20230104220137_reindex_vuln_reads_on_default_branch_with_common_query.rb b/db/post_migrate/20230104220137_reindex_vuln_reads_on_default_branch_with_common_query.rb
new file mode 100644
index 00000000000..114a1a84fa0
--- /dev/null
+++ b/db/post_migrate/20230104220137_reindex_vuln_reads_on_default_branch_with_common_query.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class ReindexVulnReadsOnDefaultBranchWithCommonQuery < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_vuln_reads_common_query_on_resolved_on_default_branch'
+
+ COLUMNS = %i[project_id state report_type vulnerability_id]
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(
+ :vulnerability_reads,
+ COLUMNS,
+ name: INDEX_NAME,
+ where: 'resolved_on_default_branch IS TRUE',
+ order: { vulnerability_id: :desc }
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name(
+ :vulnerability_reads,
+ INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20230104224020_drop_vuln_reads_on_default_branch_index.rb b/db/post_migrate/20230104224020_drop_vuln_reads_on_default_branch_index.rb
new file mode 100644
index 00000000000..acac69478a3
--- /dev/null
+++ b/db/post_migrate/20230104224020_drop_vuln_reads_on_default_branch_index.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class DropVulnReadsOnDefaultBranchIndex < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_vuln_reads_on_resolved_on_default_branch'
+
+ COLUMNS = %i[project_id state id]
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :vulnerability_reads, name: INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :vulnerability_reads, COLUMNS,
+ where: 'resolved_on_default_branch IS TRUE',
+ name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230105172120_sync_new_amount_used_with_amount_used_on_ci_namespace_monthly_usages_table.rb b/db/post_migrate/20230105172120_sync_new_amount_used_with_amount_used_on_ci_namespace_monthly_usages_table.rb
new file mode 100644
index 00000000000..4181d6a0f92
--- /dev/null
+++ b/db/post_migrate/20230105172120_sync_new_amount_used_with_amount_used_on_ci_namespace_monthly_usages_table.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class SyncNewAmountUsedWithAmountUsedOnCiNamespaceMonthlyUsagesTable < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_ci
+
+ def up
+ # This migration will only run on rollback, there is no need for the positive case
+ end
+
+ def down
+ project_usages = define_batchable_model('ci_namespace_monthly_usages')
+
+ project_usages.each_batch(of: 500) do |batch|
+ batch.where('amount_used > 0').update_all('new_amount_used = amount_used')
+ end
+ end
+end
diff --git a/db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb b/db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb
new file mode 100644
index 00000000000..cebda3e353e
--- /dev/null
+++ b/db/post_migrate/20230105180002_remove_new_amount_used_column_on_ci_namespace_monthly_usages.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class RemoveNewAmountUsedColumnOnCiNamespaceMonthlyUsages < Gitlab::Database::Migration[2.1]
+ enable_lock_retries!
+
+ TRIGGER_NAME = 'sync_namespaces_amount_used_columns'
+ def up
+ remove_rename_triggers :ci_namespace_monthly_usages, TRIGGER_NAME
+ remove_column :ci_namespace_monthly_usages, :new_amount_used
+ end
+
+ def down
+ return if column_exists?(:ci_namespace_monthly_usages, :new_amount_used)
+
+ # rubocop:disable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+ add_column :ci_namespace_monthly_usages, :new_amount_used, :decimal, default: 0.0,
+ precision: 18, scale: 2, null: false
+ # rubocop:enable Migration/SchemaAdditionMethodsNoPost, Migration/AddColumnsToWideTables
+
+ install_rename_triggers :ci_namespace_monthly_usages, :amount_used, :new_amount_used, trigger_name: TRIGGER_NAME
+ end
+end
diff --git a/db/post_migrate/20230106124332_change_keys_relation_to_ssh_signatures.rb b/db/post_migrate/20230106124332_change_keys_relation_to_ssh_signatures.rb
new file mode 100644
index 00000000000..e76a3617ba3
--- /dev/null
+++ b/db/post_migrate/20230106124332_change_keys_relation_to_ssh_signatures.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class ChangeKeysRelationToSshSignatures < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TARGET_COLUMN = :key_id
+
+ def up
+ add_concurrent_foreign_key(
+ :ssh_signatures,
+ :keys,
+ column: :key_id,
+ name: fk_name("#{TARGET_COLUMN}_nullify"),
+ on_delete: :nullify
+ )
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ssh_signatures, column: TARGET_COLUMN, name: fk_name(TARGET_COLUMN))
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(
+ :ssh_signatures,
+ :keys,
+ column: :key_id,
+ name: fk_name(TARGET_COLUMN),
+ on_delete: :cascade
+ )
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ssh_signatures, column: TARGET_COLUMN, name: fk_name("#{TARGET_COLUMN}_nullify"))
+ end
+ end
+
+ private
+
+ def fk_name(column_name)
+ concurrent_foreign_key_name(:ssh_signatures, column_name)
+ end
+end
diff --git a/db/post_migrate/20230110172751_add_partial_index_on_group_path_id.rb b/db/post_migrate/20230110172751_add_partial_index_on_group_path_id.rb
new file mode 100644
index 00000000000..c04b71835a2
--- /dev/null
+++ b/db/post_migrate/20230110172751_add_partial_index_on_group_path_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddPartialIndexOnGroupPathId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = :index_groups_on_path_and_id
+
+ def up
+ add_concurrent_index :namespaces, [:path, :id], where: "type = 'Group'", name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :namespaces, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230111125148_add_user_id_and_source_id_and_source_type_and_member_role_id_index_to_members.rb b/db/post_migrate/20230111125148_add_user_id_and_source_id_and_source_type_and_member_role_id_index_to_members.rb
new file mode 100644
index 00000000000..82e2ea8bf29
--- /dev/null
+++ b/db/post_migrate/20230111125148_add_user_id_and_source_id_and_source_type_and_member_role_id_index_to_members.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddUserIdAndSourceIdAndSourceTypeAndMemberRoleIdIndexToMembers < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'idx_members_on_user_and_source_and_source_type_and_member_role'
+
+ def up
+ add_concurrent_index :members, [:user_id, :source_id, :source_type, :member_role_id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :members, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230111125150_drop_user_id_and_source_id_and_source_type_index_from_members.rb b/db/post_migrate/20230111125150_drop_user_id_and_source_id_and_source_type_index_from_members.rb
new file mode 100644
index 00000000000..c1c56a4073c
--- /dev/null
+++ b/db/post_migrate/20230111125150_drop_user_id_and_source_id_and_source_type_index_from_members.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class DropUserIdAndSourceIdAndSourceTypeIndexFromMembers < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_members_on_user_id_source_id_source_type'
+
+ def up
+ remove_concurrent_index_by_name :members, name: INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :members, [:user_id, :source_id, :source_type], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230112085143_add_index_environments_on_project_id_and_id.rb b/db/post_migrate/20230112085143_add_index_environments_on_project_id_and_id.rb
new file mode 100644
index 00000000000..bfb85557714
--- /dev/null
+++ b/db/post_migrate/20230112085143_add_index_environments_on_project_id_and_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexEnvironmentsOnProjectIdAndId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_environments_on_project_id_and_id'
+
+ def up
+ add_concurrent_index :environments, %i[project_id id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :environments, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230113003255_remove_atlassian_refresh_token_constraint.rb b/db/post_migrate/20230113003255_remove_atlassian_refresh_token_constraint.rb
new file mode 100644
index 00000000000..81c3f10c0f6
--- /dev/null
+++ b/db/post_migrate/20230113003255_remove_atlassian_refresh_token_constraint.rb
@@ -0,0 +1,20 @@
+# 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 RemoveAtlassianRefreshTokenConstraint < Gitlab::Database::Migration[2.1]
+ CONSTRAINT_NAME = 'atlassian_identities_refresh_token_length_constraint'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_check_constraint(:atlassian_identities, CONSTRAINT_NAME)
+ add_check_constraint :atlassian_identities, 'octet_length(encrypted_refresh_token) <= 5000', CONSTRAINT_NAME
+ end
+
+ def down
+ remove_check_constraint(:atlassian_identities, CONSTRAINT_NAME)
+ add_check_constraint :atlassian_identities, 'octet_length(encrypted_refresh_token) <= 512', CONSTRAINT_NAME
+ end
+end
diff --git a/db/post_migrate/20230116083826_drop_index_on_ci_build_token_encrypted.rb b/db/post_migrate/20230116083826_drop_index_on_ci_build_token_encrypted.rb
new file mode 100644
index 00000000000..429388b1742
--- /dev/null
+++ b/db/post_migrate/20230116083826_drop_index_on_ci_build_token_encrypted.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropIndexOnCiBuildTokenEncrypted < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_builds
+ INDEX_NAME = :index_ci_builds_on_token_encrypted_partition_id_unique
+ COLUMNS = %i[token_encrypted partition_id].freeze
+
+ def up
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+
+ def down
+ add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, where: 'token_encrypted IS NOT NULL', name: INDEX_NAME)
+ end
+end
diff --git a/db/post_migrate/20230116090630_add_index_for_group_activity_events.rb b/db/post_migrate/20230116090630_add_index_for_group_activity_events.rb
new file mode 100644
index 00000000000..a775a471f98
--- /dev/null
+++ b/db/post_migrate/20230116090630_add_index_for_group_activity_events.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexForGroupActivityEvents < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_events_for_group_activity'
+
+ def up
+ add_concurrent_index :events, %i[group_id target_type action id], name: INDEX_NAME, where: 'group_id IS NOT NULL'
+ end
+
+ def down
+ remove_concurrent_index_by_name :events, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230116090852_add_index_for_project_activity_events.rb b/db/post_migrate/20230116090852_add_index_for_project_activity_events.rb
new file mode 100644
index 00000000000..f0d757ad885
--- /dev/null
+++ b/db/post_migrate/20230116090852_add_index_for_project_activity_events.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexForProjectActivityEvents < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_events_for_project_activity'
+
+ def up
+ add_concurrent_index :events, %i[project_id target_type action id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :events, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230116090920_add_index_to_events_on_group_id_and_id.rb b/db/post_migrate/20230116090920_add_index_to_events_on_group_id_and_id.rb
new file mode 100644
index 00000000000..4c2a9af7df9
--- /dev/null
+++ b/db/post_migrate/20230116090920_add_index_to_events_on_group_id_and_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexToEventsOnGroupIdAndId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_events_on_group_id_and_id'
+
+ def up
+ add_concurrent_index :events, %i[group_id id], name: INDEX_NAME, where: 'group_id IS NOT NULL'
+ end
+
+ def down
+ remove_concurrent_index_by_name :events, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230116091626_add_index_for_events_followed_users.rb b/db/post_migrate/20230116091626_add_index_for_events_followed_users.rb
new file mode 100644
index 00000000000..24358814521
--- /dev/null
+++ b/db/post_migrate/20230116091626_add_index_for_events_followed_users.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexForEventsFollowedUsers < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_events_for_followed_users'
+
+ def up
+ add_concurrent_index :events, %I[author_id target_type action id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :events, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230116111252_finalize_todo_sanitization.rb b/db/post_migrate/20230116111252_finalize_todo_sanitization.rb
new file mode 100644
index 00000000000..b3da479aa57
--- /dev/null
+++ b/db/post_migrate/20230116111252_finalize_todo_sanitization.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class FinalizeTodoSanitization < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'SanitizeConfidentialTodos'
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ ensure_batched_background_migration_is_finished(
+ job_class_name: MIGRATION,
+ table_name: :notes,
+ column_name: :id,
+ job_arguments: [],
+ finalize: true
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20230117113719_add_tmp_index_to_ci_sources_pipelines_on_partition_id.rb b/db/post_migrate/20230117113719_add_tmp_index_to_ci_sources_pipelines_on_partition_id.rb
new file mode 100644
index 00000000000..28c722893bc
--- /dev/null
+++ b/db/post_migrate/20230117113719_add_tmp_index_to_ci_sources_pipelines_on_partition_id.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class AddTmpIndexToCiSourcesPipelinesOnPartitionId < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ INDEX_NAME = :tmp_index_ci_sources_pipelines_on_partition_id_and_id
+ SOURCE_INDEX_NAME = :tmp_index_ci_sources_pipelines_on_source_partition_id_and_id
+ TABLE_NAME = :ci_sources_pipelines
+
+ def up
+ return unless Gitlab.com?
+
+ add_concurrent_index TABLE_NAME,
+ [:partition_id, :id],
+ name: INDEX_NAME, where: 'partition_id = 101'
+
+ add_concurrent_index TABLE_NAME,
+ [:source_partition_id, :id],
+ name: SOURCE_INDEX_NAME,
+ where: 'source_partition_id = 101'
+ end
+
+ def down
+ return unless Gitlab.com?
+
+ remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
+ remove_concurrent_index_by_name TABLE_NAME, SOURCE_INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230117145628_add_token_encrypted_and_partition_id_index_to_ci_build.rb b/db/post_migrate/20230117145628_add_token_encrypted_and_partition_id_index_to_ci_build.rb
new file mode 100644
index 00000000000..ffcf56dd2ca
--- /dev/null
+++ b/db/post_migrate/20230117145628_add_token_encrypted_and_partition_id_index_to_ci_build.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddTokenEncryptedAndPartitionIdIndexToCiBuild < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLE_NAME = :ci_builds
+ INDEX_NAME = :unique_ci_builds_token_encrypted_and_partition_id
+ COLUMNS = %i[token_encrypted partition_id].freeze
+
+ def up
+ add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, where: 'token_encrypted IS NOT NULL', name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+end