Commit fdf156fa authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'geo-split-file-registry' into 'master'

Geo: Create separate models for different registries

See merge request gitlab-org/gitlab-ee!9755
parents dfa450bc 67cf8846
...@@ -5,4 +5,14 @@ class Geo::FileRegistry < Geo::BaseRegistry ...@@ -5,4 +5,14 @@ class Geo::FileRegistry < Geo::BaseRegistry
scope :lfs_objects, -> { where(file_type: :lfs) } scope :lfs_objects, -> { where(file_type: :lfs) }
scope :attachments, -> { where(file_type: Geo::FileService::DEFAULT_OBJECT_TYPES) } scope :attachments, -> { where(file_type: Geo::FileService::DEFAULT_OBJECT_TYPES) }
self.inheritance_column = 'file_type'
def self.find_sti_class(file_type)
if file_type == 'lfs'
Geo::LfsObjectRegistry
elsif Geo::FileService::DEFAULT_OBJECT_TYPES.include?(file_type.to_sym)
Geo::UploadRegistry
end
end
end end
# frozen_string_literal: true
class Geo::LfsObjectRegistry < Geo::FileRegistry
belongs_to :lfs_object, foreign_key: :file_id, class_name: 'LfsObject'
def self.sti_name
'lfs'
end
end
# frozen_string_literal: true
class Geo::UploadRegistry < Geo::FileRegistry
belongs_to :upload, foreign_key: :file_id
if Rails.gem_version >= Gem::Version.new('6.0')
raise '.type_condition was changed in Rails 6.0, please adapt this code accordingly'
# see https://github.com/rails/rails/commit/6a1a1e66ea7a917942bd8369fa8dbfedce391dab
end
def self.type_condition(table = arel_table)
sti_column = arel_attribute(inheritance_column, table)
sti_names = Geo::FileService::DEFAULT_OBJECT_TYPES
sti_column.in(sti_names)
end
end
---
title: "Geo: Create separate models for different registries"
merge_request: 9755
author:
type: added
...@@ -6,13 +6,13 @@ describe Geo::FileRegistry do ...@@ -6,13 +6,13 @@ describe Geo::FileRegistry do
describe '.failed' do describe '.failed' do
it 'returns registries in the failed state' do it 'returns registries in the failed state' do
expect(described_class.failed).to contain_exactly(failed) expect(described_class.failed).to match_ids(failed)
end end
end end
describe '.synced' do describe '.synced' do
it 'returns registries in the synced state' do it 'returns registries in the synced state' do
expect(described_class.synced).to contain_exactly(synced) expect(described_class.synced).to match_ids(synced)
end end
end end
...@@ -21,7 +21,7 @@ describe Geo::FileRegistry do ...@@ -21,7 +21,7 @@ describe Geo::FileRegistry do
set(:retry_tomorrow) { create(:geo_file_registry, retry_at: Date.tomorrow) } set(:retry_tomorrow) { create(:geo_file_registry, retry_at: Date.tomorrow) }
it 'returns registries in the synced state' do it 'returns registries in the synced state' do
expect(described_class.retry_due).not_to contain_exactly([retry_tomorrow]) expect(described_class.retry_due).to match_ids([failed, synced, retry_yesterday])
end end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
describe Geo::LfsObjectRegistry, :geo do
set(:lfs_registry) { create(:geo_file_registry, :lfs, :with_file) }
set(:attachment_registry) { create(:geo_file_registry, :attachment) }
it 'only finds lfs registries' do
expect(described_class.all).to match_ids(lfs_registry)
end
it 'finds associated LfsObject record' do
expect(described_class.find(lfs_registry.id).lfs_object).to be_an_instance_of(LfsObject)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Geo::UploadRegistry, :geo do
set(:lfs_registry) { create(:geo_file_registry, :lfs) }
set(:attachment_registry) { create(:geo_file_registry, :attachment, :with_file) }
set(:avatar_registry) { create(:geo_file_registry, :avatar) }
set(:file_registry) { create(:geo_file_registry, :file) }
set(:namespace_file_registry) { create(:geo_file_registry, :namespace_file) }
set(:personal_file_registry) { create(:geo_file_registry, :personal_file) }
set(:favicon_registry) { create(:geo_file_registry, :favicon) }
set(:import_export_registry) { create(:geo_file_registry, :import_export) }
it 'finds all upload registries' do
expected = [attachment_registry,
avatar_registry,
file_registry,
namespace_file_registry,
personal_file_registry,
favicon_registry,
import_export_registry]
expect(described_class.all).to match_ids(expected)
end
it 'finds associated Upload record' do
expect(described_class.find(attachment_registry.id).upload).to be_an_instance_of(Upload)
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