summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-05-18 20:08:32 +0000
committerDouwe Maan <douwe@gitlab.com>2017-05-18 20:08:32 +0000
commitf62f0c258d89465bea514e5127ea1effdeb3b35d (patch)
tree55a982b36fc56b86d68d4bc3a8089dfc58820362 /lib
parent36ede00876aacd0005eac8e9b4779e3014519e0c (diff)
downloadgitlab-ce-f62f0c258d89465bea514e5127ea1effdeb3b35d.tar.gz
Fixes for the rename reserved paths helpers
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb8
-rw-r--r--lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb3
-rw-r--r--lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb6
3 files changed, 16 insertions, 1 deletions
diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb
index 4fdcb682c2f..5481024db8e 100644
--- a/lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb
+++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb
@@ -48,6 +48,14 @@ module Gitlab
def self.name
'Namespace'
end
+
+ def kind
+ type == 'Group' ? 'group' : 'user'
+ end
+ end
+
+ class User < ActiveRecord::Base
+ self.table_name = 'users'
end
class Route < ActiveRecord::Base
diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
index 5397877b5d5..d60fd4bb551 100644
--- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
+++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
@@ -41,7 +41,8 @@ module Gitlab
new_full_path)
update_column_in_batches(:routes, :path, replace_statement) do |table, query|
- query.where(MigrationClasses::Route.arel_table[:path].matches("#{old_full_path}%"))
+ path_or_children = table[:path].matches_any([old_full_path, "#{old_full_path}/%"])
+ query.where(path_or_children)
end
end
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 b9f4f3cff3c..2958ad4b8e5 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
@@ -29,9 +29,15 @@ module Gitlab
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)
+ rename_user(old_full_path, new_full_path) if namespace.kind == 'user'
remove_cached_html_for_projects(projects_for_namespace(namespace).map(&:id))
end
+ def rename_user(old_username, new_username)
+ MigrationClasses::User.where(username: old_username)
+ .update_all(username: new_username)
+ end
+
def move_repositories(namespace, old_full_path, new_full_path)
repo_paths_for_namespace(namespace).each do |repository_storage_path|
# Ensure old directory exists before moving it