Commit e9834785 authored by Omar Qunsul's avatar Omar Qunsul

Ignoring the column `project_pages_metadata.artifacts_archive_id`

Preparing to remove the column. This is the first step to remove the
column later.

https://gitlab.com/gitlab-org/gitlab/-/issues/348929
parent 22f8f1a8
......@@ -1926,12 +1926,12 @@ class Project < ApplicationRecord
.delete_all
end
def mark_pages_as_deployed(artifacts_archive: nil)
ensure_pages_metadatum.update!(deployed: true, artifacts_archive: artifacts_archive)
def mark_pages_as_deployed
ensure_pages_metadatum.update!(deployed: true)
end
def mark_pages_as_not_deployed
ensure_pages_metadatum.update!(deployed: false, artifacts_archive: nil, pages_deployment: nil)
ensure_pages_metadatum.update!(deployed: false)
end
def update_pages_deployment!(deployment)
......
......@@ -4,11 +4,13 @@ class ProjectPagesMetadatum < ApplicationRecord
extend SuppressCompositePrimaryKeyWarning
include EachBatch
include IgnorableColumns
self.primary_key = :project_id
ignore_columns :artifacts_archive_id, remove_with: '15.0', remove_after: '2022-04-22'
belongs_to :project, inverse_of: :pages_metadatum
belongs_to :artifacts_archive, class_name: 'Ci::JobArtifact'
belongs_to :pages_deployment
scope :deployed, -> { where(deployed: true) }
......
......@@ -22,8 +22,8 @@ module Projects
register_attempt
# Create status notifying the deployment of pages
@status = build_commit_status
::Ci::Pipelines::AddJobService.new(@build.pipeline).execute!(@status) do |job|
@commit_status = build_commit_status
::Ci::Pipelines::AddJobService.new(@build.pipeline).execute!(@commit_status) do |job|
job.enqueue!
job.run!
end
......@@ -46,17 +46,17 @@ module Projects
private
def success
@status.success
@project.mark_pages_as_deployed(artifacts_archive: build.job_artifacts_archive)
@commit_status.success
@project.mark_pages_as_deployed
super
end
def error(message)
register_failure
log_error("Projects::UpdatePagesService: #{message}")
@status.allow_failure = !latest?
@status.description = message
@status.drop(:script_failure)
@commit_status.allow_failure = !latest?
@commit_status.description = message
@commit_status.drop(:script_failure)
super
end
......
......@@ -18,15 +18,4 @@ RSpec.describe ProjectPagesMetadatum do
expect(described_class.only_on_legacy_storage).to eq([legacy_storage_project.pages_metadatum])
end
end
it_behaves_like 'cleanup by a loose foreign key' do
let!(:model) do
artifacts_archive = create(:ci_job_artifact, :legacy_archive)
metadatum = artifacts_archive.project.pages_metadatum
metadatum.artifacts_archive = artifacts_archive
metadatum
end
let!(:parent) { model.artifacts_archive }
end
end
......@@ -6559,7 +6559,6 @@ RSpec.describe Project, factory_default: :keep do
describe '#mark_pages_as_deployed' do
let(:project) { create(:project) }
let(:artifacts_archive) { create(:ci_job_artifact, project: project) }
it "works when artifacts_archive is missing" do
project.mark_pages_as_deployed
......@@ -6571,7 +6570,7 @@ RSpec.describe Project, factory_default: :keep do
project.pages_metadatum.destroy!
project.reload
project.mark_pages_as_deployed(artifacts_archive: artifacts_archive)
project.mark_pages_as_deployed
expect(project.pages_metadatum.reload.deployed).to eq(true)
end
......@@ -6581,15 +6580,13 @@ RSpec.describe Project, factory_default: :keep do
pages_metadatum.update!(deployed: false)
expect do
project.mark_pages_as_deployed(artifacts_archive: artifacts_archive)
project.mark_pages_as_deployed
end.to change { pages_metadatum.reload.deployed }.from(false).to(true)
.and change { pages_metadatum.reload.artifacts_archive }.from(nil).to(artifacts_archive)
end
end
describe '#mark_pages_as_not_deployed' do
let(:project) { create(:project) }
let(:artifacts_archive) { create(:ci_job_artifact, project: project) }
it "creates new record and sets deployed to false if none exists yet" do
project.pages_metadatum.destroy!
......@@ -6602,12 +6599,11 @@ RSpec.describe Project, factory_default: :keep do
it "updates the existing record and sets deployed to false and clears artifacts_archive" do
pages_metadatum = project.pages_metadatum
pages_metadatum.update!(deployed: true, artifacts_archive: artifacts_archive)
pages_metadatum.update!(deployed: true)
expect do
project.mark_pages_as_not_deployed
end.to change { pages_metadatum.reload.deployed }.from(true).to(false)
.and change { pages_metadatum.reload.artifacts_archive }.from(artifacts_archive).to(nil)
end
end
......
......@@ -39,7 +39,6 @@ RSpec.describe Projects::UpdatePagesService do
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
expect(project.pages_metadatum).to be_deployed
expect(project.pages_metadatum.artifacts_archive).to eq(artifacts_archive)
expect(project.pages_deployed?).to be_truthy
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