diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-04-13 18:50:36 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@gitlab.com> | 2017-05-01 11:14:24 +0200 |
commit | 579d8891d550cfbbcb433ed4966c6de37c710e83 (patch) | |
tree | bc91bd91ae5bdfd7a390b9c07fa553d102f50693 /lib/gitlab/database | |
parent | 7508ee56670dd960275b6438be91471020ea62ab (diff) | |
download | gitlab-ce-579d8891d550cfbbcb433ed4966c6de37c710e83.tar.gz |
Rename projects in a migrationhelper
Diffstat (limited to 'lib/gitlab/database')
3 files changed, 74 insertions, 23 deletions
diff --git a/lib/gitlab/database/rename_reserved_paths_migration.rb b/lib/gitlab/database/rename_reserved_paths_migration.rb index 2cfc01ab2f5..5314f933435 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration.rb @@ -8,6 +8,7 @@ module Gitlab def rename_wildcard_paths(one_or_more_paths) paths = Array(one_or_more_paths) rename_namespaces(paths, type: :wildcard) + rename_projects(paths) end def rename_root_paths(paths) @@ -69,6 +70,36 @@ module Gitlab def route_exists?(full_path) MigrationClasses::Route.where(Route.arel_table[:path].matches(full_path)).any? end + + def move_pages(old_path, new_path) + move_folders(pages_dir, old_path, new_path) + end + + def move_uploads(old_path, new_path) + return unless file_storage? + + move_folders(uploads_dir, old_path, new_path) + end + + def move_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) + 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/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 |