summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-07-04 15:00:01 +0000
committerDouwe Maan <douwe@gitlab.com>2017-07-04 15:00:01 +0000
commit5e2f7f25eb6ed1118cb541e43026915a7c4cdfef (patch)
treefbb893941818f2c9f0f1ce89dd5daf9d67ed00aa /lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb
parentafbc7520c296196d0f3f95d4a24a9e42c0e41f3c (diff)
parent016b9f2565f85b9c77a5a779b64483ca1d4e1776 (diff)
downloadgitlab-ce-5e2f7f25eb6ed1118cb541e43026915a7c4cdfef.tar.gz
Merge branch 'master' into '33580-fix-api-scoping'
# Conflicts: # lib/api/users.rb
Diffstat (limited to 'lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb')
-rw-r--r--lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb
index 448717eb744..75a75f61953 100644
--- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb
+++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb
@@ -16,12 +16,37 @@ module Gitlab
def rename_project(project)
old_full_path, new_full_path = rename_path_for_routable(project)
+ track_rename('project', old_full_path, new_full_path)
+
+ move_project_folders(project, old_full_path, new_full_path)
+ end
+
+ def move_project_folders(project, old_full_path, new_full_path)
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 revert_renames
+ reverts_for_type('project') do |path_before_rename, current_path|
+ matches_path = MigrationClasses::Route.arel_table[:path].matches(current_path)
+ project = MigrationClasses::Project.joins(:route)
+ .where(matches_path).first
+
+ if project
+ perform_rename(project, current_path, path_before_rename)
+
+ move_project_folders(project, current_path, path_before_rename)
+ else
+ say "Couldn't rename project from #{current_path} back to "\
+ "#{path_before_rename}, project was renamed or no longer "\
+ "exists at the expected path."
+
+ end
+ end
+ end
+
def move_repository(project, old_path, new_path)
unless gitlab_shell.mv_repository(project.repository_storage_path,
old_path,