diff --git a/changelogs/unreleased/18792-reschedule-background-migration.yml b/changelogs/unreleased/18792-reschedule-background-migration.yml new file mode 100644 index 0000000000000000000000000000000000000000..044a362ffc1eae44f274a0aa8f46040f801d8c61 --- /dev/null +++ b/changelogs/unreleased/18792-reschedule-background-migration.yml @@ -0,0 +1,6 @@ +--- +title: Reschedule background migration to copy projects.container_registry_enabled + to project_features.container_registry_access_level +merge_request: 58360 +author: +type: added 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 index 7bc7a0e49f7e98eca9de0e64273dded22a845504..fce311108660eb7bd26bbe4deee8c3dc6042ce76 100644 --- 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 @@ -16,7 +16,10 @@ class Project < ActiveRecord::Base end def up - queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE) + # 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 diff --git a/db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb b/db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb new file mode 100644 index 0000000000000000000000000000000000000000..6e3f7ae34d142cd105f33718e9fa76081b90807c --- /dev/null +++ b/db/post_migrate/20210401131948_move_container_registry_enabled_to_project_features2.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class MoveContainerRegistryEnabledToProjectFeatures2 < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + BATCH_SIZE = 21_000 + MIGRATION = 'MoveContainerRegistryEnabledToProjectFeature' + + disable_ddl_transaction! + + class Project < ActiveRecord::Base + include EachBatch + self.table_name = 'projects' + end + + def up + delete_queued_jobs('MoveContainerRegistryEnabledToProjectFeature') + + queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE, track_jobs: true) + end + + def down + # no-op + end +end diff --git a/db/schema_migrations/20210401131948 b/db/schema_migrations/20210401131948 new file mode 100644 index 0000000000000000000000000000000000000000..8b9950cd32c0bf36d00c54784471cc95ea94c8dd --- /dev/null +++ b/db/schema_migrations/20210401131948 @@ -0,0 +1 @@ +cbc1cd66cdbe08ac9edee14da255343acdcd8adaea6748ee82980462ae4bb88f \ No newline at end of file diff --git a/lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb b/lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb index 4eaef26c9c67f7721cd9fc689afcd96234d61e3d..9ecf53317d0a8771407dfcd56b45fe458e5cc33b 100644 --- a/lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb +++ b/lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb @@ -6,7 +6,7 @@ module BackgroundMigration # project_features.container_registry_access_level for the projects within # the given range of ids. class MoveContainerRegistryEnabledToProjectFeature - MAX_BATCH_SIZE = 1_000 + MAX_BATCH_SIZE = 300 module Migratable # Migration model namespace isolated from application code. diff --git a/spec/migrations/move_container_registry_enabled_to_project_features_spec.rb b/spec/migrations/move_container_registry_enabled_to_project_features2_spec.rb similarity index 75% rename from spec/migrations/move_container_registry_enabled_to_project_features_spec.rb rename to spec/migrations/move_container_registry_enabled_to_project_features2_spec.rb index c7b07f3ef37b5504f38dfadbbbca9ff2f2568266..11d43a36bc90270d5fe02bad34efaeb268c6959c 100644 --- a/spec/migrations/move_container_registry_enabled_to_project_features_spec.rb +++ b/spec/migrations/move_container_registry_enabled_to_project_features2_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'spec_helper' -require Rails.root.join('db', 'post_migrate', '20210226120851_move_container_registry_enabled_to_project_features.rb') +require Rails.root.join('db', 'post_migrate', '20210401131948_move_container_registry_enabled_to_project_features2.rb') -RSpec.describe MoveContainerRegistryEnabledToProjectFeatures, :migration do +RSpec.describe MoveContainerRegistryEnabledToProjectFeatures2, :migration do let(:namespace) { table(:namespaces).create!(name: 'gitlab', path: 'gitlab-org') } let!(:projects) do @@ -30,6 +30,10 @@ it 'schedules jobs for ranges of projects' do migrate! + # Since track_jobs is true, each job should have an entry in the background_migration_jobs + # table. + expect(table(:background_migration_jobs).count).to eq(2) + expect(described_class::MIGRATION) .to be_scheduled_delayed_migration(2.minutes, projects[0].id, projects[2].id)