Commit ab02bd69 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Use `job_artifacts_archive|metadata`

parent 8f01e679
......@@ -16,8 +16,8 @@ module Ci
has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_one :job_archive, -> () { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id
has_one :job_metadata, -> () { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id
has_one :job_artifacts_archive, -> () { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id
has_one :job_artifacts_metadata, -> () { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id
# The "environment" field for builds is a String, and is the unexpanded name
def persisted_environment
......
......@@ -3,11 +3,11 @@
# Meant to be prepended so the interface can stay the same
module ArtifactMigratable
def artifacts_file
job_archive&.file || legacy_artifacts_file
job_artifacts_archive&.file || legacy_artifacts_file
end
def artifacts_metadata
job_metadata&.file || legacy_artifacts_metadata
job_artifacts_metadata&.file || legacy_artifacts_metadata
end
def artifacts?
......@@ -19,20 +19,20 @@ module ArtifactMigratable
end
def artifacts_file_changed?
job_archive&.file_changed? || attribute_changed?(:artifacts_file)
job_artifacts_archive&.file_changed? || attribute_changed?(:artifacts_file)
end
def remove_artifacts_file!
if job_archive
job_archive.destroy
if job_artifacts_archive
job_artifacts_archive.destroy
else
remove_legacy_artifacts_file!
end
end
def remove_artifacts_metadata!
if job_metadata
job_metadata.destroy
if job_artifacts_metadata
job_artifacts_metadata.destroy
else
remove_legacy_artifacts_metadata!
end
......@@ -40,6 +40,6 @@ module ArtifactMigratable
def artifacts_size
read_attribute(:artifacts_size).to_i +
job_archive&.size.to_i + job_metadata&.size.to_i
job_artifacts_archive&.size.to_i + job_artifacts_metadata&.size.to_i
end
end
......@@ -17,7 +17,7 @@ describe Ci::RetryBuildService do
%i[id status user token coverage trace runner artifacts_expire_at
artifacts_file artifacts_metadata artifacts_size created_at
updated_at started_at finished_at queued_at erased_by
erased_at auto_canceled_by job_artifacts job_archive job_metadata].freeze
erased_at auto_canceled_by job_artifacts job_artifacts_archive job_artifacts_metadata].freeze
IGNORE_ACCESSORS =
%i[type lock_version target_url base_tags trace_sections
......
......@@ -155,7 +155,7 @@ describe Projects::UpdatePagesService do
end
it 'fails for empty file fails' do
build.job_archive.update_attributes(file: empty_file)
build.job_artifacts_archive.update_attributes(file: empty_file)
expect(execute).not_to eq(:success)
end
......
......@@ -23,7 +23,7 @@ describe ExpireBuildInstanceArtifactsWorker do
end
it 'does remove the job artifact record' do
expect(build.reload.job_archive).to be_nil
expect(build.reload.job_artifacts_archive).to be_nil
end
end
end
......@@ -42,7 +42,7 @@ describe ExpireBuildInstanceArtifactsWorker do
end
it 'does not remove the job artifact record' do
expect(build.reload.job_archive).not_to be_nil
expect(build.reload.job_artifacts_archive).not_to be_nil
end
end
......@@ -58,7 +58,7 @@ describe ExpireBuildInstanceArtifactsWorker do
end
it 'does not remove the job artifact record' do
expect(build.reload.job_archive).not_to be_nil
expect(build.reload.job_artifacts_archive).not_to be_nil
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