Commit 748829de authored by Krasimir Angelov's avatar Krasimir Angelov

Schedule background migration to populate pages metadata

Call MigratePagesMetadata for batches of projects to populate
`project_pages_metadata` table.

Related to https://gitlab.com/gitlab-org/gitlab/issues/28781.
parent 82bf296b
---
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