Commit 38aeeece authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '28781-migrate-pages-metadata-in-background' into 'master'

Schedule background migration to populate pages metadata

See merge request gitlab-org/gitlab!17993
parents bed487d1 748829de
---
title: Schedule background migration to populate pages metadata
merge_request: 17993
author:
type: added
# frozen_string_literal: true
class SchedulePagesMetadataMigration < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
BATCH_SIZE = 10_000
MIGRATION = 'MigratePagesMetadata'
disable_ddl_transaction!
class Project < ActiveRecord::Base
include ::EachBatch
self.table_name = 'projects'
end
def up
say "Scheduling `#{MIGRATION}` jobs"
# At the time of writing there are ~10_669_292 records to be inserted for GitLab.com,
# batches of 10_000 with delay interval of 2 minutes gives us an estimate of close to 36 hours.
queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, 2.minutes, batch_size: BATCH_SIZE)
end
def down
# no-op
end
end
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20191002031332_schedule_pages_metadata_migration')
describe SchedulePagesMetadataMigration, :migration, :sidekiq do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
before do
stub_const("#{described_class.name}::BATCH_SIZE", 1)
namespaces.create!(id: 11, name: 'gitlab', path: 'gitlab-org')
projects.create!(id: 111, namespace_id: 11, name: 'Project 111')
projects.create!(id: 114, namespace_id: 11, name: 'Project 114')
end
it 'schedules pages metadata migration' do
Sidekiq::Testing.fake! do
Timecop.freeze do
migrate!
expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 111, 111)
expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, 114, 114)
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
end
end
end
end
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