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:
authorBob Van Landuyt <bob@gitlab.com>2017-04-13 19:50:36 +0300
committerBob Van Landuyt <bob@gitlab.com>2017-05-01 12:14:24 +0300
commit579d8891d550cfbbcb433ed4966c6de37c710e83 (patch)
treebc91bd91ae5bdfd7a390b9c07fa553d102f50693 /lib/gitlab/database/rename_reserved_paths_migration
parent7508ee56670dd960275b6438be91471020ea62ab (diff)
Rename projects in a migrationhelper
Diffstat (limited to 'lib/gitlab/database/rename_reserved_paths_migration')
-rw-r--r--lib/gitlab/database/rename_reserved_paths_migration/namespaces.rb28
-rw-r--r--lib/gitlab/database/rename_reserved_paths_migration/projects.rb38
2 files changed, 43 insertions, 23 deletions
diff --git a/lib/gitlab/database/rename_reserved_paths_migration/namespaces.rb b/lib/gitlab/database/rename_reserved_paths_migration/namespaces.rb
index b4f2a67fd06..2ef2629f4c2 100644
--- a/lib/gitlab/database/rename_reserved_paths_migration/namespaces.rb
+++ b/lib/gitlab/database/rename_reserved_paths_migration/namespaces.rb
@@ -16,23 +16,17 @@ module Gitlab
elsif type == :top_level
MigrationClasses::Namespace.where(parent_id: nil)
end
- namespaces.where('lower(path) in (?)', paths.map(&:downcase))
+ with_paths = MigrationClasses::Namespace.arel_table[:path].
+ matches_any(paths)
+ namespaces.where(with_paths)
end
def rename_namespace(namespace)
old_full_path, new_full_path = rename_path_for_routable(namespace)
move_repositories(namespace, old_full_path, new_full_path)
- move_namespace_folders(uploads_dir, old_full_path, new_full_path) if file_storage?
- move_namespace_folders(pages_dir, old_full_path, new_full_path)
- end
-
- def move_namespace_folders(directory, old_relative_path, new_relative_path)
- old_path = File.join(directory, old_relative_path)
- return unless File.directory?(old_path)
-
- new_path = File.join(directory, new_relative_path)
- FileUtils.mv(old_path, new_path)
+ move_uploads(old_full_path, new_full_path)
+ move_pages(old_full_path, new_full_path)
end
def move_repositories(namespace, old_full_path, new_full_path)
@@ -70,18 +64,6 @@ module Gitlab
end
ids
end
-
- def file_storage?
- CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
- end
-
- def uploads_dir
- File.join(CarrierWave.root, "uploads")
- end
-
- def pages_dir
- Settings.pages.path
- end
end
end
end
diff --git a/lib/gitlab/database/rename_reserved_paths_migration/projects.rb b/lib/gitlab/database/rename_reserved_paths_migration/projects.rb
new file mode 100644
index 00000000000..a2c9354e430
--- /dev/null
+++ b/lib/gitlab/database/rename_reserved_paths_migration/projects.rb
@@ -0,0 +1,38 @@
+module Gitlab
+ module Database
+ module RenameReservedPathsMigration
+ module Projects
+ include Gitlab::ShellAdapter
+
+ def rename_projects(paths)
+ projects_for_paths(paths).each do |project|
+ rename_project(project)
+ end
+ end
+
+ def rename_project(project)
+ old_full_path, new_full_path = rename_path_for_routable(project)
+
+ move_repository(project, old_full_path, new_full_path)
+ move_repository(project, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
+ move_uploads(old_full_path, new_full_path)
+ move_pages(old_full_path, new_full_path)
+ end
+
+ def move_repository(project, old_path, new_path)
+ unless gitlab_shell.mv_repository(project.repository_storage_path,
+ old_path,
+ new_path)
+ Rails.logger.error "Error moving #{old_path} to #{new_path}"
+ end
+ end
+
+ def projects_for_paths(paths)
+ with_paths = MigrationClasses::Project.arel_table[:path]
+ .matches_any(paths)
+ MigrationClasses::Project.where(with_paths)
+ end
+ end
+ end
+ end
+end