Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2018-11-28 00:48:16 +0300
committerToon Claes <toon@gitlab.com>2018-11-28 00:48:55 +0300
commitf35ff1ea48f228a705a6b5cd6a492a922e7db396 (patch)
tree3adb4a1c279b9e198285a212579cacfe020fec8d /lib/gitlab/background_migration
parentde0cc8e46a063676bbdf05cb5b1bb1b4ccf08f14 (diff)
Ensure all Routables have a parent
Or otherwise do not try to write repo config.
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb b/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
index 7a6d4175b99..29fa0f18448 100644
--- a/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
+++ b/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
@@ -7,6 +7,8 @@ module Gitlab
# Storing the full project path in the git config allows admins to
# easily identify a project when it is using hashed storage.
module BackfillProjectFullpathInRepoConfig
+ OrphanedNamespaceError = Class.new(StandardError)
+
module Storage
# Class that returns the disk path for a project using hashed storage
class HashedProject
@@ -51,11 +53,15 @@ module Gitlab
end
def build_full_path
- if parent && path
- parent.full_path + '/' + path
- else
- path
- end
+ return path unless has_parent?
+
+ raise OrphanedNamespaceError if parent.nil?
+
+ parent.full_path + '/' + path
+ end
+
+ def has_parent?
+ read_attribute(association(:parent).reflection.foreign_key)
end
end
@@ -81,7 +87,9 @@ module Gitlab
include Routable
- belongs_to :parent, class_name: "Namespace"
+ belongs_to :parent, class_name: 'Namespace', inverse_of: 'namespaces'
+ has_many :projects, inverse_of: :parent
+ has_many :namespaces, inverse_of: :parent
end
# Project is where the repository (etc.) is stored
@@ -93,9 +101,8 @@ module Gitlab
FULLPATH_CONFIG_KEY = 'gitlab.fullpath'
- belongs_to :namespace
+ belongs_to :parent, class_name: 'Namespace', foreign_key: :namespace_id, inverse_of: 'projects'
delegate :disk_path, to: :storage
- alias_method :parent, :namespace
def add_fullpath_config
entries = { FULLPATH_CONFIG_KEY => full_path }
@@ -150,14 +157,14 @@ module Gitlab
end
def perform(start_id, end_id)
- Project.where(id: start_id..end_id).each do |project|
+ Project.includes(:parent).where(id: start_id..end_id).each do |project|
safe_perform_one(project)
end
end
def safe_perform_one(project, retry_count = 0)
perform_one(project)
- rescue GRPC::NotFound, GRPC::InvalidArgument
+ rescue GRPC::NotFound, GRPC::InvalidArgument, OrphanedNamespaceError
nil
rescue GRPC::BadStatus
schedule_retry(project, retry_count + 1) if retry_count < MAX_RETRIES