debian-mirror-gitlab/app/models/bulk_imports/export.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.5 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module BulkImports
class Export < ApplicationRecord
include Gitlab::Utils::StrongMemoize
2021-09-04 01:27:46 +05:30
STARTED = 0
FINISHED = 1
FAILED = -1
2021-06-08 01:23:25 +05:30
self.table_name = 'bulk_import_exports'
belongs_to :project, optional: true
belongs_to :group, optional: true
has_one :upload, class_name: 'BulkImports::ExportUpload'
2023-05-27 22:25:52 +05:30
has_many :batches, class_name: 'BulkImports::ExportBatch'
2021-06-08 01:23:25 +05:30
validates :project, presence: true, unless: :group
validates :group, presence: true, unless: :project
validates :relation, :status, presence: true
validate :portable_relation?
state_machine :status, initial: :started do
2021-09-04 01:27:46 +05:30
state :started, value: STARTED
state :finished, value: FINISHED
state :failed, value: FAILED
2021-06-08 01:23:25 +05:30
event :start do
transition any => :started
end
event :finish do
transition started: :finished
2023-07-09 08:55:56 +05:30
transition finished: :finished
2021-06-08 01:23:25 +05:30
transition failed: :failed
end
event :fail_op do
transition any => :failed
end
end
def portable_relation?
return unless portable
errors.add(:relation, 'Unsupported portable relation') unless config.portable_relations.include?(relation)
end
def portable
strong_memoize(:portable) do
project || group
end
end
def relation_definition
2021-11-18 22:05:49 +05:30
config.relation_definition_for(relation)
2021-06-08 01:23:25 +05:30
end
def config
strong_memoize(:config) do
FileTransfer.config_for(portable)
end
end
end
end