diff options
Diffstat (limited to 'app/models/bulk_imports')
-rw-r--r-- | app/models/bulk_imports/configuration.rb | 2 | ||||
-rw-r--r-- | app/models/bulk_imports/entity.rb | 46 | ||||
-rw-r--r-- | app/models/bulk_imports/tracker.rb | 18 |
3 files changed, 64 insertions, 2 deletions
diff --git a/app/models/bulk_imports/configuration.rb b/app/models/bulk_imports/configuration.rb index 8c3aff6f749..4c6f745c268 100644 --- a/app/models/bulk_imports/configuration.rb +++ b/app/models/bulk_imports/configuration.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +# Stores the authentication data required to access another GitLab instance on +# behalf of a user, to import Groups and Projects directly from that instance. class BulkImports::Configuration < ApplicationRecord self.table_name = 'bulk_import_configurations' diff --git a/app/models/bulk_imports/entity.rb b/app/models/bulk_imports/entity.rb index 2d0bba7bccc..34030e079c7 100644 --- a/app/models/bulk_imports/entity.rb +++ b/app/models/bulk_imports/entity.rb @@ -1,5 +1,22 @@ # frozen_string_literal: true +# The BulkImport::Entity represents a Group or Project to be imported during the +# bulk import process. An entity is nested under the parent group when it is not +# a top level group. +# +# A full bulk import entity structure might look like this, where the links are +# parents: +# +# **Before Import** **After Import** +# +# GroupEntity Group +# | | | | +# GroupEntity ProjectEntity Group Project +# | | +# ProjectEntity Project +# +# The tree structure of the entities results in the same structure for imported +# Groups and Projects. class BulkImports::Entity < ApplicationRecord self.table_name = 'bulk_import_entities' @@ -9,6 +26,10 @@ class BulkImports::Entity < ApplicationRecord belongs_to :project, optional: true belongs_to :group, foreign_key: :namespace_id, optional: true + has_many :trackers, + class_name: 'BulkImports::Tracker', + foreign_key: :bulk_import_entity_id + validates :project, absence: true, if: :group validates :group, absence: true, if: :project validates :source_type, :source_full_path, :destination_name, @@ -21,6 +42,21 @@ class BulkImports::Entity < ApplicationRecord state_machine :status, initial: :created do state :created, value: 0 + state :started, value: 1 + state :finished, value: 2 + state :failed, value: -1 + + event :start do + transition created: :started + end + + event :finish do + transition started: :finished + end + + event :fail_op do + transition any => :failed + end end private @@ -33,11 +69,17 @@ class BulkImports::Entity < ApplicationRecord def validate_imported_entity_type if group.present? && project_entity? - errors.add(:group, s_('BulkImport|expected an associated Project but has an associated Group')) + errors.add( + :group, + s_('BulkImport|expected an associated Project but has an associated Group') + ) end if project.present? && group_entity? - errors.add(:project, s_('BulkImport|expected an associated Group but has an associated Project')) + errors.add( + :project, + s_('BulkImport|expected an associated Group but has an associated Project') + ) end end end diff --git a/app/models/bulk_imports/tracker.rb b/app/models/bulk_imports/tracker.rb new file mode 100644 index 00000000000..02e0904e1af --- /dev/null +++ b/app/models/bulk_imports/tracker.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# This model is responsible for keeping track of the requests/pagination +# happening during a Group Migration (BulkImport). +class BulkImports::Tracker < ApplicationRecord + self.table_name = 'bulk_import_trackers' + + belongs_to :entity, + class_name: 'BulkImports::Entity', + foreign_key: :bulk_import_entity_id, + optional: false + + validates :relation, + presence: true, + uniqueness: { scope: :bulk_import_entity_id } + + validates :next_page, presence: { if: :has_next_page? } +end |