summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-01-16 09:11:36 +0100
committerJames Lopez <james@jameslopez.es>2017-01-16 09:11:36 +0100
commit6cfaab3f7646b45aac7c5bf8609e777d17ce4897 (patch)
tree63a4a245205ec394fb3f5288201729128d5fb21b /db
parentdaaaf5ef9f182761ac07d76d24d971765134c7e1 (diff)
downloadgitlab-ce-6cfaab3f7646b45aac7c5bf8609e777d17ce4897.tar.gz
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
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20161226122833_remove_dot_git_from_usernames.rb39
1 files changed, 29 insertions, 10 deletions
diff --git a/db/migrate/20161226122833_remove_dot_git_from_usernames.rb b/db/migrate/20161226122833_remove_dot_git_from_usernames.rb
index 7d97339581f..6e4b164b772 100644
--- a/db/migrate/20161226122833_remove_dot_git_from_usernames.rb
+++ b/db/migrate/20161226122833_remove_dot_git_from_usernames.rb
@@ -15,15 +15,26 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
path_was = user['username']
path_was_wildcard = quote_string("#{path_was}/%")
- path = move_namespace(namespace_id, path_was, path)
-
- 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 users SET username = '#{path}' WHERE id = #{id}"
-
- select_all("SELECT id, path FROM routes WHERE path LIKE '#{path_was_wildcard}'").each do |route|
- new_path = "#{path}/#{route['path'].split('/').last}"
- execute "UPDATE routes SET path = '#{new_path}' WHERE id = #{route['id']}"
+ # 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 namespaces SET path = '#{path}' WHERE id = #{namespace_id}"
+ execute "UPDATE users SET username = '#{path}' WHERE id = #{id}"
+
+ select_all("SELECT id, path FROM routes WHERE path LIKE '#{path_was_wildcard}'").each do |route|
+ new_path = "#{path}/#{route['path'].split('/').last}"
+ execute "UPDATE routes SET path = '#{new_path}' WHERE id = #{route['id']}"
+ 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
@@ -87,7 +98,15 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
end
end
- Gitlab::UploadsTransfer.new.rename_namespace(path_was, path)
+ begin
+ 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
end