From 152cba56e4004de1b1c2accee77e40a019d8c667 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Tue, 6 Jun 2017 18:40:11 +0200 Subject: Revert namespace renames --- .../v1/rename_namespaces.rb | 21 +++++++++++++++++++++ .../v1/rename_projects.rb | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'lib/gitlab/database/rename_reserved_paths_migration') diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb index a84af02e67b..434167b0f88 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb @@ -28,6 +28,10 @@ module Gitlab track_rename('namespace', old_full_path, new_full_path) + rename_namespace_dependencies(namespace, old_full_path, new_full_path) + end + + def rename_namespace_dependencies(namespace, old_full_path, new_full_path) move_repositories(namespace, old_full_path, new_full_path) move_uploads(old_full_path, new_full_path) move_pages(old_full_path, new_full_path) @@ -35,6 +39,23 @@ module Gitlab remove_cached_html_for_projects(projects_for_namespace(namespace).map(&:id)) end + def revert_renames + reverts_for_type('namespace') do |path_before_rename, current_path| + matches_path = MigrationClasses::Route.arel_table[:path].matches(current_path) + namespace = MigrationClasses::Namespace.joins(:route) + .where(matches_path).first.becomes(MigrationClasses::Namespace) + + if namespace + perform_rename(namespace, current_path, path_before_rename) + + rename_namespace_dependencies(namespace, current_path, path_before_rename) + else + say "Couldn't rename namespace##{namespace.id} from #{current_path} "\ + " back to #{path_before_rename}, namespace no longer exists" + end + end + end + def rename_user(old_username, new_username) MigrationClasses::User.where(username: old_username) .update_all(username: new_username) 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 1d2a41d91bb..061f531f1d5 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 @@ -38,7 +38,8 @@ module Gitlab move_project_folders(project, current_path, path_before_rename) else - say "Couldn't rename project##{project.id} from #{current_path} back to #{path_before_rename}, project no longer exists" + say "Couldn't rename project##{project.id} from #{current_path} "\ + "back to #{path_before_rename}, project no longer exists" end end end -- cgit v1.2.3