summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
commita5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch)
treefb69158581673816a8cd895f9d352dcb3c678b1e /db/post_migrate
parentd16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff)
downloadgitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb10
-rw-r--r--db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb26
-rw-r--r--db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb37
-rw-r--r--db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb16
-rw-r--r--db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb36
-rw-r--r--db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb27
-rw-r--r--db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb29
-rw-r--r--db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb42
-rw-r--r--db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb16
-rw-r--r--db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb89
-rw-r--r--db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb44
-rw-r--r--db/post_migrate/20210525075724_clean_up_pending_builds_table.rb28
-rw-r--r--db/post_migrate/20210526160133_remove_segment_selections_table.rb26
-rw-r--r--db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb17
-rw-r--r--db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb15
-rw-r--r--db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb13
-rw-r--r--db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb27
-rw-r--r--db/post_migrate/20210604070207_retry_backfill_traversal_ids.rb21
-rw-r--r--db/post_migrate/20210606143426_add_index_for_container_registry_access_level.rb36
-rw-r--r--db/post_migrate/20210609125005_drop_non_partitioned_web_hook_logs.rb43
-rw-r--r--db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb26
-rw-r--r--db/post_migrate/20210610113229_add_index_to_protected_pending_builds.rb17
-rw-r--r--db/post_migrate/20210610141711_disable_expiration_policies_linked_to_no_container_images.rb32
-rw-r--r--db/post_migrate/20210611080951_fix_missing_traversal_ids.rb48
24 files changed, 716 insertions, 5 deletions
diff --git a/db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb b/db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb
index 04cf5906b61..f337390f10c 100644
--- a/db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb
+++ b/db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb
@@ -18,12 +18,12 @@ class ScheduleCalculateWikiSizes < ActiveRecord::Migration[5.0]
disable_ddl_transaction!
+ # Disabling this old migration because it should already run
+ # in 14.0. This will allow us to remove some `technical debt`
+ # in ProjectStatistics model, because of some columns
+ # not present by the time the migration is run.
def up
- queue_background_migration_jobs_by_range_at_intervals(
- ::ScheduleCalculateWikiSizes::ProjectStatistics.without_wiki_size,
- MIGRATION,
- BATCH_TIME,
- batch_size: BATCH_SIZE)
+ # no-op
end
def down
diff --git a/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb b/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb
new file mode 100644
index 00000000000..7d4d97acf58
--- /dev/null
+++ b/db/post_migrate/20210421163509_schedule_update_jira_tracker_data_deployment_type_based_on_url.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class ScheduleUpdateJiraTrackerDataDeploymentTypeBasedOnUrl < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ MIGRATION = 'UpdateJiraTrackerDataDeploymentTypeBasedOnUrl'
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 2_500
+
+ disable_ddl_transaction!
+
+ def up
+ say "Scheduling #{MIGRATION} jobs"
+ queue_background_migration_jobs_by_range_at_intervals(
+ define_batchable_model('jira_tracker_data'),
+ MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+
+ def down
+ # no-op
+ 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
new file mode 100644
index 00000000000..96eea2d5d77
--- /dev/null
+++ b/db/post_migrate/20210426225417_schedule_recalculate_uuid_on_vulnerabilities_occurrences2.rb
@@ -0,0 +1,37 @@
+# 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
+ )
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb b/db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb
new file mode 100644
index 00000000000..f832b06d439
--- /dev/null
+++ b/db/post_migrate/20210430121542_backfill_ci_build_trace_sections_for_bigint_conversion.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class BackfillCiBuildTraceSectionsForBigintConversion < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ TABLE = :ci_build_trace_sections
+ COLUMN = :build_id
+
+ def up
+ backfill_conversion_of_integer_to_bigint TABLE, COLUMN, batch_size: 15000, sub_batch_size: 100, primary_key: COLUMN
+ end
+
+ def down
+ revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMN, primary_key: COLUMN
+ end
+end
diff --git a/db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb b/db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb
new file mode 100644
index 00000000000..665d274a0ee
--- /dev/null
+++ b/db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class CleanupMoveContainerRegistryEnabledToProjectFeature < ActiveRecord::Migration[6.0]
+ MIGRATION = 'MoveContainerRegistryEnabledToProjectFeature'
+
+ disable_ddl_transaction!
+
+ def up
+ Gitlab::BackgroundMigration.steal(MIGRATION)
+
+ bg_migration_job_class = define_background_migration_jobs_class
+ bg_migration_job_class.where(class_name: MIGRATION, status: bg_migration_job_class.statuses['pending']).each do |job|
+ Gitlab::BackgroundMigration::MoveContainerRegistryEnabledToProjectFeature.new.perform(*job.arguments)
+ end
+
+ bg_migration_job_class.where(class_name: MIGRATION).delete_all
+ end
+
+ def down
+ # no-op
+ end
+
+ private
+
+ def define_background_migration_jobs_class
+ Class.new(ActiveRecord::Base) do
+ self.table_name = 'background_migration_jobs'
+ self.inheritance_column = :_type_disabled
+
+ enum status: {
+ pending: 0,
+ succeeded: 1
+ }
+ end
+ end
+end
diff --git a/db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb b/db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb
new file mode 100644
index 00000000000..76e4a0a95bb
--- /dev/null
+++ b/db/post_migrate/20210514063252_schedule_cleanup_orphaned_lfs_objects_projects.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class ScheduleCleanupOrphanedLfsObjectsProjects < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ MIGRATION = 'CleanupOrphanedLfsObjectsProjects'
+ DELAY_INTERVAL = 2.minutes
+ BATCH_SIZE = 50_000
+
+ disable_ddl_transaction!
+
+ class LfsObjectsProject < ActiveRecord::Base
+ self.table_name = 'lfs_objects_projects'
+
+ include ::EachBatch
+ end
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(LfsObjectsProject, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
+ end
+
+ def down
+ # NOOP
+ end
+end
diff --git a/db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb b/db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb
new file mode 100644
index 00000000000..8583f8541c7
--- /dev/null
+++ b/db/post_migrate/20210518074332_schedule_disable_expiration_policies_linked_to_no_container_images.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class ScheduleDisableExpirationPoliciesLinkedToNoContainerImages < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ BATCH_SIZE = 30_000
+ DELAY = 2.minutes.freeze
+ DOWNTIME = false
+ MIGRATION = 'DisableExpirationPoliciesLinkedToNoContainerImages'
+
+ disable_ddl_transaction!
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(
+ define_batchable_model('container_expiration_policies').where(enabled: true),
+ MIGRATION,
+ DELAY,
+ batch_size: BATCH_SIZE,
+ track_jobs: false,
+ primary_column_name: :project_id
+ )
+ end
+
+ def down
+ # this migration is irreversible
+
+ # we can't accuretaly know which policies were previously enabled during the background migration
+ end
+end
diff --git a/db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb b/db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb
new file mode 100644
index 00000000000..6cd9b1173b6
--- /dev/null
+++ b/db/post_migrate/20210519104931_backfill_clusters_integration_prometheus_enabled.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+class BackfillClustersIntegrationPrometheusEnabled < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ ApplicationRecord.connection.execute(<<~SQL.squish)
+ WITH executed_at AS (VALUES (TIMEZONE('UTC', NOW())))
+ INSERT INTO clusters_integration_prometheus(
+ cluster_id,
+ enabled,
+ encrypted_alert_manager_token,
+ encrypted_alert_manager_token_iv,
+ created_at,
+ updated_at
+ )
+ SELECT
+ cluster_id,
+ true,
+ encrypted_alert_manager_token,
+ encrypted_alert_manager_token_iv,
+ (table executed_at),
+ (table executed_at)
+ FROM clusters_applications_prometheus
+ WHERE status IN (
+ 3, /* installed */
+ 11 /* externally installed */
+ )
+ ON CONFLICT(cluster_id) DO UPDATE SET
+ enabled = true,
+ encrypted_alert_manager_token = EXCLUDED.encrypted_alert_manager_token,
+ encrypted_alert_manager_token_iv = EXCLUDED.encrypted_alert_manager_token_iv,
+ updated_at = (table executed_at)
+ SQL
+ end
+
+ def down
+ # Irreversible
+ end
+end
diff --git a/db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb b/db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb
new file mode 100644
index 00000000000..3aeabbcc0ad
--- /dev/null
+++ b/db/post_migrate/20210519132129_backfill_ci_builds_metadata_for_bigint_conversion.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class BackfillCiBuildsMetadataForBigintConversion < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ TABLE = :ci_builds_metadata
+ COLUMN = :build_id
+
+ def up
+ backfill_conversion_of_integer_to_bigint TABLE, COLUMN, batch_size: 15000, sub_batch_size: 100
+ end
+
+ def down
+ revert_backfill_conversion_of_integer_to_bigint TABLE, COLUMN
+ end
+end
diff --git a/db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb b/db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb
new file mode 100644
index 00000000000..f972815cf67
--- /dev/null
+++ b/db/post_migrate/20210519220019_backfill_escalation_policies_for_oncall_schedules.rb
@@ -0,0 +1,89 @@
+# frozen_string_literal: true
+
+class BackfillEscalationPoliciesForOncallSchedules < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ # Creates a single new escalation policy for projects which have
+ # existing on-call schedules. Only one schedule is expected
+ # per project, but it is possible to have multiple.
+ #
+ # An escalation rule is created for each existing schedule,
+ # configured to immediately notify the schedule of an incoming
+ # alert payload unless the alert has already been acknowledged.
+ # For projects with multiple schedules, the name of the first saved
+ # schedule will be used for the policy's description.
+ #
+ # Skips projects which already have escalation policies & schedules.
+ #
+ # EX)
+ # For these existing records:
+ # Project #3
+ # IncidentManagement::OncallSchedules #13
+ # project_id: 3
+ # name: 'Awesome Schedule'
+ # description: null
+ # IncidentManagement::OncallSchedules #14
+ # project_id: 3
+ # name: '2ndary sched'
+ # description: 'Backup on-call'
+ #
+ # These will be inserted:
+ # EscalationPolicy #1
+ # project_id: 3
+ # name: 'On-call Escalation Policy'
+ # description: 'Immediately notify Awesome Schedule'
+ # EscalationRule #1
+ # policy_id: 1,
+ # oncall_schedule_id: 13
+ # status: 1 # Acknowledged status
+ # elapsed_time_seconds: 0
+ # EscalationRule #2
+ # policy_id: 1,
+ # oncall_schedule_id: 14
+ # status: 1 # Acknowledged status
+ # elapsed_time_seconds: 0
+ def up
+ ApplicationRecord.connection.exec_query(<<~SQL.squish)
+ WITH new_escalation_policies AS (
+ INSERT INTO incident_management_escalation_policies (
+ project_id,
+ name,
+ description
+ )
+ SELECT
+ DISTINCT ON (project_id) project_id,
+ 'On-call Escalation Policy',
+ CONCAT('Immediately notify ', name)
+ FROM incident_management_oncall_schedules
+ WHERE project_id NOT IN (
+ SELECT DISTINCT project_id
+ FROM incident_management_escalation_policies
+ )
+ ORDER BY project_id, id
+ RETURNING id, project_id
+ )
+
+ INSERT INTO incident_management_escalation_rules (
+ policy_id,
+ oncall_schedule_id,
+ status,
+ elapsed_time_seconds
+ )
+ SELECT
+ new_escalation_policies.id,
+ incident_management_oncall_schedules.id,
+ 1,
+ 0
+ FROM new_escalation_policies
+ INNER JOIN incident_management_oncall_schedules
+ ON new_escalation_policies.project_id = incident_management_oncall_schedules.project_id
+ SQL
+ end
+
+ # There is no way to distinguish between policies created
+ # via the backfill or as a result of a user creating a new
+ # on-call schedule.
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb b/db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb
new file mode 100644
index 00000000000..d554b412420
--- /dev/null
+++ b/db/post_migrate/20210520012430_backfill_pk_conversion_for_self_managed.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+class BackfillPkConversionForSelfManaged < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ CONVERSIONS = [
+ { table: :events, columns: %i(id), sub_batch_size: 500 },
+ { table: :push_event_payloads, columns: %i(event_id), sub_batch_size: 2500, primary_key: :event_id },
+ { table: :ci_job_artifacts, columns: %i(id job_id), sub_batch_size: 2000 },
+ { table: :ci_sources_pipelines, columns: %i(source_job_id), sub_batch_size: 100 },
+ { table: :ci_build_needs, columns: %i(build_id), sub_batch_size: 1000 },
+ { table: :ci_builds, columns: %i(id stage_id), sub_batch_size: 250 },
+ { table: :ci_builds_runner_session, columns: %i(build_id), sub_batch_size: 5000 },
+ { table: :ci_build_trace_chunks, columns: %i(build_id), sub_batch_size: 1000 }
+ ]
+
+ def up
+ return unless should_run?
+
+ CONVERSIONS.each do |conversion|
+ backfill_conversion_of_integer_to_bigint(
+ conversion[:table], conversion[:columns],
+ sub_batch_size: conversion[:sub_batch_size], primary_key: conversion.fetch(:primary_key, :id)
+ )
+ end
+ end
+
+ def down
+ return unless should_run?
+
+ CONVERSIONS.each do |conversion|
+ revert_backfill_conversion_of_integer_to_bigint(
+ conversion[:table], conversion[:columns],
+ primary_key: conversion.fetch(:primary_key, :id)
+ )
+ end
+ end
+
+ private
+
+ def should_run?
+ !Gitlab.com?
+ end
+end
diff --git a/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb b/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb
new file mode 100644
index 00000000000..c380f15188a
--- /dev/null
+++ b/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanUpPendingBuildsTable < ActiveRecord::Migration[6.0]
+ include ::Gitlab::Database::DynamicModelHelpers
+
+ BATCH_SIZE = 1000
+
+ disable_ddl_transaction!
+
+ def up
+ return unless Gitlab.dev_or_test_env? || Gitlab.com?
+
+ each_batch_range('ci_pending_builds', of: BATCH_SIZE) do |min, max|
+ execute <<~SQL
+ DELETE FROM ci_pending_builds
+ USING ci_builds
+ WHERE ci_builds.id = ci_pending_builds.build_id
+ AND ci_builds.status != 'pending'
+ AND ci_builds.type = 'Ci::Build'
+ AND ci_pending_builds.id BETWEEN #{min} AND #{max}
+ SQL
+ end
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/post_migrate/20210526160133_remove_segment_selections_table.rb b/db/post_migrate/20210526160133_remove_segment_selections_table.rb
new file mode 100644
index 00000000000..02e981b40ba
--- /dev/null
+++ b/db/post_migrate/20210526160133_remove_segment_selections_table.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class RemoveSegmentSelectionsTable < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ drop_table :analytics_devops_adoption_segment_selections
+ end
+
+ def down
+ create_table :analytics_devops_adoption_segment_selections do |t|
+ t.references :segment, index: { name: 'index_on_segment_selections_segment_id' }, null: false, foreign_key: { to_table: :analytics_devops_adoption_segments, on_delete: :cascade }
+ t.bigint :group_id
+ t.bigint :project_id
+ t.index [:group_id, :segment_id], unique: true, name: 'index_on_segment_selections_group_id_segment_id'
+ t.index [:project_id, :segment_id], unique: true, name: 'index_on_segment_selections_project_id_segment_id'
+
+ t.timestamps_with_timezone
+ end
+ add_concurrent_foreign_key(:analytics_devops_adoption_segment_selections, :projects, column: :project_id, on_delete: :cascade)
+ add_concurrent_foreign_key(:analytics_devops_adoption_segment_selections, :namespaces, column: :group_id, on_delete: :cascade)
+ add_check_constraint :analytics_devops_adoption_segment_selections, '(project_id != NULL AND group_id IS NULL) OR (group_id != NULL AND project_id IS NULL)', 'segment_selection_project_id_or_group_id_required'
+ end
+end
diff --git a/db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb b/db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb
new file mode 100644
index 00000000000..8ff0e306ad5
--- /dev/null
+++ b/db/post_migrate/20210526222715_backfill_draft_status_on_merge_requests.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class BackfillDraftStatusOnMergeRequests < ActiveRecord::Migration[6.0]
+ # include Gitlab::Database::MigrationHelpers
+
+ # Marking these as no-op as the original contents caused timeouts on
+ # staging. Removing the code here per
+ # #https://docs.gitlab.com/ee/development/deleting_migrations.html#how-to-disable-a-data-migration
+ # =>
+ def up
+ # no-op
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb b/db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb
new file mode 100644
index 00000000000..6dec99c8acd
--- /dev/null
+++ b/db/post_migrate/20210527131039_clean_up_rename_experiment_subjects_group_id_to_namespace_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class CleanUpRenameExperimentSubjectsGroupIdToNamespaceId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers::V2
+
+ disable_ddl_transaction!
+
+ def up
+ cleanup_concurrent_column_rename :experiment_subjects, :group_id, :namespace_id
+ end
+
+ def down
+ undo_cleanup_concurrent_column_rename :experiment_subjects, :group_id, :namespace_id
+ end
+end
diff --git a/db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb b/db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb
new file mode 100644
index 00000000000..7aac4446c0c
--- /dev/null
+++ b/db/post_migrate/20210531054108_finalize_rename_instance_statistics_measurements.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class FinalizeRenameInstanceStatisticsMeasurements < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ def up
+ finalize_table_rename(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements)
+ end
+
+ def down
+ undo_finalize_table_rename(:analytics_instance_statistics_measurements, :analytics_usage_trends_measurements)
+ end
+end
diff --git a/db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb b/db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb
new file mode 100644
index 00000000000..85302ee1d20
--- /dev/null
+++ b/db/post_migrate/20210601073400_fix_total_stage_in_vsa.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class FixTotalStageInVsa < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ TOTAL_STAGE = 'Total'
+
+ class GroupStage < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'analytics_cycle_analytics_group_stages'
+ end
+
+ def up
+ GroupStage.reset_column_information
+
+ GroupStage.each_batch(of: 100) do |relation|
+ relation.where(name: TOTAL_STAGE, custom: false).update_all(custom: true)
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20210604070207_retry_backfill_traversal_ids.rb b/db/post_migrate/20210604070207_retry_backfill_traversal_ids.rb
new file mode 100644
index 00000000000..5e540c7f359
--- /dev/null
+++ b/db/post_migrate/20210604070207_retry_backfill_traversal_ids.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class RetryBackfillTraversalIds < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ ROOTS_MIGRATION = 'BackfillNamespaceTraversalIdsRoots'
+ CHILDREN_MIGRATION = 'BackfillNamespaceTraversalIdsChildren'
+ DOWNTIME = false
+ DELAY_INTERVAL = 2.minutes
+
+ disable_ddl_transaction!
+
+ def up
+ duration = requeue_background_migration_jobs_by_range_at_intervals(ROOTS_MIGRATION, DELAY_INTERVAL)
+ requeue_background_migration_jobs_by_range_at_intervals(CHILDREN_MIGRATION, DELAY_INTERVAL, initial_delay: duration)
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20210606143426_add_index_for_container_registry_access_level.rb b/db/post_migrate/20210606143426_add_index_for_container_registry_access_level.rb
new file mode 100644
index 00000000000..64d37054eb8
--- /dev/null
+++ b/db/post_migrate/20210606143426_add_index_for_container_registry_access_level.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class AddIndexForContainerRegistryAccessLevel < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::SchemaHelpers
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX = 'index_project_features_on_project_id_include_container_registry'
+
+ def up
+ if index_exists_by_name?('project_features', INDEX)
+ Gitlab::AppLogger.warn "Index not created because it already exists (this may be due to an aborted migration or similar): table_name: project_features, index_name: #{INDEX}"
+ return
+ end
+
+ begin
+ disable_statement_timeout do
+ execute "CREATE UNIQUE INDEX CONCURRENTLY #{INDEX} ON project_features " \
+ 'USING btree (project_id) INCLUDE (container_registry_access_level)'
+ end
+ rescue ActiveRecord::StatementInvalid => ex
+ raise "The index #{INDEX} couldn't be added: #{ex.message}"
+ end
+
+ create_comment(
+ 'INDEX',
+ INDEX,
+ 'Included column (container_registry_access_level) improves performance of the ContainerRepository.for_group_and_its_subgroups scope query'
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name('project_features', INDEX)
+ end
+end
diff --git a/db/post_migrate/20210609125005_drop_non_partitioned_web_hook_logs.rb b/db/post_migrate/20210609125005_drop_non_partitioned_web_hook_logs.rb
new file mode 100644
index 00000000000..596b643e079
--- /dev/null
+++ b/db/post_migrate/20210609125005_drop_non_partitioned_web_hook_logs.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+class DropNonPartitionedWebHookLogs < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+ include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
+
+ DOWNTIME = false
+
+ def up
+ drop_nonpartitioned_archive_table(:web_hook_logs)
+ end
+
+ def down
+ execute(<<~SQL)
+ CREATE TABLE web_hook_logs_archived (
+ id integer NOT NULL,
+ web_hook_id integer NOT NULL,
+ trigger character varying,
+ url character varying,
+ request_headers text,
+ request_data text,
+ response_headers text,
+ response_body text,
+ response_status character varying,
+ execution_duration double precision,
+ internal_error_message character varying,
+ created_at timestamp without time zone NOT NULL,
+ updated_at timestamp without time zone NOT NULL
+ );
+
+ ALTER TABLE ONLY web_hook_logs_archived ADD CONSTRAINT web_hook_logs_archived_pkey PRIMARY KEY (id);
+
+ CREATE INDEX index_web_hook_logs_on_created_at_and_web_hook_id ON web_hook_logs_archived USING btree (created_at, web_hook_id);
+ CREATE INDEX index_web_hook_logs_on_web_hook_id ON web_hook_logs_archived USING btree (web_hook_id);
+
+ ALTER TABLE ONLY web_hook_logs_archived ADD CONSTRAINT fk_rails_666826e111 FOREIGN KEY (web_hook_id) REFERENCES web_hooks(id) ON DELETE CASCADE;
+ SQL
+
+ with_lock_retries do
+ create_trigger_to_sync_tables(:web_hook_logs, :web_hook_logs_archived, 'id')
+ end
+ end
+end
diff --git a/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb b/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb
new file mode 100644
index 00000000000..f47ff244d7a
--- /dev/null
+++ b/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class MigrateProtectedAttributeToPendingBuilds < ActiveRecord::Migration[6.1]
+ include ::Gitlab::Database::DynamicModelHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ return unless Gitlab.dev_or_test_env? || Gitlab.com?
+
+ each_batch_range('ci_pending_builds', of: 1000) do |min, max|
+ execute <<~SQL
+ UPDATE ci_pending_builds
+ SET protected = true
+ FROM ci_builds
+ WHERE ci_pending_builds.build_id = ci_builds.id
+ AND ci_builds.protected = true
+ AND ci_pending_builds.id BETWEEN #{min} AND #{max}
+ SQL
+ end
+ end
+
+ def down
+ # no op
+ end
+end
diff --git a/db/post_migrate/20210610113229_add_index_to_protected_pending_builds.rb b/db/post_migrate/20210610113229_add_index_to_protected_pending_builds.rb
new file mode 100644
index 00000000000..140bf7df4e6
--- /dev/null
+++ b/db/post_migrate/20210610113229_add_index_to_protected_pending_builds.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToProtectedPendingBuilds < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_ci_pending_builds_id_on_protected_partial'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :ci_pending_builds, :id, where: 'protected = true', name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :ci_pending_builds, INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20210610141711_disable_expiration_policies_linked_to_no_container_images.rb b/db/post_migrate/20210610141711_disable_expiration_policies_linked_to_no_container_images.rb
new file mode 100644
index 00000000000..f4827c0bbc0
--- /dev/null
+++ b/db/post_migrate/20210610141711_disable_expiration_policies_linked_to_no_container_images.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class DisableExpirationPoliciesLinkedToNoContainerImages < ActiveRecord::Migration[6.1]
+ disable_ddl_transaction!
+
+ BATCH_SIZE = 1000
+
+ class ContainerExpirationPolicy < ActiveRecord::Base
+ include ::EachBatch
+ self.table_name = 'container_expiration_policies'
+ end
+
+ def up
+ ContainerExpirationPolicy.where(enabled: true).each_batch(of: BATCH_SIZE) do |batch, _|
+ sql = <<-SQL
+ WITH batched_relation AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported} (#{batch.limit(BATCH_SIZE).to_sql})
+ UPDATE container_expiration_policies
+ SET enabled = FALSE
+ FROM batched_relation
+ WHERE container_expiration_policies.project_id = batched_relation.project_id
+ AND NOT EXISTS (SELECT 1 FROM "container_repositories" WHERE container_repositories.project_id = container_expiration_policies.project_id)
+ SQL
+ execute(sql)
+ end
+ end
+
+ def down
+ # no-op
+
+ # we can't accuretaly know which policies were previously enabled during `#up`
+ end
+end
diff --git a/db/post_migrate/20210611080951_fix_missing_traversal_ids.rb b/db/post_migrate/20210611080951_fix_missing_traversal_ids.rb
new file mode 100644
index 00000000000..45728ef26f5
--- /dev/null
+++ b/db/post_migrate/20210611080951_fix_missing_traversal_ids.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+class FixMissingTraversalIds < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ ROOTS_MIGRATION = 'BackfillNamespaceTraversalIdsRoots'
+ CHILDREN_MIGRATION = 'BackfillNamespaceTraversalIdsChildren'
+ DOWNTIME = false
+ BATCH_SIZE = 1_000
+ SUB_BATCH_SIZE = 50
+ DELAY_INTERVAL = 2.minutes
+ ROOT_NS_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_root_namespaces'
+ CHILD_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_child_namespaces'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :namespaces, :id, where: "parent_id IS NULL AND traversal_ids = '{}'", name: ROOT_NS_INDEX_NAME
+ add_concurrent_index :namespaces, :id, where: "parent_id IS NOT NULL AND traversal_ids = '{}'", name: CHILD_INDEX_NAME
+
+ # Personal namespaces and top-level groups
+ final_delay = queue_background_migration_jobs_by_range_at_intervals(
+ ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsRoots::Namespace.base_query.where("traversal_ids = '{}'"),
+ ROOTS_MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ other_job_arguments: [SUB_BATCH_SIZE],
+ track_jobs: true
+ )
+ final_delay += DELAY_INTERVAL
+
+ # Subgroups
+ queue_background_migration_jobs_by_range_at_intervals(
+ ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsChildren::Namespace.base_query.where("traversal_ids = '{}'"),
+ CHILDREN_MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE,
+ initial_delay: final_delay,
+ other_job_arguments: [SUB_BATCH_SIZE],
+ track_jobs: true
+ )
+ end
+
+ def down
+ remove_concurrent_index_by_name :namespaces, ROOT_NS_INDEX_NAME
+ remove_concurrent_index_by_name :namespaces, CHILD_INDEX_NAME
+ end
+end