summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 09:16:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 09:16:11 +0000
commitedaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch)
tree11f143effbfeba52329fb7afbd05e6e2a3790241 /db/post_migrate
parentd8a5691316400a0f7ec4f83832698f1988eb27c1 (diff)
downloadgitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20201211090634_schedule_populate_finding_uuid_for_vulnerability_feedback.rb25
-rw-r--r--db/post_migrate/20201216185336_add_devops_adoption_snapshot_not_null.rb31
-rw-r--r--db/post_migrate/20201217112249_change_pages_deployment_size_to_bigint_cleanup.rb17
-rw-r--r--db/post_migrate/20201223012231_reindex_ci_pipelines_on_schedule_id_and_id.rb21
-rw-r--r--db/post_migrate/20201231133921_schedule_set_default_iteration_cadences.rb26
-rw-r--r--db/post_migrate/20210105030125_cleanup_projects_with_bad_has_external_wiki_data.rb88
-rw-r--r--db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb19
-rw-r--r--db/post_migrate/20210105103649_delete_column_group_id_on_compliance_framework.rb9
-rw-r--r--db/post_migrate/20210107194543_remove_alerts_service_records.rb19
-rw-r--r--db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb20
-rw-r--r--db/post_migrate/20210111075206_schedule_uuid_population_for_security_findings2.rb34
-rw-r--r--db/post_migrate/20210112143418_remove_duplicate_services2.rb29
-rw-r--r--db/post_migrate/20210115215854_cancel_artifact_expiry_backfill.rb22
-rw-r--r--db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb48
-rw-r--r--db/post_migrate/20210119122354_alter_vsa_issue_first_mentioned_in_commit_value.rb34
-rw-r--r--db/post_migrate/20210203143131_migrate_existing_devops_segments_to_groups.rb15
-rw-r--r--db/post_migrate/20210205104425_add_new_post_eoa_plans.rb14
-rw-r--r--db/post_migrate/20210205144537_remove_namespace_onboarding_actions_table.rb23
-rw-r--r--db/post_migrate/20210205174154_remove_bad_dependency_proxy_manifests.rb15
-rw-r--r--db/post_migrate/20210205213933_drop_alerts_service_data.rb26
-rw-r--r--db/post_migrate/20210205214003_remove_alerts_service_records_again.rb19
-rw-r--r--db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb34
-rw-r--r--db/post_migrate/20210210221006_cleanup_projects_with_bad_has_external_issue_tracker_data.rb84
-rw-r--r--db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb28
-rw-r--r--db/post_migrate/20210215144909_migrate_usage_trends_sidekiq_queue.rb19
-rw-r--r--db/post_migrate/20210217100728_move_create_release_evidence_queue_out_of_cronjob_namespace.rb16
-rw-r--r--db/post_migrate/20210218105431_remove_deprecated_ci_builds_columns.rb36
-rw-r--r--db/post_migrate/20210218110552_remove_deprecated_ci_runner_column.rb22
-rw-r--r--db/post_migrate/20210219102900_reschedule_set_default_iteration_cadences.rb30
-rw-r--r--db/post_migrate/20210222185538_remove_backup_labels_foreign_keys.rb21
-rw-r--r--db/post_migrate/20210222192144_remove_backup_labels_table.rb36
-rw-r--r--db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb44
-rw-r--r--db/post_migrate/20210226120851_move_container_registry_enabled_to_project_features.rb28
-rw-r--r--db/post_migrate/20210226141517_dedup_issue_metrics.rb71
-rw-r--r--db/post_migrate/20210301200959_clean_up_asset_proxy_allowlist_rename_on_application_settings.rb21
-rw-r--r--db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb29
-rw-r--r--db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb22
-rw-r--r--db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb10
-rw-r--r--db/post_migrate/20211123161906_cleanup_after_drop_invalid_security_findings.rb26
-rw-r--r--db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb28
-rw-r--r--db/post_migrate/20211206162601_cleanup_after_add_primary_email_to_emails_if_user_confirmed.rb59
-rw-r--r--db/post_migrate/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb15
-rw-r--r--db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb16
-rw-r--r--db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb28
-rw-r--r--db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb57
-rw-r--r--db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb71
-rw-r--r--db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb23
-rw-r--r--db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb23
-rw-r--r--db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb16
-rw-r--r--db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb25
-rw-r--r--db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb15
-rw-r--r--db/post_migrate/20211210140629_encrypt_static_object_token.rb22
-rw-r--r--db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb26
-rw-r--r--db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb41
-rw-r--r--db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb14
-rw-r--r--db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb20
-rw-r--r--db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb28
-rw-r--r--db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb15
-rw-r--r--db/post_migrate/20211220123956_update_invalid_member_states.rb21
-rw-r--r--db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb15
-rw-r--r--db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb17
-rw-r--r--db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb15
-rw-r--r--db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb17
-rw-r--r--db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb17
-rw-r--r--db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb17
-rw-r--r--db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb17
-rw-r--r--db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb17
-rw-r--r--db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb17
-rw-r--r--db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb23
-rw-r--r--db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb18
-rw-r--r--db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb15
-rw-r--r--db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb14
-rw-r--r--db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb15
-rw-r--r--db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb17
-rw-r--r--db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb23
-rw-r--r--db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb16
-rw-r--r--db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb15
-rw-r--r--db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb15
-rw-r--r--db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb15
-rw-r--r--db/post_migrate/20220114105525_add_index_on_projects_path.rb17
-rw-r--r--db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb16
-rw-r--r--db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb17
88 files changed, 1079 insertions, 1099 deletions
diff --git a/db/post_migrate/20201211090634_schedule_populate_finding_uuid_for_vulnerability_feedback.rb b/db/post_migrate/20201211090634_schedule_populate_finding_uuid_for_vulnerability_feedback.rb
deleted file mode 100644
index 3ecb48dab0f..00000000000
--- a/db/post_migrate/20201211090634_schedule_populate_finding_uuid_for_vulnerability_feedback.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-class SchedulePopulateFindingUuidForVulnerabilityFeedback < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION_CLASS = 'PopulateFindingUuidForVulnerabilityFeedback'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 1000
-
- disable_ddl_transaction!
-
- def up
- queue_background_migration_jobs_by_range_at_intervals(
- Gitlab::BackgroundMigration::PopulateFindingUuidForVulnerabilityFeedback::VulnerabilityFeedback,
- MIGRATION_CLASS,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE
- )
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20201216185336_add_devops_adoption_snapshot_not_null.rb b/db/post_migrate/20201216185336_add_devops_adoption_snapshot_not_null.rb
deleted file mode 100644
index 1bb3c57f3cd..00000000000
--- a/db/post_migrate/20201216185336_add_devops_adoption_snapshot_not_null.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-class AddDevopsAdoptionSnapshotNotNull < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- execute(
- <<~SQL
- LOCK TABLE analytics_devops_adoption_snapshots IN ACCESS EXCLUSIVE MODE;
-
- UPDATE analytics_devops_adoption_snapshots SET end_time = date_trunc('month', recorded_at) - interval '1 millisecond';
-
- ALTER TABLE analytics_devops_adoption_snapshots ALTER COLUMN end_time SET NOT NULL;
- SQL
- )
- end
- end
-
- def down
- with_lock_retries do
- execute(<<~SQL)
- ALTER TABLE analytics_devops_adoption_snapshots ALTER COLUMN end_time DROP NOT NULL;
- SQL
- end
- end
-end
diff --git a/db/post_migrate/20201217112249_change_pages_deployment_size_to_bigint_cleanup.rb b/db/post_migrate/20201217112249_change_pages_deployment_size_to_bigint_cleanup.rb
deleted file mode 100644
index 4ed29ba61f9..00000000000
--- a/db/post_migrate/20201217112249_change_pages_deployment_size_to_bigint_cleanup.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class ChangePagesDeploymentSizeToBigintCleanup < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- cleanup_concurrent_column_type_change :pages_deployments, :size
- end
-
- def down
- undo_cleanup_concurrent_column_type_change :pages_deployments, :size, :integer, limit: 4
- end
-end
diff --git a/db/post_migrate/20201223012231_reindex_ci_pipelines_on_schedule_id_and_id.rb b/db/post_migrate/20201223012231_reindex_ci_pipelines_on_schedule_id_and_id.rb
deleted file mode 100644
index 9ed1aea911a..00000000000
--- a/db/post_migrate/20201223012231_reindex_ci_pipelines_on_schedule_id_and_id.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-class ReindexCiPipelinesOnScheduleIdAndId < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- OLD_INDEX_NAME = 'index_ci_pipelines_on_pipeline_schedule_id'
- NEW_INDEX_NAME = 'index_ci_pipelines_on_pipeline_schedule_id_and_id'
-
- disable_ddl_transaction!
-
- def up
- add_concurrent_index :ci_pipelines, [:pipeline_schedule_id, :id], name: NEW_INDEX_NAME
- remove_concurrent_index_by_name :ci_pipelines, OLD_INDEX_NAME
- end
-
- def down
- add_concurrent_index :ci_pipelines, :pipeline_schedule_id, name: OLD_INDEX_NAME
- remove_concurrent_index_by_name :ci_pipelines, NEW_INDEX_NAME
- end
-end
diff --git a/db/post_migrate/20201231133921_schedule_set_default_iteration_cadences.rb b/db/post_migrate/20201231133921_schedule_set_default_iteration_cadences.rb
deleted file mode 100644
index 32645430e19..00000000000
--- a/db/post_migrate/20201231133921_schedule_set_default_iteration_cadences.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleSetDefaultIterationCadences < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- BATCH_SIZE = 1_000
- DELAY_INTERVAL = 2.minutes.to_i
- MIGRATION_CLASS = 'SetDefaultIterationCadences'
-
- class Iteration < ActiveRecord::Base # rubocop:disable Style/Documentation
- include EachBatch
-
- self.table_name = 'sprints'
- end
-
- disable_ddl_transaction!
-
- def up
- # Do nothing, rescheduling migration: 20210219102900_reschedule_set_default_iteration_cadences.rb
- end
-
- def down
- # Not needed
- end
-end
diff --git a/db/post_migrate/20210105030125_cleanup_projects_with_bad_has_external_wiki_data.rb b/db/post_migrate/20210105030125_cleanup_projects_with_bad_has_external_wiki_data.rb
deleted file mode 100644
index bc90a5f48ea..00000000000
--- a/db/post_migrate/20210105030125_cleanup_projects_with_bad_has_external_wiki_data.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupProjectsWithBadHasExternalWikiData < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- TMP_INDEX_NAME = 'tmp_index_projects_on_id_where_has_external_wiki_is_true'
- BATCH_SIZE = 100
-
- disable_ddl_transaction!
-
- class Service < ActiveRecord::Base
- include EachBatch
- belongs_to :project
-
- self.table_name = 'services'
- self.inheritance_column = :_type_disabled
- end
-
- class Project < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'projects'
- end
-
- def up
- update_projects_with_active_external_wikis
- update_projects_without_active_external_wikis
- end
-
- def down
- # no-op : can't go back to incorrect data
- end
-
- private
-
- def update_projects_with_active_external_wikis
- # 11 projects are scoped in this query on GitLab.com.
- scope = Service.where(active: true, type: 'ExternalWikiService').where.not(project_id: nil)
-
- scope.each_batch(of: BATCH_SIZE) do |relation|
- scope_with_projects = relation
- .joins(:project)
- .select('project_id')
- .merge(Project.where(has_external_wiki: false).where(pending_delete: false).where(archived: false))
-
- execute(<<~SQL)
- WITH project_ids_to_update (id) AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} (
- #{scope_with_projects.to_sql}
- )
- UPDATE projects SET has_external_wiki = true WHERE id IN (SELECT id FROM project_ids_to_update)
- SQL
- end
- end
-
- def update_projects_without_active_external_wikis
- # Add a temporary index to speed up the scoping of projects.
- index_where = <<~SQL
- (
- "projects"."has_external_wiki" = TRUE
- )
- AND "projects"."pending_delete" = FALSE
- AND "projects"."archived" = FALSE
- SQL
-
- add_concurrent_index(:projects, :id, where: index_where, name: TMP_INDEX_NAME)
-
- services_sub_query = Service
- .select('1')
- .where('services.project_id = projects.id')
- .where(type: 'ExternalWikiService')
- .where(active: true)
-
- # 322 projects are scoped in this query on GitLab.com.
- Project.where(index_where).each_batch(of: BATCH_SIZE) do |relation|
- relation_with_exists_query = relation.where('NOT EXISTS (?)', services_sub_query)
- execute(<<~SQL)
- WITH project_ids_to_update (id) AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} (
- #{relation_with_exists_query.select(:id).to_sql}
- )
- UPDATE projects SET has_external_wiki = false WHERE id IN (SELECT id FROM project_ids_to_update)
- SQL
- end
-
- # Drop the temporary index.
- remove_concurrent_index_by_name(:projects, TMP_INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb b/db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb
deleted file mode 100644
index 87f391e240d..00000000000
--- a/db/post_migrate/20210105052229_clean_up_asset_proxy_whitelist_rename_on_application_settings.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class CleanUpAssetProxyWhitelistRenameOnApplicationSettings < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers::V2
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- # This migration has been made a no-op in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56352
- # because to revert the rename in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55419 we need
- # to cleanup the triggers on the `asset_proxy_allowlist` column. As such, this migration would do nothing.
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210105103649_delete_column_group_id_on_compliance_framework.rb b/db/post_migrate/20210105103649_delete_column_group_id_on_compliance_framework.rb
deleted file mode 100644
index b13d2fe2d0a..00000000000
--- a/db/post_migrate/20210105103649_delete_column_group_id_on_compliance_framework.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-class DeleteColumnGroupIdOnComplianceFramework < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def change
- remove_column :compliance_management_frameworks, :group_id, :bigint
- end
-end
diff --git a/db/post_migrate/20210107194543_remove_alerts_service_records.rb b/db/post_migrate/20210107194543_remove_alerts_service_records.rb
deleted file mode 100644
index 51a2f96ac7f..00000000000
--- a/db/post_migrate/20210107194543_remove_alerts_service_records.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveAlertsServiceRecords < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- class Service < ActiveRecord::Base
- self.table_name = 'services'
- end
-
- def up
- Service.delete_by(type: 'AlertsService')
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb b/db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb
deleted file mode 100644
index 43cfb27b94c..00000000000
--- a/db/post_migrate/20210111075105_schedule_uuid_population_for_security_findings.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleUuidPopulationForSecurityFindings < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION_CLASS = 'PopulateUuidsForSecurityFindings'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 25
-
- disable_ddl_transaction!
-
- def up
- # no-op, replaced by 20210111075206_schedule_uuid_population_for_security_findings2.rb
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210111075206_schedule_uuid_population_for_security_findings2.rb b/db/post_migrate/20210111075206_schedule_uuid_population_for_security_findings2.rb
deleted file mode 100644
index 00569581ca4..00000000000
--- a/db/post_migrate/20210111075206_schedule_uuid_population_for_security_findings2.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-# This replaces the previous post-deployment migration 20210111075105_schedule_uuid_population_for_security_findings.rb,
-# we have to run this again due to a bug in how we were receiving the arguments in the background migration.
-class ScheduleUuidPopulationForSecurityFindings2 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION_CLASS = 'PopulateUuidsForSecurityFindings'
- DELAY_INTERVAL = 2.minutes
- BATCH_SIZE = 25
-
- disable_ddl_transaction!
-
- def up
- ::Gitlab::BackgroundMigration.steal(MIGRATION_CLASS) do |job|
- job.delete
-
- false
- end
-
- Gitlab::BackgroundMigration::PopulateUuidsForSecurityFindings.security_findings.each_batch(column: :scan_id, of: BATCH_SIZE) do |batch, index|
- migrate_in(
- DELAY_INTERVAL * index,
- MIGRATION_CLASS,
- batch.pluck(:scan_id)
- )
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210112143418_remove_duplicate_services2.rb b/db/post_migrate/20210112143418_remove_duplicate_services2.rb
deleted file mode 100644
index 83d92a78473..00000000000
--- a/db/post_migrate/20210112143418_remove_duplicate_services2.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-# This replaces the previous post-deployment migration 20201207165956_remove_duplicate_services_spec.rb,
-# we have to run this again due to a bug in how we were receiving the arguments in the background migration.
-class RemoveDuplicateServices2 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- INTERVAL = 2.minutes
- BATCH_SIZE = 5_000
- MIGRATION = 'RemoveDuplicateServices'
-
- disable_ddl_transaction!
-
- def up
- project_ids_with_duplicates = Gitlab::BackgroundMigration::RemoveDuplicateServices::Service.project_ids_with_duplicates
-
- project_ids_with_duplicates.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index|
- migrate_in(
- INTERVAL * index,
- MIGRATION,
- batch.pluck(:project_id)
- )
- end
- end
-
- def down
- end
-end
diff --git a/db/post_migrate/20210115215854_cancel_artifact_expiry_backfill.rb b/db/post_migrate/20210115215854_cancel_artifact_expiry_backfill.rb
deleted file mode 100644
index 8a03a90a1c5..00000000000
--- a/db/post_migrate/20210115215854_cancel_artifact_expiry_backfill.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class CancelArtifactExpiryBackfill < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION = 'BackfillArtifactExpiryDate'
-
- disable_ddl_transaction!
-
- def up
- Gitlab::BackgroundMigration.steal(MIGRATION) do |job|
- job.delete
-
- false
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb b/db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb
deleted file mode 100644
index 4f49e8b75af..00000000000
--- a/db/post_migrate/20210115220610_schedule_artifact_expiry_backfill.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# frozen_string_literal: true
-
-class ScheduleArtifactExpiryBackfill < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION = 'BackfillArtifactExpiryDate'
- SWITCH_DATE = Date.new(2020, 06, 22).freeze
- INDEX_NAME = 'expired_artifacts_temp_index'
- OLD_INDEX_CONDITION = "expire_at IS NULL AND created_at < '#{SWITCH_DATE}'"
- INDEX_CONDITION = "expire_at IS NULL AND date(created_at AT TIME ZONE 'UTC') < '2020-06-22'::date"
-
- disable_ddl_transaction!
-
- class JobArtifact < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'ci_job_artifacts'
-
- scope :without_expiry_date, -> { where(expire_at: nil) }
- scope :before_switch, -> { where("date(created_at AT TIME ZONE 'UTC') < ?::date", SWITCH_DATE) }
- end
-
- def up
- # Create temporary index for expired artifacts
- # Needs to be removed in a later migration
- remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME
- add_concurrent_index(:ci_job_artifacts, %i(id created_at), where: INDEX_CONDITION, name: INDEX_NAME)
-
- queue_background_migration_jobs_by_range_at_intervals(
- JobArtifact.without_expiry_date.before_switch,
- MIGRATION,
- 2.minutes,
- batch_size: 200_000
- )
- end
-
- def down
- remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME
- add_concurrent_index(:ci_job_artifacts, %i(id created_at), where: OLD_INDEX_CONDITION, name: INDEX_NAME)
-
- Gitlab::BackgroundMigration.steal(MIGRATION) do |job|
- job.delete
-
- false
- end
- end
-end
diff --git a/db/post_migrate/20210119122354_alter_vsa_issue_first_mentioned_in_commit_value.rb b/db/post_migrate/20210119122354_alter_vsa_issue_first_mentioned_in_commit_value.rb
deleted file mode 100644
index 132d72e180b..00000000000
--- a/db/post_migrate/20210119122354_alter_vsa_issue_first_mentioned_in_commit_value.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-class AlterVsaIssueFirstMentionedInCommitValue < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- ISSUE_FIRST_MENTIONED_IN_COMMIT_FOSS = 2
- ISSUE_FIRST_MENTIONED_IN_COMMIT_EE = 6
-
- class GroupStage < ActiveRecord::Base
- self.table_name = 'analytics_cycle_analytics_group_stages'
-
- include EachBatch
- end
-
- def up
- GroupStage.each_batch(of: 100) do |relation|
- relation
- .where(start_event_identifier: ISSUE_FIRST_MENTIONED_IN_COMMIT_EE)
- .update_all(start_event_identifier: ISSUE_FIRST_MENTIONED_IN_COMMIT_FOSS)
-
- relation
- .where(end_event_identifier: ISSUE_FIRST_MENTIONED_IN_COMMIT_EE)
- .update_all(end_event_identifier: ISSUE_FIRST_MENTIONED_IN_COMMIT_FOSS)
- end
- end
-
- def down
- # rollback is not needed, the identifier "6" is the same as identifier "2" on the application level
- end
-end
diff --git a/db/post_migrate/20210203143131_migrate_existing_devops_segments_to_groups.rb b/db/post_migrate/20210203143131_migrate_existing_devops_segments_to_groups.rb
deleted file mode 100644
index 5267e0fd658..00000000000
--- a/db/post_migrate/20210203143131_migrate_existing_devops_segments_to_groups.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-# Data migration to migrate multi-selection segments into separate segments.
-# Both tables involved are pretty-low traffic and the number
-# of records in DB cannot exceed 400
-class MigrateExistingDevopsSegmentsToGroups < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def up
- Gitlab::BackgroundMigration::MigrateDevopsSegmentsToGroups.new.perform
- end
-
- def down
- end
-end
diff --git a/db/post_migrate/20210205104425_add_new_post_eoa_plans.rb b/db/post_migrate/20210205104425_add_new_post_eoa_plans.rb
deleted file mode 100644
index d1a5afbd314..00000000000
--- a/db/post_migrate/20210205104425_add_new_post_eoa_plans.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-class AddNewPostEoaPlans < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def up
- execute "INSERT INTO plans (name, title, created_at, updated_at) VALUES ('premium', 'Premium (Formerly Silver)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
- execute "INSERT INTO plans (name, title, created_at, updated_at) VALUES ('ultimate', 'Ultimate (Formerly Gold)', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
- end
-
- def down
- execute "DELETE FROM plans WHERE name IN ('premium', 'ultimate')"
- end
-end
diff --git a/db/post_migrate/20210205144537_remove_namespace_onboarding_actions_table.rb b/db/post_migrate/20210205144537_remove_namespace_onboarding_actions_table.rb
deleted file mode 100644
index 210b1d7822c..00000000000
--- a/db/post_migrate/20210205144537_remove_namespace_onboarding_actions_table.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveNamespaceOnboardingActionsTable < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- def up
- with_lock_retries do
- drop_table :namespace_onboarding_actions
- end
- end
-
- def down
- with_lock_retries do
- create_table :namespace_onboarding_actions do |t|
- t.references :namespace, index: true, null: false
- t.datetime_with_timezone :created_at, null: false
- t.integer :action, limit: 2, null: false
- end
- end
- end
-end
diff --git a/db/post_migrate/20210205174154_remove_bad_dependency_proxy_manifests.rb b/db/post_migrate/20210205174154_remove_bad_dependency_proxy_manifests.rb
deleted file mode 100644
index eb302fb7009..00000000000
--- a/db/post_migrate/20210205174154_remove_bad_dependency_proxy_manifests.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveBadDependencyProxyManifests < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def up
- # We run destroy on each record because we need the callback to remove
- # the underlying files
- DependencyProxy::Manifest.where.not(content_type: nil).destroy_all # rubocop:disable Cop/DestroyAll
- end
-
- def down
- # no op
- end
-end
diff --git a/db/post_migrate/20210205213933_drop_alerts_service_data.rb b/db/post_migrate/20210205213933_drop_alerts_service_data.rb
deleted file mode 100644
index 6ad6c90290e..00000000000
--- a/db/post_migrate/20210205213933_drop_alerts_service_data.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-class DropAlertsServiceData < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- def up
- with_lock_retries do
- drop_table :alerts_service_data
- end
- end
-
- # rubocop:disable Migration/PreventStrings
- def down
- with_lock_retries do
- create_table :alerts_service_data do |t|
- t.bigint :service_id, null: false
- t.timestamps_with_timezone
- t.string :encrypted_token, limit: 255
- t.string :encrypted_token_iv, limit: 255
- end
- end
- end
- # rubocop:enable Migration/PreventStrings
-end
diff --git a/db/post_migrate/20210205214003_remove_alerts_service_records_again.rb b/db/post_migrate/20210205214003_remove_alerts_service_records_again.rb
deleted file mode 100644
index aabc6fc00cd..00000000000
--- a/db/post_migrate/20210205214003_remove_alerts_service_records_again.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveAlertsServiceRecordsAgain < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- class Service < ActiveRecord::Base
- self.table_name = 'services'
- end
-
- def up
- Service.delete_by(type: 'AlertsService')
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb b/db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb
deleted file mode 100644
index efd0eeb9d47..00000000000
--- a/db/post_migrate/20210210093901_backfill_updated_at_after_repository_storage_move.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-class BackfillUpdatedAtAfterRepositoryStorageMove < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- BATCH_SIZE = 10_000
- INTERVAL = 2.minutes
- MIGRATION_CLASS = 'BackfillProjectUpdatedAtAfterRepositoryStorageMove'
-
- disable_ddl_transaction!
-
- class RepositoryStorageMove < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'project_repository_storage_moves'
- end
-
- def up
- RepositoryStorageMove.reset_column_information
-
- RepositoryStorageMove.select(:project_id).distinct.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index|
- migrate_in(
- INTERVAL * index,
- MIGRATION_CLASS,
- batch.pluck(:project_id)
- )
- end
- end
-
- def down
- # No-op
- end
-end
diff --git a/db/post_migrate/20210210221006_cleanup_projects_with_bad_has_external_issue_tracker_data.rb b/db/post_migrate/20210210221006_cleanup_projects_with_bad_has_external_issue_tracker_data.rb
deleted file mode 100644
index 7b17faeb4b4..00000000000
--- a/db/post_migrate/20210210221006_cleanup_projects_with_bad_has_external_issue_tracker_data.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupProjectsWithBadHasExternalIssueTrackerData < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- TMP_INDEX_NAME = 'tmp_idx_projects_on_id_where_has_external_issue_tracker_is_true'
- BATCH_SIZE = 100
-
- disable_ddl_transaction!
-
- class Service < ActiveRecord::Base
- include EachBatch
- belongs_to :project
-
- self.table_name = 'services'
- self.inheritance_column = :_type_disabled
- end
-
- class Project < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'projects'
- end
-
- def up
- update_projects_with_active_external_issue_trackers
- update_projects_without_active_external_issue_trackers
- end
-
- def down
- # no-op : can't go back to incorrect data
- end
-
- private
-
- def update_projects_with_active_external_issue_trackers
- scope = Service.where(active: true, category: 'issue_tracker').where.not(project_id: nil).distinct(:project_id)
-
- scope.each_batch(of: BATCH_SIZE) do |relation|
- scope_with_projects = relation
- .joins(:project)
- .select('project_id')
- .merge(Project.where(has_external_issue_tracker: false).where(pending_delete: false))
-
- execute(<<~SQL)
- WITH project_ids_to_update (id) AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} (
- #{scope_with_projects.to_sql}
- )
- UPDATE projects SET has_external_issue_tracker = true WHERE id IN (SELECT id FROM project_ids_to_update)
- SQL
- end
- end
-
- def update_projects_without_active_external_issue_trackers
- # Add a temporary index to speed up the scoping of projects.
- index_where = <<~SQL
- "projects"."has_external_issue_tracker" = TRUE
- AND "projects"."pending_delete" = FALSE
- SQL
-
- add_concurrent_index(:projects, :id, where: index_where, name: TMP_INDEX_NAME)
-
- services_sub_query = Service
- .select('1')
- .where('services.project_id = projects.id')
- .where(category: 'issue_tracker')
- .where(active: true)
-
- # 322 projects are scoped in this query on GitLab.com.
- Project.where(index_where).each_batch(of: BATCH_SIZE) do |relation|
- relation_with_exists_query = relation.where('NOT EXISTS (?)', services_sub_query)
- execute(<<~SQL)
- WITH project_ids_to_update (id) AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} (
- #{relation_with_exists_query.select(:id).to_sql}
- )
- UPDATE projects SET has_external_issue_tracker = false WHERE id IN (SELECT id FROM project_ids_to_update)
- SQL
- end
-
- # Drop the temporary index.
- remove_concurrent_index_by_name(:projects, TMP_INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb b/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb
deleted file mode 100644
index 12e156d3b8a..00000000000
--- a/db/post_migrate/20210215095328_migrate_delayed_project_removal_from_namespaces_to_namespace_settings.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class MigrateDelayedProjectRemovalFromNamespacesToNamespaceSettings < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- class Namespace < ActiveRecord::Base
- self.table_name = 'namespaces'
-
- include ::EachBatch
- end
-
- def up
- Namespace.select(:id).where(delayed_project_removal: true).each_batch do |batch|
- values = batch.map { |record| "(#{record.id}, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)" }
-
- execute <<-EOF.strip_heredoc
- INSERT INTO namespace_settings (namespace_id, delayed_project_removal, created_at, updated_at)
- VALUES #{values.join(', ')}
- ON CONFLICT (namespace_id) DO UPDATE
- SET delayed_project_removal = TRUE
- EOF
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210215144909_migrate_usage_trends_sidekiq_queue.rb b/db/post_migrate/20210215144909_migrate_usage_trends_sidekiq_queue.rb
deleted file mode 100644
index 3e6eabfba97..00000000000
--- a/db/post_migrate/20210215144909_migrate_usage_trends_sidekiq_queue.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class MigrateUsageTrendsSidekiqQueue < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- sidekiq_queue_migrate 'cronjob:analytics_instance_statistics_count_job_trigger', to: 'cronjob:analytics_usage_trends_count_job_trigger'
- sidekiq_queue_migrate 'analytics_instance_statistics_counter_job', to: 'analytics_usage_trends_counter_job'
- end
-
- def down
- sidekiq_queue_migrate 'cronjob:analytics_usage_trends_count_job_trigger', to: 'cronjob:analytics_instance_statistics_count_job_trigger'
- sidekiq_queue_migrate 'analytics_usage_trends_counter_job', to: 'analytics_instance_statistics_counter_job'
- end
-end
diff --git a/db/post_migrate/20210217100728_move_create_release_evidence_queue_out_of_cronjob_namespace.rb b/db/post_migrate/20210217100728_move_create_release_evidence_queue_out_of_cronjob_namespace.rb
deleted file mode 100644
index 22bead87dc1..00000000000
--- a/db/post_migrate/20210217100728_move_create_release_evidence_queue_out_of_cronjob_namespace.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-class MoveCreateReleaseEvidenceQueueOutOfCronjobNamespace < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- # Set this constant to true if this migration requires downtime.
- DOWNTIME = false
-
- def up
- sidekiq_queue_migrate 'cronjob:releases_create_evidence', to: 'releases_create_evidence'
- end
-
- def down
- sidekiq_queue_migrate 'releases_create_evidence', to: 'cronjob:releases_create_evidence'
- end
-end
diff --git a/db/post_migrate/20210218105431_remove_deprecated_ci_builds_columns.rb b/db/post_migrate/20210218105431_remove_deprecated_ci_builds_columns.rb
deleted file mode 100644
index 6fa7a15a90d..00000000000
--- a/db/post_migrate/20210218105431_remove_deprecated_ci_builds_columns.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveDeprecatedCiBuildsColumns < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- # Set this constant to true if this migration requires downtime.
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_column :ci_builds, :artifacts_file
- remove_column :ci_builds, :artifacts_file_store
- remove_column :ci_builds, :artifacts_metadata
- remove_column :ci_builds, :artifacts_metadata_store
- remove_column :ci_builds, :artifacts_size
- remove_column :ci_builds, :commands
- end
- end
-
- def down
- # rubocop:disable Migration/AddColumnsToWideTables
- with_lock_retries do
- add_column :ci_builds, :artifacts_file, :text
- add_column :ci_builds, :artifacts_file_store, :integer
- add_column :ci_builds, :artifacts_metadata, :text
- add_column :ci_builds, :artifacts_metadata_store, :integer
- add_column :ci_builds, :artifacts_size, :bigint
- add_column :ci_builds, :commands, :text
- end
- # rubocop:enable Migration/AddColumnsToWideTables
-
- add_concurrent_index :ci_builds, :artifacts_expire_at, where: "artifacts_file <> ''::text", name: 'index_ci_builds_on_artifacts_expire_at'
- end
-end
diff --git a/db/post_migrate/20210218110552_remove_deprecated_ci_runner_column.rb b/db/post_migrate/20210218110552_remove_deprecated_ci_runner_column.rb
deleted file mode 100644
index 06fd900590b..00000000000
--- a/db/post_migrate/20210218110552_remove_deprecated_ci_runner_column.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveDeprecatedCiRunnerColumn < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- # Set this constant to true if this migration requires downtime.
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_column :ci_runners, :is_shared
- end
- end
-
- def down
- add_column :ci_runners, :is_shared, :boolean, default: false unless column_exists?(:ci_runners, :is_shared)
-
- add_concurrent_index :ci_runners, :is_shared
- end
-end
diff --git a/db/post_migrate/20210219102900_reschedule_set_default_iteration_cadences.rb b/db/post_migrate/20210219102900_reschedule_set_default_iteration_cadences.rb
deleted file mode 100644
index 6c7b46737aa..00000000000
--- a/db/post_migrate/20210219102900_reschedule_set_default_iteration_cadences.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class RescheduleSetDefaultIterationCadences < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- BATCH_SIZE = 1_000
- DELAY_INTERVAL = 2.minutes.to_i
- MIGRATION_CLASS = 'SetDefaultIterationCadences'
-
- class Iteration < ActiveRecord::Base # rubocop:disable Style/Documentation
- include EachBatch
-
- self.table_name = 'sprints'
- end
-
- disable_ddl_transaction!
-
- def up
- Iteration.select(:group_id).distinct.each_batch(of: BATCH_SIZE, column: :group_id) do |batch, index|
- group_ids = batch.pluck(:group_id)
-
- migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, group_ids)
- end
- end
-
- def down
- # Not needed
- end
-end
diff --git a/db/post_migrate/20210222185538_remove_backup_labels_foreign_keys.rb b/db/post_migrate/20210222185538_remove_backup_labels_foreign_keys.rb
deleted file mode 100644
index 614ec4875d6..00000000000
--- a/db/post_migrate/20210222185538_remove_backup_labels_foreign_keys.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveBackupLabelsForeignKeys < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- with_lock_retries do
- remove_foreign_key_if_exists(:backup_labels, :projects)
- remove_foreign_key_if_exists(:backup_labels, :namespaces)
- end
- end
-
- def down
- add_concurrent_foreign_key(:backup_labels, :projects, column: :project_id, on_delete: :cascade)
- add_concurrent_foreign_key(:backup_labels, :namespaces, column: :group_id, on_delete: :cascade)
- end
-end
diff --git a/db/post_migrate/20210222192144_remove_backup_labels_table.rb b/db/post_migrate/20210222192144_remove_backup_labels_table.rb
deleted file mode 100644
index 1208c3c970f..00000000000
--- a/db/post_migrate/20210222192144_remove_backup_labels_table.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-class RemoveBackupLabelsTable < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def up
- drop_table :backup_labels
- end
-
- def down
- create_table :backup_labels, id: false do |t|
- t.integer :id, null: false
- t.string :title
- t.string :color
- t.integer :project_id
- t.timestamps null: true # rubocop:disable Migration/Timestamps
- t.boolean :template, default: false
- t.string :description
- t.text :description_html
- t.string :type
- t.integer :group_id
- t.integer :cached_markdown_version
- t.integer :restore_action
- t.string :new_title
- end
-
- execute 'ALTER TABLE backup_labels ADD PRIMARY KEY (id)'
-
- add_index :backup_labels, [:group_id, :project_id, :title], name: 'backup_labels_group_id_project_id_title_idx', unique: true
- add_index :backup_labels, [:group_id, :title], where: 'project_id = NULL::integer', name: 'backup_labels_group_id_title_idx'
- add_index :backup_labels, :project_id, name: 'backup_labels_project_id_idx'
- add_index :backup_labels, :template, name: 'backup_labels_template_idx', where: 'template'
- add_index :backup_labels, :title, name: 'backup_labels_title_idx'
- add_index :backup_labels, [:type, :project_id], name: 'backup_labels_type_project_id_idx'
- end
-end
diff --git a/db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb b/db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb
deleted file mode 100644
index 2c0fe405490..00000000000
--- a/db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-# frozen_string_literal: true
-
-class RescheduleArtifactExpiryBackfill < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION = 'BackfillArtifactExpiryDate'
- SWITCH_DATE = Date.new(2020, 06, 22).freeze
-
- disable_ddl_transaction!
-
- class JobArtifact < ActiveRecord::Base
- include EachBatch
-
- self.inheritance_column = :_type_disabled
- self.table_name = 'ci_job_artifacts'
-
- scope :without_expiry_date, -> { where(expire_at: nil) }
- scope :before_switch, -> { where("date(created_at AT TIME ZONE 'UTC') < ?::date", SWITCH_DATE) }
- end
-
- def up
- Gitlab::BackgroundMigration.steal(MIGRATION) do |job|
- job.delete
-
- false
- end
-
- queue_background_migration_jobs_by_range_at_intervals(
- JobArtifact.without_expiry_date.before_switch,
- MIGRATION,
- 2.minutes,
- batch_size: 200_000
- )
- end
-
- def down
- Gitlab::BackgroundMigration.steal(MIGRATION) do |job|
- job.delete
-
- false
- end
- end
-end
diff --git a/db/post_migrate/20210226120851_move_container_registry_enabled_to_project_features.rb b/db/post_migrate/20210226120851_move_container_registry_enabled_to_project_features.rb
deleted file mode 100644
index fce31110866..00000000000
--- a/db/post_migrate/20210226120851_move_container_registry_enabled_to_project_features.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class MoveContainerRegistryEnabledToProjectFeatures < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- BATCH_SIZE = 50_000
- MIGRATION = 'MoveContainerRegistryEnabledToProjectFeature'
-
- disable_ddl_transaction!
-
- class Project < ActiveRecord::Base
- include EachBatch
- self.table_name = 'projects'
- end
-
- def up
- # no-op
- # Superceded by db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb
-
- # queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE)
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20210226141517_dedup_issue_metrics.rb b/db/post_migrate/20210226141517_dedup_issue_metrics.rb
deleted file mode 100644
index 8228d509e07..00000000000
--- a/db/post_migrate/20210226141517_dedup_issue_metrics.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-# frozen_string_literal: true
-
-class DedupIssueMetrics < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- TMP_INDEX_NAME = 'tmp_unique_issue_metrics_by_issue_id'
- OLD_INDEX_NAME = 'index_issue_metrics'
- INDEX_NAME = 'index_unique_issue_metrics_issue_id'
- BATCH_SIZE = 1_000
-
- disable_ddl_transaction!
-
- class IssueMetrics < ActiveRecord::Base
- self.table_name = 'issue_metrics'
-
- include EachBatch
- end
-
- def up
- IssueMetrics.reset_column_information
-
- last_metrics_record_id = IssueMetrics.maximum(:id) || 0
-
- # This index will disallow further duplicates while we're deduplicating the data.
- add_concurrent_index(:issue_metrics, :issue_id, where: "id > #{Integer(last_metrics_record_id)}", unique: true, name: TMP_INDEX_NAME)
-
- IssueMetrics.each_batch(of: BATCH_SIZE) do |relation|
- duplicated_issue_ids = IssueMetrics
- .where(issue_id: relation.select(:issue_id))
- .select(:issue_id)
- .group(:issue_id)
- .having('COUNT(issue_metrics.issue_id) > 1')
- .pluck(:issue_id)
-
- duplicated_issue_ids.each do |issue_id|
- deduplicate_item(issue_id)
- end
- end
-
- add_concurrent_index(:issue_metrics, :issue_id, unique: true, name: INDEX_NAME)
- remove_concurrent_index_by_name(:issue_metrics, TMP_INDEX_NAME)
- remove_concurrent_index_by_name(:issue_metrics, OLD_INDEX_NAME)
- end
-
- def down
- add_concurrent_index(:issue_metrics, :issue_id, name: OLD_INDEX_NAME)
- remove_concurrent_index_by_name(:issue_metrics, TMP_INDEX_NAME)
- remove_concurrent_index_by_name(:issue_metrics, INDEX_NAME)
- end
-
- private
-
- def deduplicate_item(issue_id)
- issue_metrics_records = IssueMetrics.where(issue_id: issue_id).order(updated_at: :asc).to_a
-
- attributes = {}
- issue_metrics_records.each do |issue_metrics_record|
- params = issue_metrics_record.attributes.except('id')
- attributes.merge!(params.compact)
- end
-
- ActiveRecord::Base.transaction do
- record_to_keep = issue_metrics_records.pop
- records_to_delete = issue_metrics_records
-
- IssueMetrics.where(id: records_to_delete.map(&:id)).delete_all
- record_to_keep.update!(attributes)
- end
- end
-end
diff --git a/db/post_migrate/20210301200959_clean_up_asset_proxy_allowlist_rename_on_application_settings.rb b/db/post_migrate/20210301200959_clean_up_asset_proxy_allowlist_rename_on_application_settings.rb
deleted file mode 100644
index d0b372b84f0..00000000000
--- a/db/post_migrate/20210301200959_clean_up_asset_proxy_allowlist_rename_on_application_settings.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-class CleanUpAssetProxyAllowlistRenameOnApplicationSettings < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers::V2
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- cleanup_concurrent_column_rename :application_settings,
- :asset_proxy_allowlist,
- :asset_proxy_whitelist
- end
-
- def down
- undo_cleanup_concurrent_column_rename :application_settings,
- :asset_proxy_allowlist,
- :asset_proxy_whitelist
- 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
index 96eea2d5d77..0e85fb40a36 100644
--- a/db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb
+++ b/db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb
@@ -1,34 +1,9 @@
# frozen_string_literal: true
class ScheduleRecalculateUuidOnVulnerabilitiesOccurrences2 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 2_500
-
- disable_ddl_transaction!
-
- class VulnerabilitiesFinding < ActiveRecord::Base
- include ::EachBatch
- self.inheritance_column = :_type_disabled
-
- self.table_name = "vulnerability_occurrences"
- end
-
def up
- # Make sure that RemoveDuplicateVulnerabilitiesFindings has finished running
- # so that we don't run into duplicate UUID issues
- Gitlab::BackgroundMigration.steal('RemoveDuplicateVulnerabilitiesFindings')
-
- say "Scheduling #{MIGRATION} jobs"
- queue_background_migration_jobs_by_range_at_intervals(
- VulnerabilitiesFinding,
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
+ # no-op
+ # superseded by db/post_migrate/20211207125231_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb
end
def down
diff --git a/db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb b/db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb
index c59c71708ca..0e6f1c50534 100644
--- a/db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb
+++ b/db/post_migrate/20210813195518_schedule_recalculate_uuid_on_vulnerabilities_occurrences3.rb
@@ -1,27 +1,9 @@
# frozen_string_literal: true
class ScheduleRecalculateUuidOnVulnerabilitiesOccurrences3 < ActiveRecord::Migration[6.0]
- include Gitlab::Database::MigrationHelpers
-
- MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid'
- DELAY_INTERVAL = 2.minutes.to_i
- BATCH_SIZE = 2_500
-
- disable_ddl_transaction!
-
def up
- # Make sure that RemoveDuplicateVulnerabilitiesFindings has finished running
- # so that we don't run into duplicate UUID issues
- Gitlab::BackgroundMigration.steal('RemoveDuplicateVulnerabilitiesFindings')
-
- say "Scheduling #{MIGRATION} jobs"
- queue_background_migration_jobs_by_range_at_intervals(
- define_batchable_model('vulnerability_occurrences'),
- MIGRATION,
- DELAY_INTERVAL,
- batch_size: BATCH_SIZE,
- track_jobs: true
- )
+ # no-op
+ # superseded by db/post_migrate/20211207125231_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb
end
def down
diff --git a/db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb b/db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
index 88351b3007a..c03c379dcc0 100644
--- a/db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
+++ b/db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
@@ -1,15 +1,9 @@
# frozen_string_literal: true
class ReschedulePendingJobsForRecalculateVulnerabilitiesOccurrencesUuid < Gitlab::Database::Migration[1.0]
- MIGRATION = "RecalculateVulnerabilitiesOccurrencesUuid"
- DELAY_INTERVAL = 2.minutes
-
- disable_ddl_transaction!
-
def up
- delete_queued_jobs(MIGRATION)
-
- requeue_background_migration_jobs_by_range_at_intervals(MIGRATION, DELAY_INTERVAL)
+ # no-op
+ # no replacement because we will reschedule this for the whole table
end
def down
diff --git a/db/post_migrate/20211123161906_cleanup_after_drop_invalid_security_findings.rb b/db/post_migrate/20211123161906_cleanup_after_drop_invalid_security_findings.rb
new file mode 100644
index 00000000000..599342e83e3
--- /dev/null
+++ b/db/post_migrate/20211123161906_cleanup_after_drop_invalid_security_findings.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class CleanupAfterDropInvalidSecurityFindings < Gitlab::Database::Migration[1.0]
+ MIGRATION = "DropInvalidSecurityFindings"
+ INDEX_NAME = "tmp_index_uuid_is_null"
+
+ disable_ddl_transaction!
+
+ def up
+ # Make sure all jobs scheduled by
+ # db/post_migrate/20211110151350_schedule_drop_invalid_security_findings.rb
+ # are finished
+ finalize_background_migration(MIGRATION)
+ # Created by db/post_migrate/20211110151320_add_temporary_index_on_security_findings_uuid.rb
+ remove_concurrent_index_by_name :security_findings, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index(
+ :security_findings,
+ :id,
+ where: "uuid IS NULL",
+ name: INDEX_NAME
+ )
+ end
+end
diff --git a/db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb b/db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb
new file mode 100644
index 00000000000..0e370dfc5f8
--- /dev/null
+++ b/db/post_migrate/20211206161271_add_indexes_for_primary_email_cleanup_migration.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class AddIndexesForPrimaryEmailCleanupMigration < Gitlab::Database::Migration[1.0]
+ USERS_INDEX = :index_users_on_id_for_primary_email_migration
+ EMAIL_INDEX = :index_emails_on_email_user_id
+
+ disable_ddl_transaction!
+
+ def up
+ unless index_exists_by_name?(:users, USERS_INDEX)
+
+ disable_statement_timeout do
+ execute <<~SQL
+ CREATE INDEX CONCURRENTLY #{USERS_INDEX}
+ ON users (id) INCLUDE (email, confirmed_at)
+ WHERE confirmed_at IS NOT NULL
+ SQL
+ end
+ end
+
+ add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX
+ end
+
+ def down
+ remove_concurrent_index_by_name :users, USERS_INDEX
+ remove_concurrent_index_by_name :emails, EMAIL_INDEX
+ end
+end
diff --git a/db/post_migrate/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
new file mode 100644
index 00000000000..14f6c751e4d
--- /dev/null
+++ b/db/post_migrate/20211206162601_cleanup_after_add_primary_email_to_emails_if_user_confirmed.rb
@@ -0,0 +1,59 @@
+# 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/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb b/db/post_migrate/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb
new file mode 100644
index 00000000000..959bf61a6cc
--- /dev/null
+++ b/db/post_migrate/20211207081708_add_index_ci_job_artifacts_project_id_file_type.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexCiJobArtifactsProjectIdFileType < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_job_artifacts_on_id_project_id_and_file_type'
+
+ def up
+ add_concurrent_index :ci_job_artifacts, [:project_id, :file_type, :id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :ci_job_artifacts, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb b/db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
new file mode 100644
index 00000000000..cc37f2dc65d
--- /dev/null
+++ b/db/post_migrate/20211207125331_remove_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class RemoveJobsForRecalculateVulnerabilitiesOccurrencesUuid < Gitlab::Database::Migration[1.0]
+ MIGRATION_NAME = 'RecalculateVulnerabilitiesOccurrencesUuid'
+
+ def up
+ delete_job_tracking(
+ MIGRATION_NAME,
+ status: %w[pending succeeded]
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb b/db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb
new file mode 100644
index 00000000000..13abf8b5540
--- /dev/null
+++ b/db/post_migrate/20211207135331_schedule_recalculate_uuid_on_vulnerabilities_occurrences4.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class ScheduleRecalculateUuidOnVulnerabilitiesOccurrences4 < Gitlab::Database::Migration[1.0]
+ MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid'
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 2_500
+
+ disable_ddl_transaction!
+
+ def up
+ # Make sure the migration removing Findings with attributes for which UUID would be identical
+ # has finished
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74008
+ Gitlab::BackgroundMigration.steal('RemoveOccurrencePipelinesAndDuplicateVulnerabilitiesFindings')
+
+ queue_background_migration_jobs_by_range_at_intervals(
+ define_batchable_model('vulnerability_occurrences'),
+ MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ track_jobs: true
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb b/db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb
new file mode 100644
index 00000000000..eaf07abe29d
--- /dev/null
+++ b/db/post_migrate/20211207173510_remove_extra_finding_evidence_tables_foreign_keys.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+class RemoveExtraFindingEvidenceTablesForeignKeys < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key :vulnerability_finding_evidence_assets, :vulnerability_finding_evidences
+ remove_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_requests
+ remove_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_responses
+ remove_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidences
+ remove_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidence_supporting_messages
+ remove_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidences
+ remove_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidence_supporting_messages
+ remove_foreign_key :vulnerability_finding_evidence_sources, :vulnerability_finding_evidences
+ remove_foreign_key :vulnerability_finding_evidence_supporting_messages, :vulnerability_finding_evidences
+ end
+ end
+
+ def down
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_assets, :vulnerability_finding_evidences, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_requests, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_headers, :vulnerability_finding_evidence_responses, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidences, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_requests, :vulnerability_finding_evidence_supporting_messages, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidences, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_responses, :vulnerability_finding_evidence_supporting_messages, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_sources, :vulnerability_finding_evidences, on_delete: :cascade
+ end
+
+ with_lock_retries do
+ add_foreign_key :vulnerability_finding_evidence_supporting_messages, :vulnerability_finding_evidences, on_delete: :cascade
+ end
+ end
+end
diff --git a/db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb b/db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb
new file mode 100644
index 00000000000..9a246a8c707
--- /dev/null
+++ b/db/post_migrate/20211207173511_remove_extra_finding_evidence_tables.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+class RemoveExtraFindingEvidenceTables < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ drop_table :vulnerability_finding_evidence_assets, if_exists: true
+ drop_table :vulnerability_finding_evidence_headers, if_exists: true
+ drop_table :vulnerability_finding_evidence_requests, if_exists: true
+ drop_table :vulnerability_finding_evidence_responses, if_exists: true
+ drop_table :vulnerability_finding_evidence_sources, if_exists: true
+ drop_table :vulnerability_finding_evidence_supporting_messages, if_exists: true
+ end
+ end
+
+ def down
+ create_table :vulnerability_finding_evidence_assets, if_not_exists: true do |t|
+ t.timestamps_with_timezone null: false
+
+ t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_assets_on_finding_evidence_id' }, null: false
+ t.text :type, limit: 2048
+ t.text :name, limit: 2048
+ t.text :url, limit: 2048
+ end
+
+ create_table :vulnerability_finding_evidence_sources, if_not_exists: true do |t|
+ t.timestamps_with_timezone null: false
+
+ t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_sources_on_finding_evidence_id' }, null: false
+ t.text :name, limit: 2048
+ t.text :url, limit: 2048
+ end
+
+ create_table :vulnerability_finding_evidence_supporting_messages, if_not_exists: true do |t|
+ t.timestamps_with_timezone null: false
+
+ t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_supporting_messages_on_finding_evidence_id' }, null: false
+ t.text :name, limit: 2048
+ end
+
+ create_table :vulnerability_finding_evidence_requests, if_not_exists: true do |t|
+ t.timestamps_with_timezone null: false
+
+ t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_requests_on_finding_evidence_id' }, null: true
+ t.text :method, limit: 32
+ t.text :url, limit: 2048
+ t.text :body, limit: 2048
+ t.references :vulnerability_finding_evidence_supporting_message, index: { name: 'finding_evidence_requests_on_supporting_evidence_id' }, null: true
+ end
+
+ create_table :vulnerability_finding_evidence_responses, if_not_exists: true do |t|
+ t.timestamps_with_timezone null: false
+
+ t.references :vulnerability_finding_evidence, index: { name: 'finding_evidence_responses_on_finding_evidences_id' }, null: true
+ t.integer :status_code
+ t.text :reason_phrase, limit: 2048
+ t.text :body, limit: 2048
+ t.references :vulnerability_finding_evidence_supporting_message, index: { name: 'finding_evidence_responses_on_supporting_evidence_id' }, null: true
+ end
+
+ create_table :vulnerability_finding_evidence_headers, if_not_exists: true do |t|
+ t.timestamps_with_timezone null: false
+
+ t.references :vulnerability_finding_evidence_request, index: { name: 'finding_evidence_header_on_finding_evidence_request_id' }, null: true
+ t.references :vulnerability_finding_evidence_response, index: { name: 'finding_evidence_header_on_finding_evidence_response_id' }, null: true
+ t.text :name, null: false, limit: 255
+ t.text :value, null: false, limit: 8192
+ end
+ end
+end
diff --git a/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb b/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb
new file mode 100644
index 00000000000..3d39148f402
--- /dev/null
+++ b/db/post_migrate/20211208122200_schedule_backfill_ci_namespace_mirrors.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class ScheduleBackfillCiNamespaceMirrors < Gitlab::Database::Migration[1.0]
+ MIGRATION = 'BackfillCiNamespaceMirrors'
+ BATCH_SIZE = 10_000
+ DELAY_INTERVAL = 2.minutes
+
+ disable_ddl_transaction!
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(
+ Gitlab::BackgroundMigration::BackfillCiNamespaceMirrors::Namespace.base_query,
+ MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ track_jobs: true
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb b/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb
new file mode 100644
index 00000000000..5678ee9f292
--- /dev/null
+++ b/db/post_migrate/20211208122201_schedule_backfill_ci_project_mirrors.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class ScheduleBackfillCiProjectMirrors < Gitlab::Database::Migration[1.0]
+ MIGRATION = 'BackfillCiProjectMirrors'
+ BATCH_SIZE = 10_000
+ DELAY_INTERVAL = 2.minutes
+
+ disable_ddl_transaction!
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(
+ Gitlab::BackgroundMigration::BackfillCiProjectMirrors::Project.base_query,
+ MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ track_jobs: true
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb b/db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb
new file mode 100644
index 00000000000..07a2c079511
--- /dev/null
+++ b/db/post_migrate/20211209203820_add_tmp_index_on_report_type.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+class AddTmpIndexOnReportType < Gitlab::Database::Migration[1.0]
+ # Temporary index to perform migration fixing invalid vulnerability_occurrences.raw_metadata rows
+ # Will be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/349605
+ INDEX_NAME = 'tmp_idx_vulnerability_occurrences_on_id_where_report_type_7_99'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :vulnerability_occurrences, :id, where: 'report_type IN (7, 99)', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb b/db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb
new file mode 100644
index 00000000000..757cbf60d4d
--- /dev/null
+++ b/db/post_migrate/20211209203821_convert_stringified_raw_metadata_hash_to_json.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+class ConvertStringifiedRawMetadataHashToJson < Gitlab::Database::Migration[1.0]
+ MIGRATION_CLASS = Gitlab::BackgroundMigration::FixVulnerabilityOccurrencesWithHashesAsRawMetadata
+ MODEL_CLASS = MIGRATION_CLASS::Finding
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 500
+
+ disable_ddl_transaction!
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(
+ MODEL_CLASS.by_api_report_types,
+ MIGRATION_CLASS,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+
+ def down
+ # no-op
+
+ # up fixes invalid data by updating columns in-place.
+ # It is a backwards-compatible change, and reversing it in a downgrade would not be desirable.
+ end
+end
diff --git a/db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb b/db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb
new file mode 100644
index 00000000000..54997dc4cc4
--- /dev/null
+++ b/db/post_migrate/20211210140000_add_temporary_static_object_token_index.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddTemporaryStaticObjectTokenIndex < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_users_with_static_object_token'
+
+ def up
+ add_concurrent_index :users, :id, where: "static_object_token IS NOT NULL AND static_object_token_encrypted IS NULL", name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index :users, :id, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20211210140629_encrypt_static_object_token.rb b/db/post_migrate/20211210140629_encrypt_static_object_token.rb
new file mode 100644
index 00000000000..fe4db9fc14c
--- /dev/null
+++ b/db/post_migrate/20211210140629_encrypt_static_object_token.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class EncryptStaticObjectToken < Gitlab::Database::Migration[1.0]
+ BATCH_SIZE = 10_000
+ MIGRATION = 'EncryptStaticObjectToken'
+
+ disable_ddl_transaction!
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(
+ define_batchable_model('users').where.not(static_object_token: nil).where(static_object_token_encrypted: nil),
+ MIGRATION,
+ 2.minutes,
+ batch_size: BATCH_SIZE,
+ track_jobs: true
+ )
+ end
+
+ def down
+ # no ops
+ end
+end
diff --git a/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb b/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb
new file mode 100644
index 00000000000..7f0168be1a4
--- /dev/null
+++ b/db/post_migrate/20211214012507_backfill_incident_issue_escalation_statuses.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class BackfillIncidentIssueEscalationStatuses < Gitlab::Database::Migration[1.0]
+ MIGRATION = 'BackfillIncidentIssueEscalationStatuses'
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 20_000
+
+ disable_ddl_transaction!
+
+ class Issue < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'issues'
+ end
+
+ def up
+ relation = Issue.all
+
+ queue_background_migration_jobs_by_range_at_intervals(
+ relation, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE, track_jobs: true)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb b/db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb
new file mode 100644
index 00000000000..310a49a667e
--- /dev/null
+++ b/db/post_migrate/20211217120000_modify_kubernetes_resource_location_index_to_vulnerability_occurrences.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class ModifyKubernetesResourceLocationIndexToVulnerabilityOccurrences < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ OLD_CLUSTER_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_cluster_id'
+ OLD_AGENT_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_agent_id'
+
+ NEW_CLUSTER_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_k8s_cluster_id'
+ NEW_AGENT_ID_INDEX_NAME = 'index_vulnerability_occurrences_on_location_k8s_agent_id'
+
+ def up
+ add_concurrent_index :vulnerability_occurrences, "(location -> 'kubernetes_resource' -> 'cluster_id')",
+ using: 'GIN',
+ where: 'report_type = 7',
+ name: NEW_CLUSTER_ID_INDEX_NAME
+
+ add_concurrent_index :vulnerability_occurrences, "(location -> 'kubernetes_resource' -> 'agent_id')",
+ using: 'GIN',
+ where: 'report_type = 7',
+ name: NEW_AGENT_ID_INDEX_NAME
+
+ remove_concurrent_index_by_name :vulnerability_occurrences, OLD_CLUSTER_ID_INDEX_NAME
+ remove_concurrent_index_by_name :vulnerability_occurrences, OLD_AGENT_ID_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :vulnerability_occurrences, "(location -> 'cluster_id')",
+ using: 'GIN',
+ where: 'report_type = 7',
+ name: OLD_CLUSTER_ID_INDEX_NAME
+
+ add_concurrent_index :vulnerability_occurrences, "(location -> 'agent_id')",
+ using: 'GIN',
+ where: 'report_type = 7',
+ name: OLD_AGENT_ID_INDEX_NAME
+
+ remove_concurrent_index_by_name :vulnerability_occurrences, NEW_CLUSTER_ID_INDEX_NAME
+ remove_concurrent_index_by_name :vulnerability_occurrences, NEW_AGENT_ID_INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb b/db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb
new file mode 100644
index 00000000000..a05d68279c3
--- /dev/null
+++ b/db/post_migrate/20211217145923_add_index_to_events_on_author_id_and_action_and_id.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class AddIndexToEventsOnAuthorIdAndActionAndId < Gitlab::Database::Migration[1.0]
+ # no-op
+ # see: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77436
+
+ def up
+ # no-op
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb b/db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb
new file mode 100644
index 00000000000..316209ae1f4
--- /dev/null
+++ b/db/post_migrate/20211217174331_mark_recalculate_finding_signatures_as_completed.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class MarkRecalculateFindingSignaturesAsCompleted < Gitlab::Database::Migration[1.0]
+ MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid'
+
+ def up
+ # Only run migration for Gitlab.com
+ return unless ::Gitlab.com?
+
+ # In previous migration marking jobs as successful was missed
+ Gitlab::Database::BackgroundMigrationJob
+ .for_migration_class(MIGRATION)
+ .pending
+ .update_all(status: :succeeded)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb b/db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb
new file mode 100644
index 00000000000..1d61aec401e
--- /dev/null
+++ b/db/post_migrate/20211220064757_drop_temporary_indexes_for_primary_email_migration.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class DropTemporaryIndexesForPrimaryEmailMigration < Gitlab::Database::Migration[1.0]
+ USERS_INDEX = :index_users_on_id_for_primary_email_migration
+ EMAIL_INDEX = :index_emails_on_email_user_id
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :users, USERS_INDEX
+ remove_concurrent_index_by_name :emails, EMAIL_INDEX
+ end
+
+ def down
+ unless index_exists_by_name?(:users, USERS_INDEX)
+
+ disable_statement_timeout do
+ execute <<~SQL
+ CREATE INDEX CONCURRENTLY #{USERS_INDEX}
+ ON users (id) INCLUDE (email, confirmed_at)
+ WHERE confirmed_at IS NOT NULL
+ SQL
+ end
+ end
+
+ add_concurrent_index :emails, [:email, :user_id], name: EMAIL_INDEX
+ end
+end
diff --git a/db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb b/db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb
new file mode 100644
index 00000000000..c98d3d05f2f
--- /dev/null
+++ b/db/post_migrate/20211220120402_add_index_on_ci_pipelines_user_id_id_failure_reason.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexOnCiPipelinesUserIdIdFailureReason < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_pipelines_on_user_id_and_id_desc_and_user_not_verified'
+
+ def up
+ add_concurrent_index :ci_pipelines, [:user_id, :id], order: { id: :desc }, where: 'failure_reason = 3', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :ci_pipelines, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20211220123956_update_invalid_member_states.rb b/db/post_migrate/20211220123956_update_invalid_member_states.rb
new file mode 100644
index 00000000000..5da100f0ec2
--- /dev/null
+++ b/db/post_migrate/20211220123956_update_invalid_member_states.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class UpdateInvalidMemberStates < Gitlab::Database::Migration[1.0]
+ class Member < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'members'
+
+ scope :in_invalid_state, -> { where(state: 2) }
+ end
+
+ def up
+ Member.in_invalid_state.each_batch do |relation|
+ relation.update_all(state: 0)
+ end
+ end
+
+ def down
+ # no-op as we don't need to revert any changed records
+ end
+end
diff --git a/db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb b/db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb
new file mode 100644
index 00000000000..5338cab3871
--- /dev/null
+++ b/db/post_migrate/20211229023654_add_async_index_ci_job_artifacts_project_id_file_type.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddAsyncIndexCiJobArtifactsProjectIdFileType < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_ci_job_artifacts_on_id_project_id_and_file_type'
+
+ def up
+ prepare_async_index :ci_job_artifacts, [:project_id, :file_type, :id], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index_by_name :ci_job_artifacts, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb b/db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb
new file mode 100644
index 00000000000..2215a49e286
--- /dev/null
+++ b/db/post_migrate/20211230112517_remove_index_events_on_author_id_and_action_and_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveIndexEventsOnAuthorIdAndActionAndId < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'index_events_on_author_id_and_action_and_id'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :events, name: INDEX_NAME
+ end
+
+ def down
+ # no-op
+ # The index had been added in the same milestone.
+ # Adding back the index takes a long time and should not be needed.
+ end
+end
diff --git a/db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb b/db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb
new file mode 100644
index 00000000000..e4cdc9add39
--- /dev/null
+++ b/db/post_migrate/20211230113031_add_index_to_events_on_author_id_and_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexToEventsOnAuthorIdAndId < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'index_events_on_author_id_and_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :events, [:author_id, :id], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :events, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb b/db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb
new file mode 100644
index 00000000000..9be81e00b50
--- /dev/null
+++ b/db/post_migrate/20220104060049_remove_foreign_key_ci_group_variables_group_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeyCiGroupVariablesGroupId < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_33ae4d58d8'
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_group_variables, :namespaces, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :ci_group_variables, :namespaces, column: :group_id, on_delete: :cascade, name: CONSTRAINT_NAME
+ end
+end
diff --git a/db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb b/db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb
new file mode 100644
index 00000000000..b072d5616f5
--- /dev/null
+++ b/db/post_migrate/20220105020514_remove_ci_minutes_additional_packs_namespace_id_foreign_key_constraint.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveCiMinutesAdditionalPacksNamespaceIdForeignKeyConstraint < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_rails_e0e0c4e4b1'
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_minutes_additional_packs, :namespaces, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :ci_minutes_additional_packs, :namespaces, column: :namespace_id, on_delete: :cascade, name: CONSTRAINT_NAME
+ end
+end
diff --git a/db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb b/db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb
new file mode 100644
index 00000000000..ece20f8095d
--- /dev/null
+++ b/db/post_migrate/20220106231518_remove_foreign_key_ci_daily_build_group_report_results_group_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeyCiDailyBuildGroupReportResultsGroupId < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_fd1858fefd'
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_daily_build_group_report_results, :namespaces, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :ci_daily_build_group_report_results, :namespaces, column: :group_id, on_delete: :cascade, name: CONSTRAINT_NAME
+ end
+end
diff --git a/db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb b/db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb
new file mode 100644
index 00000000000..1304f19708e
--- /dev/null
+++ b/db/post_migrate/20220106233459_remove_foreign_key_ci_pending_builds_namespace_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeyCiPendingBuildsNamespaceId < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_fdc0137e4a'
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_pending_builds, :namespaces, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :ci_pending_builds, :namespaces, column: :namespace_id, on_delete: :cascade, name: CONSTRAINT_NAME
+ end
+end
diff --git a/db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb b/db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb
new file mode 100644
index 00000000000..61ca066401e
--- /dev/null
+++ b/db/post_migrate/20220106235626_remove_foreign_key_ci_runner_namespaces_namespace_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveForeignKeyCiRunnerNamespacesNamespaceId < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_rails_f9d9ed3308'
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_runner_namespaces, :namespaces, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key :ci_runner_namespaces, :namespaces, column: :namespace_id, on_delete: :cascade, name: CONSTRAINT_NAME
+ end
+end
diff --git a/db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb b/db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb
new file mode 100644
index 00000000000..06be8edd707
--- /dev/null
+++ b/db/post_migrate/20220109134455_add_idx_vulnerability_occurrences_dedup_again.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIdxVulnerabilityOccurrencesDedupAgain < Gitlab::Database::Migration[1.0]
+ TABLE = :vulnerability_occurrences
+ INDEX_NAME = 'index_vulnerability_occurrences_deduplication'
+ COLUMNS = %i[project_id report_type project_fingerprint]
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index TABLE, COLUMNS, name: INDEX_NAME
+ end
+
+ def down
+ # nothing to do here
+ end
+end
diff --git a/db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb b/db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb
new file mode 100644
index 00000000000..dae93e1636d
--- /dev/null
+++ b/db/post_migrate/20220110171049_schedule_populate_test_reports_issue_id.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class SchedulePopulateTestReportsIssueId < Gitlab::Database::Migration[1.0]
+ MIGRATION = 'PopulateTestReportsIssueId'
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 30
+
+ disable_ddl_transaction!
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(
+ define_batchable_model('requirements_management_test_reports').where(issue_id: nil),
+ MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ track_jobs: true
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb b/db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb
new file mode 100644
index 00000000000..d91cd3b43ef
--- /dev/null
+++ b/db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveDastScannerProfilesBuildsCiBuildIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_e4c49200f8'
+
+ def up
+ with_lock_retries do
+ execute('LOCK ci_builds, dast_scanner_profiles_builds IN ACCESS EXCLUSIVE MODE')
+ remove_foreign_key_if_exists(:dast_scanner_profiles_builds, :ci_builds, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:dast_scanner_profiles_builds, :ci_builds, column: :ci_build_id, on_delete: :cascade, name: CONSTRAINT_NAME)
+ end
+end
diff --git a/db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb b/db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb
new file mode 100644
index 00000000000..dd8c6de4aaf
--- /dev/null
+++ b/db/post_migrate/20220110231420_remove_requirements_management_test_reports_build_id_fk.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveRequirementsManagementTestReportsBuildIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_rails_e67d085910'
+
+ def up
+ with_lock_retries do
+ execute('LOCK ci_builds, requirements_management_test_reports IN ACCESS EXCLUSIVE MODE')
+ remove_foreign_key_if_exists(:requirements_management_test_reports, :ci_builds, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:requirements_management_test_reports, :ci_builds, column: :build_id, on_delete: :nullify, name: CONSTRAINT_NAME)
+ end
+end
diff --git a/db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb b/db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb
new file mode 100644
index 00000000000..00d8a39216b
--- /dev/null
+++ b/db/post_migrate/20220110233155_remove_dast_site_profiles_builds_ci_build_id_fk.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveDastSiteProfilesBuildsCiBuildIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_a325505e99'
+
+ def up
+ with_lock_retries do
+ execute('LOCK ci_builds, dast_site_profiles_builds IN ACCESS EXCLUSIVE MODE')
+ remove_foreign_key_if_exists(:dast_site_profiles_builds, :ci_builds, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:dast_site_profiles_builds, :ci_builds, column: :ci_build_id, on_delete: :cascade, name: CONSTRAINT_NAME)
+ end
+end
diff --git a/db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb b/db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb
new file mode 100644
index 00000000000..20782664f63
--- /dev/null
+++ b/db/post_migrate/20220111002756_remove_security_scans_build_id_fk.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class RemoveSecurityScansBuildIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ CONSTRAINT_NAME = 'fk_rails_4ef1e6b4c6'
+
+ def up
+ with_lock_retries do
+ execute('LOCK ci_builds, security_scans IN ACCESS EXCLUSIVE MODE')
+ remove_foreign_key_if_exists(:security_scans, :ci_builds, name: CONSTRAINT_NAME)
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:security_scans, :ci_builds, column: :build_id, on_delete: :cascade, name: CONSTRAINT_NAME)
+ end
+end
diff --git a/db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb b/db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb
new file mode 100644
index 00000000000..6de0f9424e8
--- /dev/null
+++ b/db/post_migrate/20220111023852_index_cluster_agent_tokens_on_status.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class IndexClusterAgentTokensOnStatus < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'index_cluster_agent_tokens_on_agent_id_status_last_used_at'
+
+ def up
+ add_concurrent_index :cluster_agent_tokens, 'agent_id, status, last_used_at DESC NULLS LAST', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :cluster_agent_tokens, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb b/db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb
new file mode 100644
index 00000000000..795ec24f3bd
--- /dev/null
+++ b/db/post_migrate/20220111102314_truncate_ci_mirror_tables.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class TruncateCiMirrorTables < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ execute('TRUNCATE TABLE ci_namespace_mirrors')
+ execute('TRUNCATE TABLE ci_project_mirrors')
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb b/db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb
new file mode 100644
index 00000000000..bc17c125ba7
--- /dev/null
+++ b/db/post_migrate/20220111221516_remove_projects_ci_pending_builds_fk.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiPendingBuildsFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_pending_builds, :projects, name: "fk_rails_480669c3b3")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_pending_builds, :projects, name: "fk_rails_480669c3b3", column: :project_id, target_column: :id, on_delete: "cascade")
+ end
+end
diff --git a/db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb b/db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb
new file mode 100644
index 00000000000..79d864e2c2a
--- /dev/null
+++ b/db/post_migrate/20220112015940_remove_projects_ci_running_builds_fk.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiRunningBuildsFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ execute('LOCK projects, ci_running_builds IN ACCESS EXCLUSIVE MODE')
+
+ remove_foreign_key_if_exists(:ci_running_builds, :projects, name: "fk_rails_dc1d0801e8")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_running_builds, :projects, name: "fk_rails_dc1d0801e8", column: :project_id, target_column: :id, on_delete: "cascade")
+ end
+end
diff --git a/db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb b/db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb
new file mode 100644
index 00000000000..d786c9d846a
--- /dev/null
+++ b/db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class RemoveCascadeDeleteFromProjectNamespaceForeignKey < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ TARGET_COLUMN = :project_namespace_id
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
+ end
+
+ add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :nullify)
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
+ end
+
+ add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :cascade)
+ end
+end
diff --git a/db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb b/db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb
new file mode 100644
index 00000000000..9ad90a3a7a0
--- /dev/null
+++ b/db/post_migrate/20220112230642_remove_projects_ci_unit_tests_project_id_fk.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiUnitTestsProjectIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_unit_tests, :projects, name: "fk_7a8fabf0a8")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_unit_tests, :projects, name: "fk_7a8fabf0a8", column: :project_id, target_column: :id, on_delete: "cascade")
+ end
+end
diff --git a/db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb b/db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb
new file mode 100644
index 00000000000..ad7cf2a20c9
--- /dev/null
+++ b/db/post_migrate/20220112232723_remove_projects_ci_daily_build_group_report_results_project_id_fk.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiDailyBuildGroupReportResultsProjectIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ execute('LOCK projects, ci_daily_build_group_report_results IN ACCESS EXCLUSIVE MODE')
+ remove_foreign_key_if_exists(:ci_daily_build_group_report_results, :projects, name: "fk_rails_0667f7608c")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_daily_build_group_report_results, :projects, name: "fk_rails_0667f7608c", column: :project_id, target_column: :id, on_delete: "cascade")
+ end
+end
diff --git a/db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb b/db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb
new file mode 100644
index 00000000000..13cfacdc223
--- /dev/null
+++ b/db/post_migrate/20220113013319_remove_projects_ci_freeze_periods_project_id_fk.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiFreezePeriodsProjectIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_freeze_periods, :projects, name: "fk_2e02bbd1a6")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_freeze_periods, :projects, name: "fk_2e02bbd1a6", column: :project_id, target_column: :id, on_delete: "cascade")
+ end
+end
diff --git a/db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb b/db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb
new file mode 100644
index 00000000000..e86dd015493
--- /dev/null
+++ b/db/post_migrate/20220113014438_remove_projects_ci_resource_groups_project_id_fk.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiResourceGroupsProjectIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_resource_groups, :projects, name: "fk_774722d144")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_resource_groups, :projects, name: "fk_774722d144", column: :project_id, target_column: :id, on_delete: "cascade")
+ end
+end
diff --git a/db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb b/db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb
new file mode 100644
index 00000000000..3d2753bf9bf
--- /dev/null
+++ b/db/post_migrate/20220113015830_remove_projects_ci_build_report_results_project_id_fk.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiBuildReportResultsProjectIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_build_report_results, :projects, name: "fk_rails_056d298d48")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_build_report_results, :projects, name: "fk_rails_056d298d48", column: :project_id, target_column: :id, on_delete: "cascade")
+ end
+end
diff --git a/db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb b/db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb
new file mode 100644
index 00000000000..966286a6730
--- /dev/null
+++ b/db/post_migrate/20220113035519_remove_users_ci_job_token_project_scope_links_added_by_id_fk.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveUsersCiJobTokenProjectScopeLinksAddedByIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_job_token_project_scope_links, :users, name: "fk_rails_35f7f506ce")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_job_token_project_scope_links, :users, name: "fk_rails_35f7f506ce", column: :added_by_id, target_column: :id, on_delete: :nullify)
+ end
+end
diff --git a/db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb b/db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb
new file mode 100644
index 00000000000..2e5d4cfd22e
--- /dev/null
+++ b/db/post_migrate/20220113040447_remove_users_ci_pipeline_schedules_owner_id_fk.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveUsersCiPipelineSchedulesOwnerIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ remove_foreign_key_if_exists(:ci_pipeline_schedules, :users, name: "fk_9ea99f58d2")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_pipeline_schedules, :users, name: "fk_9ea99f58d2", column: :owner_id, target_column: :id, on_delete: :nullify)
+ end
+end
diff --git a/db/post_migrate/20220114105525_add_index_on_projects_path.rb b/db/post_migrate/20220114105525_add_index_on_projects_path.rb
new file mode 100644
index 00000000000..cef38f91b21
--- /dev/null
+++ b/db/post_migrate/20220114105525_add_index_on_projects_path.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexOnProjectsPath < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ TABLE = :projects
+ INDEX_NAME = 'index_on_projects_path'
+ COLUMN = :path
+
+ def up
+ add_concurrent_index TABLE, COLUMN, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index TABLE, COLUMN, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb b/db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb
new file mode 100644
index 00000000000..1ea89609926
--- /dev/null
+++ b/db/post_migrate/20220116175851_add_author_index_to_design_management_versions.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddAuthorIndexToDesignManagementVersions < Gitlab::Database::Migration[1.0]
+ TABLE = :design_management_versions
+ INDEX_NAME = 'index_design_management_versions_on_author_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index TABLE, :author_id, where: 'author_id IS NOT NULL', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index TABLE, :author_id, name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb b/db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb
new file mode 100644
index 00000000000..59a003c8f8d
--- /dev/null
+++ b/db/post_migrate/20220119141736_remove_projects_ci_pipeline_artifacts_project_id_fk.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class RemoveProjectsCiPipelineArtifactsProjectIdFk < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ execute('LOCK projects, ci_pipeline_artifacts IN ACCESS EXCLUSIVE MODE')
+
+ remove_foreign_key_if_exists(:ci_pipeline_artifacts, :projects, name: "fk_rails_4a70390ca6")
+ end
+ end
+
+ def down
+ add_concurrent_foreign_key(:ci_pipeline_artifacts, :projects, name: "fk_rails_4a70390ca6", column: :project_id, target_column: :id, on_delete: :cascade)
+ end
+end