Commit 6cfaab3f authored by James Lopez's avatar James Lopez

Fix remove dot git migration failing when user has no projects

- Fixed typo
- Fixed migration when there are no projects and path is nil
- Added path rollback that was missing if there was a SQL error
parent daaaf5ef
...@@ -15,8 +15,11 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration ...@@ -15,8 +15,11 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
path_was = user['username'] path_was = user['username']
path_was_wildcard = quote_string("#{path_was}/%") path_was_wildcard = quote_string("#{path_was}/%")
path = move_namespace(namespace_id, path_was, path) # It's possible for `move_namespace` to return nil if the given namespace
# has nothing on storage (i.e., they never made a project).
path = move_namespace(namespace_id, path_was) || rename_path(path_was)
begin
execute "UPDATE routes SET path = '#{path}' WHERE source_type = 'Namespace' AND source_id = #{namespace_id}" execute "UPDATE routes SET path = '#{path}' WHERE source_type = 'Namespace' AND source_id = #{namespace_id}"
execute "UPDATE namespaces SET path = '#{path}' WHERE id = #{namespace_id}" execute "UPDATE namespaces SET path = '#{path}' WHERE id = #{namespace_id}"
execute "UPDATE users SET username = '#{path}' WHERE id = #{id}" execute "UPDATE users SET username = '#{path}' WHERE id = #{id}"
...@@ -25,6 +28,14 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration ...@@ -25,6 +28,14 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
new_path = "#{path}/#{route['path'].split('/').last}" new_path = "#{path}/#{route['path'].split('/').last}"
execute "UPDATE routes SET path = '#{new_path}' WHERE id = #{route['id']}" execute "UPDATE routes SET path = '#{new_path}' WHERE id = #{route['id']}"
end end
rescue => e
# Move namespace path back, if it has been moved already.
unless path_exists?(repository_storage_path, path_was)
gitlab_shell.mv_namespace(repository_storage_path, path, path_was)
end
raise e
end
end end
end end
...@@ -87,7 +98,15 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration ...@@ -87,7 +98,15 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
end end
end end
begin
Gitlab::UploadsTransfer.new.rename_namespace(path_was, path) Gitlab::UploadsTransfer.new.rename_namespace(path_was, path)
rescue => e
if path.nil?
say("Couldn't find a storage path for #{namespace_id}, #{path_was} -- skipping")
else
raise e
end
end
path path
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment