Commit 0a37ccf8 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch...

Merge branch '240938-schedulecalculatewikisizes-when-missing-wiki-sizes-exist-calculates-missing-wiki-sizes' into 'master'

Fix a broken background migration spec due to a missing column

Closes #240938

See merge request gitlab-org/gitlab!40290
parents 6519954c e92a940d
...@@ -80,11 +80,15 @@ class ProjectStatistics < ApplicationRecord ...@@ -80,11 +80,15 @@ 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 + pipeline_artifacts_size storage_size = repository_size + wiki_size + lfs_objects_size + build_artifacts_size + packages_size
# The `snippets_size` column was added on 20200622095419 but db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb # The `snippets_size` column was added on 20200622095419 but db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb
# might try to update project statistics before the `snippets_size` column has been created. # might try to update project statistics before the `snippets_size` column has been created.
storage_size += snippets_size if self.class.column_names.include?('snippets_size') storage_size += snippets_size if self.class.column_names.include?('snippets_size')
# The `pipeline_artifacts_size` column was added on 20200817142800 but db/post_migrate/20190527194900_schedule_calculate_wiki_sizes.rb
# might try to update project statistics before the `pipeline_artifacts_size` column has been created.
storage_size += pipeline_artifacts_size if self.class.column_names.include?('pipeline_artifacts_size')
self.storage_size = storage_size self.storage_size = storage_size
end end
......
...@@ -16,9 +16,9 @@ RSpec.describe ScheduleCalculateWikiSizes do ...@@ -16,9 +16,9 @@ RSpec.describe ScheduleCalculateWikiSizes do
let(:project3) { projects.create!(name: 'wiki-project-3', path: 'wiki-project-3', 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 context 'when missing wiki sizes exist' do
let!(:project_statistic1) { project_statistics.create!(id: 1, project_id: project1.id, namespace_id: namespace.id, wiki_size: 1000) } let!(:project_statistic1) { project_statistics.create!(project_id: project1.id, namespace_id: namespace.id, wiki_size: 1000) }
let!(:project_statistic2) { project_statistics.create!(id: 2, project_id: project2.id, namespace_id: namespace.id, wiki_size: nil) } let!(:project_statistic2) { project_statistics.create!(project_id: project2.id, namespace_id: namespace.id, wiki_size: nil) }
let!(:project_statistic3) { project_statistics.create!(id: 3, project_id: project3.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 it 'schedules a background migration' do
Timecop.freeze do Timecop.freeze do
...@@ -44,7 +44,7 @@ RSpec.describe ScheduleCalculateWikiSizes do ...@@ -44,7 +44,7 @@ RSpec.describe ScheduleCalculateWikiSizes do
before do before do
namespace = namespaces.create!(name: 'wiki-migration', path: 'wiki-migration') 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 = projects.create!(name: 'wiki-project-1', path: 'wiki-project-1', namespace_id: namespace.id)
project_statistics.create!(project_id: project.id, namespace_id: 1, wiki_size: 1000) project_statistics.create!(project_id: project.id, namespace_id: namespace.id, wiki_size: 1000)
end end
it 'does not schedule a background migration' do it 'does not schedule a background migration' do
......
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