Commit 75f58060 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Ensure that pages metadata exists when updating it

This fix is a bit paranoid: pages_metadata was added in 12.*
and created via background migration.

Now it should exists for every project. (this is true for .com)

But if users just upgrade to 13.* after a long wait,
then background migration may still be in-progress, so we want
to ensure that metadata exist before we update it with
deployment_id
parent 66ad4f19
......@@ -1823,6 +1823,10 @@ class Project < ApplicationRecord
ensure_pages_metadatum.update!(deployed: false, artifacts_archive: nil, pages_deployment: nil)
end
def update_pages_deployment!(deployment)
ensure_pages_metadatum.update!(pages_deployment: deployment)
end
def write_repository_config(gl_full_path: full_path)
# We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using
......
......@@ -138,7 +138,7 @@ module Projects
deployment = project.pages_deployments.create!(file: file,
file_count: entries_count,
file_sha256: sha256)
project.pages_metadatum.update!(pages_deployment: deployment)
project.update_pages_deployment!(deployment)
end
DestroyPagesDeploymentsWorker.perform_in(
......
......@@ -5927,6 +5927,26 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '#update_pages_deployment!' do
let(:project) { create(:project) }
let(:deployment) { create(:pages_deployment, project: project) }
it "creates new metadata record if none exists yet and sets deployment" do
project.pages_metadatum.destroy!
project.reload
project.update_pages_deployment!(deployment)
expect(project.pages_metadatum.pages_deployment).to eq(deployment)
end
it "updates the existing metadara record with deployment" do
expect do
project.update_pages_deployment!(deployment)
end.to change { project.pages_metadatum.reload.pages_deployment }.from(nil).to(deployment)
end
end
describe '#has_pool_repsitory?' do
it 'returns false when it does not have a pool repository' do
subject = create(:project, :repository)
......
......@@ -71,6 +71,17 @@ RSpec.describe Projects::UpdatePagesService do
expect(project.pages_metadatum.reload.pages_deployment_id).to eq(deployment.id)
end
it 'does not fail if pages_metadata is absent' do
project.pages_metadatum.destroy!
project.reload
expect do
expect(execute).to eq(:success)
end.to change { project.pages_deployments.count }.by(1)
expect(project.pages_metadatum.reload.pages_deployment).to eq(project.pages_deployments.last)
end
context 'when there is an old pages deployment' do
let!(:old_deployment_from_another_project) { create(:pages_deployment) }
let!(:old_deployment) { create(:pages_deployment, project: project) }
......
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