Commit daa1c701 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Port rename of artifacts_* to legacy_artifacts_* to EE

parent 2ef226b8
......@@ -45,7 +45,7 @@ module Ci
end
scope :with_artifacts_not_expired, ->() { with_artifacts.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }
scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :with_artifacts_stored_locally, ->() { with_artifacts.where(artifacts_file_store: [nil, ArtifactUploader::LOCAL_STORE]) }
scope :with_artifacts_stored_locally, ->() { with_artifacts.where(artifacts_file_store: [nil, LegacyArtifactUploader::LOCAL_STORE]) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) }
scope :ref_protected, -> { where(protected: true) }
......
......@@ -38,13 +38,6 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
end
end
attr_reader :subject, :field
def initialize(subject, field)
@subject = subject
@field = field
end
def file_storage?
storage.is_a?(CarrierWave::Storage::File)
end
......@@ -54,7 +47,7 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
end
def real_object_store
subject.public_send(:"#{field}_store") # rubocop:disable GitlabSecurity/PublicSend
model.public_send(store_serialization_column) # rubocop:disable GitlabSecurity/PublicSend
end
def object_store
......@@ -63,7 +56,7 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
def object_store=(value)
@storage = nil
subject.public_send(:"#{field}_store=", value) # rubocop:disable GitlabSecurity/PublicSend
model.public_send(:"#{store_serialization_column}=", value) # rubocop:disable GitlabSecurity/PublicSend
end
def store_dir
......@@ -111,7 +104,7 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
# since we change storage store the new storage
# in case of failure delete new file
begin
subject.save!
model.save!
rescue => e
new_file.delete
self.object_store = old_store
......@@ -125,7 +118,7 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
def schedule_migration_to_object_storage(new_file)
if self.class.object_store_enabled? && licensed? && file_storage?
ObjectStorageUploadWorker.perform_async(self.class.name, subject.class.name, field, subject.id)
ObjectStorageUploadWorker.perform_async(self.class.name, model.class.name, mounted_as, model.id)
end
end
......@@ -194,6 +187,14 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
raise NotImplementedError
end
def serialization_column
model.class.uploader_option(mounted_as, :mount_on) || mounted_as
end
def store_serialization_column
:"#{serialization_column}_store"
end
def storage
@storage ||=
if object_store == REMOTE_STORE
......
......@@ -149,7 +149,7 @@ describe Projects::ArtifactsController do
context 'when using local file storage' do
it_behaves_like 'a valid file' do
let(:store) { ObjectStoreUploader::LOCAL_STORE }
let(:archive_path) { ArtifactUploader.local_store_path }
let(:archive_path) { LegacyArtifactUploader.local_store_path }
end
end
......
......@@ -163,7 +163,7 @@ describe Ci::Build do
context 'artifacts metadata does not exist' do
before do
build.update_attributes(artifacts_metadata: nil)
build.update_attributes(legacy_artifacts_metadata: nil)
end
it { is_expected.to be_falsy }
......
......@@ -5,7 +5,7 @@ describe 'gitlab:artifacts namespace rake task' do
Rake.application.rake_require 'tasks/gitlab/artifacts'
end
let(:object_storage_enabled) { false }
let(:object_storage_enabled) { false }
before do
stub_artifacts_object_storage(enabled: object_storage_enabled)
......@@ -15,38 +15,14 @@ describe 'gitlab:artifacts namespace rake task' do
context 'legacy artifacts' do
describe 'migrate' do
let(:build) { create(:ci_build, artifacts_file_store: store, artifacts_metadata_store: store) }
before do
# Mock the legacy way of artifacts
path = Rails.root.join(ArtifactUploader.local_store_path,
build.created_at.utc.strftime('%Y_%m'),
build.project_id.to_s,
build.id.to_s)
FileUtils.mkdir_p(path)
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts.zip'),
File.join(path, "ci_build_artifacts.zip"))
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'),
File.join(path, "ci_build_artifacts_metadata.gz"))
build.update_columns(
artifacts_file: 'ci_build_artifacts.zip',
artifacts_metadata: 'ci_build_artifacts_metadata.gz')
end
let!(:build) { create(:ci_build, :legacy_artifacts, artifacts_file_store: store, artifacts_metadata_store: store) }
context 'when local storage is used' do
let(:store) { ObjectStoreUploader::LOCAL_STORE }
context 'and job does not have file store defined' do
let(:object_storage_enabled) { true }
before do
build.update(artifacts_file_store: nil)
end
let(:store) { nil }
it "migrates file to remote storage" do
subject
......
......@@ -49,33 +49,12 @@ describe ObjectStorageUploadWorker do
end
context 'for legacy artifacts' do
let(:build) { create(:ci_build) }
let(:uploader_class) { ArtifactUploader }
let(:build) { create(:ci_build, :legacy_artifacts) }
let(:uploader_class) { LegacyArtifactUploader }
let(:subject_class) { Ci::Build }
let(:file_field) { :artifacts_file }
let(:subject_id) { build.id }
before do
# Mock the legacy way of artifacts
path = Rails.root.join(uploader_class.local_store_path,
build.created_at.utc.strftime('%Y_%m'),
build.project_id.to_s,
build.id.to_s)
FileUtils.mkdir_p(path)
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts.zip'),
File.join(path, "ci_build_artifacts.zip"))
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'),
File.join(path, "ci_build_artifacts_metadata.gz"))
build.update_columns(
artifacts_file: 'ci_build_artifacts.zip',
artifacts_metadata: 'ci_build_artifacts_metadata.gz')
end
context 'when local storage is used' do
let(:store) { local }
......
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