Commit 654cb525 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '240962-fj-disable-wiki-size-calc-migration' into 'master'

Disable ScheduleCalculateWikiSizes migration and remove technical debt

See merge request gitlab-org/gitlab!61991
parents 23577fbc f8576036
...@@ -94,18 +94,14 @@ class ProjectStatistics < ApplicationRecord ...@@ -94,18 +94,14 @@ class ProjectStatistics < ApplicationRecord
end end
def update_storage_size def update_storage_size
storage_size = repository_size + wiki_size + lfs_objects_size + build_artifacts_size + packages_size storage_size = repository_size +
# The `snippets_size` column was added on 20200622095419 but db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb wiki_size +
# might try to update project statistics before the `snippets_size` column has been created. lfs_objects_size +
storage_size += snippets_size if self.class.column_names.include?('snippets_size') build_artifacts_size +
packages_size +
# The `pipeline_artifacts_size` column was added on 20200817142800 but db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb snippets_size +
# might try to update project statistics before the `pipeline_artifacts_size` column has been created. pipeline_artifacts_size +
storage_size += pipeline_artifacts_size if self.class.column_names.include?('pipeline_artifacts_size') uploads_size
# The `uploads_size` column was added on 20201105021637 but db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb
# might try to update project statistics before the `uploads_size` column has been created.
storage_size += uploads_size if self.class.column_names.include?('uploads_size')
self.storage_size = storage_size self.storage_size = storage_size
end end
......
...@@ -18,12 +18,12 @@ class ScheduleCalculateWikiSizes < ActiveRecord::Migration[5.0] ...@@ -18,12 +18,12 @@ class ScheduleCalculateWikiSizes < ActiveRecord::Migration[5.0]
disable_ddl_transaction! 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 def up
queue_background_migration_jobs_by_range_at_intervals( # no-op
::ScheduleCalculateWikiSizes::ProjectStatistics.without_wiki_size,
MIGRATION,
BATCH_TIME,
batch_size: BATCH_SIZE)
end end
def down def down
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20190527194900_schedule_calculate_wiki_sizes.rb')
RSpec.describe ScheduleCalculateWikiSizes do
let(:migration_class) { Gitlab::BackgroundMigration::CalculateWikiSizes }
let(:migration_name) { migration_class.to_s.demodulize }
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:project_statistics) { table(:project_statistics) }
let(:namespace) { namespaces.create!(name: 'wiki-migration', path: 'wiki-migration') }
let(:project1) { projects.create!(name: 'wiki-project-1', path: 'wiki-project-1', namespace_id: namespace.id) }
let(:project2) { projects.create!(name: 'wiki-project-2', path: 'wiki-project-2', namespace_id: namespace.id) }
let(:project3) { projects.create!(name: 'wiki-project-3', path: 'wiki-project-3', namespace_id: namespace.id) }
context 'when missing wiki sizes exist' do
let!(:project_statistic1) { project_statistics.create!(project_id: project1.id, namespace_id: namespace.id, wiki_size: 1000) }
let!(:project_statistic2) { project_statistics.create!(project_id: project2.id, namespace_id: namespace.id, wiki_size: nil) }
let!(:project_statistic3) { project_statistics.create!(project_id: project3.id, namespace_id: namespace.id, wiki_size: nil) }
it 'schedules a background migration' do
freeze_time do
migrate!
expect(migration_name).to be_scheduled_delayed_migration(5.minutes, project_statistic2.id, project_statistic3.id)
expect(BackgroundMigrationWorker.jobs.size).to eq 1
end
end
it 'calculates missing wiki sizes', :sidekiq_inline do
expect(project_statistic2.wiki_size).to be_nil
expect(project_statistic3.wiki_size).to be_nil
migrate!
expect(project_statistic2.reload.wiki_size).not_to be_nil
expect(project_statistic3.reload.wiki_size).not_to be_nil
end
end
context 'when missing wiki sizes do not exist' do
before do
namespace = namespaces.create!(name: 'wiki-migration', path: 'wiki-migration')
project = projects.create!(name: 'wiki-project-1', path: 'wiki-project-1', namespace_id: namespace.id)
project_statistics.create!(project_id: project.id, namespace_id: namespace.id, wiki_size: 1000)
end
it 'does not schedule a background migration' do
Sidekiq::Testing.fake! do
freeze_time do
migrate!
expect(BackgroundMigrationWorker.jobs.size).to eq 0
end
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