Commit d6caf0eb authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '348929-remove-unneeded-column-artifacts_archive_id' into 'master'

Ignoring the no longer needed column `project_pages_metadata.artifacts_archive_id`

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