Commit c0c48ea7 authored by Reuben Pereira's avatar Reuben Pereira

Reschedule background migration to copy container_registry_enabled

The previous background migration missed 10 jobs, so this time we
will be tracking the jobs by passing in the track_jobs: true
parameter.
parent c9b65766
---
title: Reschedule background migration to copy projects.container_registry_enabled
to project_features.container_registry_access_level
merge_request: 58360
author:
type: added
...@@ -16,7 +16,10 @@ class MoveContainerRegistryEnabledToProjectFeatures < ActiveRecord::Migration[6. ...@@ -16,7 +16,10 @@ class MoveContainerRegistryEnabledToProjectFeatures < ActiveRecord::Migration[6.
end end
def up 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 end
def down def down
......
# 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
cbc1cd66cdbe08ac9edee14da255343acdcd8adaea6748ee82980462ae4bb88f
\ No newline at end of file
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
# project_features.container_registry_access_level for the projects within # project_features.container_registry_access_level for the projects within
# the given range of ids. # the given range of ids.
class MoveContainerRegistryEnabledToProjectFeature class MoveContainerRegistryEnabledToProjectFeature
MAX_BATCH_SIZE = 1_000 MAX_BATCH_SIZE = 300
module Migratable module Migratable
# Migration model namespace isolated from application code. # Migration model namespace isolated from application code.
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' 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(:namespace) { table(:namespaces).create!(name: 'gitlab', path: 'gitlab-org') }
let!(:projects) do let!(:projects) do
...@@ -30,6 +30,10 @@ RSpec.describe MoveContainerRegistryEnabledToProjectFeatures, :migration do ...@@ -30,6 +30,10 @@ RSpec.describe MoveContainerRegistryEnabledToProjectFeatures, :migration do
it 'schedules jobs for ranges of projects' do it 'schedules jobs for ranges of projects' do
migrate! 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) expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(2.minutes, projects[0].id, projects[2].id) .to be_scheduled_delayed_migration(2.minutes, projects[0].id, projects[2].id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment