1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# frozen_string_literal: true
module Projects
module ImportExport
class RelationExport < ApplicationRecord
DESIGN_REPOSITORY_RELATION = 'design_repository'
LFS_OBJECTS_RELATION = 'lfs_objects'
REPOSITORY_RELATION = 'repository'
ROOT_RELATION = 'project'
SNIPPETS_REPOSITORY_RELATION = 'snippets_repository'
UPLOADS_RELATION = 'uploads'
WIKI_REPOSITORY_RELATION = 'wiki_repository'
EXTRA_RELATION_LIST = [
DESIGN_REPOSITORY_RELATION, LFS_OBJECTS_RELATION, REPOSITORY_RELATION, ROOT_RELATION,
SNIPPETS_REPOSITORY_RELATION, UPLOADS_RELATION, WIKI_REPOSITORY_RELATION
].freeze
private_constant :EXTRA_RELATION_LIST
self.table_name = 'project_relation_exports'
belongs_to :project_export_job
has_one :upload,
class_name: 'Projects::ImportExport::RelationExportUpload',
foreign_key: :project_relation_export_id,
inverse_of: :relation_export
validates :export_error, length: { maximum: 300 }
validates :jid, length: { maximum: 255 }
validates :project_export_job, presence: true
validates :relation, presence: true, length: { maximum: 255 }, uniqueness: { scope: :project_export_job_id }
validates :status, numericality: { only_integer: true }, presence: true
scope :by_relation, -> (relation) { where(relation: relation) }
STATUS = {
queued: 0,
started: 1,
finished: 2,
failed: 3
}.freeze
state_machine :status, initial: :queued do
state :queued, value: STATUS[:queued]
state :started, value: STATUS[:started]
state :finished, value: STATUS[:finished]
state :failed, value: STATUS[:failed]
event :start do
transition queued: :started
end
event :retry do
transition started: :queued
end
event :finish do
transition started: :finished
end
event :fail_op do
transition [:queued, :started, :failed] => :failed
end
end
def self.relation_names_list
project_tree_relation_names = ::Gitlab::ImportExport::Reader.new(shared: nil).project_relation_names.map(&:to_s)
project_tree_relation_names + EXTRA_RELATION_LIST
end
def mark_as_failed(export_error)
sanitized_error = Gitlab::UrlSanitizer.sanitize(export_error)
fail_op
update_column(:export_error, sanitized_error)
end
end
end
end
|