Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
7d03a55c
Commit
7d03a55c
authored
Jan 16, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove rollback and fixed a couple of issues
parent
6cfaab3f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
db/migrate/20161226122833_remove_dot_git_from_usernames.rb
db/migrate/20161226122833_remove_dot_git_from_usernames.rb
+8
-11
No files found.
db/migrate/20161226122833_remove_dot_git_from_usernames.rb
View file @
7d03a55c
...
@@ -17,7 +17,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
...
@@ -17,7 +17,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
# It's possible for `move_namespace` to return nil if the given namespace
# It's possible for `move_namespace` to return nil if the given namespace
# has nothing on storage (i.e., they never made a project).
# has nothing on storage (i.e., they never made a project).
path
=
move_namespace
(
namespace_id
,
path_was
)
||
rename
_path
(
path_was
)
path
=
move_namespace
(
namespace_id
,
path_was
)
||
new
_path
(
path_was
)
begin
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
}
"
...
@@ -29,10 +29,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
...
@@ -29,10 +29,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
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
rescue
=>
e
# Move namespace path back, if it has been moved already.
say
(
"Couldn't update routes for path
#{
path_was
}
to
#{
path
}
"
)
unless
path_exists?
(
repository_storage_path
,
path_was
)
gitlab_shell
.
mv_namespace
(
repository_storage_path
,
path
,
path_was
)
end
raise
e
raise
e
end
end
...
@@ -55,13 +52,13 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
...
@@ -55,13 +52,13 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
select_all
(
"SELECT id, path FROM routes WHERE path = '
#{
quote_string
(
path
)
}
'"
).
present?
select_all
(
"SELECT id, path FROM routes WHERE path = '
#{
quote_string
(
path
)
}
'"
).
present?
end
end
def
path_exists?
(
repository_storage_path
,
path
)
def
path_exists?
(
path
,
repository_storage_
path
)
gitlab_shell
.
exists?
(
repository_storage_path
,
path
)
repository_storage_path
&&
gitlab_shell
.
exists?
(
repository_storage_path
,
path
)
end
end
# Accepts invalid path like test.git and returns test_git or
# Accepts invalid path like test.git and returns test_git or
# test_git1 if test_git already taken
# test_git1 if test_git already taken
def
rename_path
(
repository_storage_path
,
path
)
def
new_path
(
path
,
repository_storage_path
=
nil
)
# To stay closer with original name and reduce risk of duplicates
# To stay closer with original name and reduce risk of duplicates
# we rename suffix instead of removing it
# we rename suffix instead of removing it
path
=
path
.
sub
(
/\.git\z/
,
'_git'
)
path
=
path
.
sub
(
/\.git\z/
,
'_git'
)
...
@@ -69,7 +66,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
...
@@ -69,7 +66,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
counter
=
0
counter
=
0
base
=
path
base
=
path
while
route_exists?
(
path
)
||
path_exists?
(
repository_storage_path
,
path
)
while
route_exists?
(
path
)
||
path_exists?
(
path
,
repository_storage_
path
)
counter
+=
1
counter
+=
1
path
=
"
#{
base
}#{
counter
}
"
path
=
"
#{
base
}#{
counter
}
"
end
end
...
@@ -77,7 +74,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
...
@@ -77,7 +74,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
path
path
end
end
def
move_namespace
(
namespace_id
,
path_was
,
path
)
def
move_namespace
(
namespace_id
,
path_was
)
repository_storage_paths
=
select_all
(
"SELECT distinct(repository_storage) FROM projects WHERE namespace_id =
#{
namespace_id
}
"
).
map
do
|
row
|
repository_storage_paths
=
select_all
(
"SELECT distinct(repository_storage) FROM projects WHERE namespace_id =
#{
namespace_id
}
"
).
map
do
|
row
|
Gitlab
.
config
.
repositories
.
storages
[
row
[
'repository_storage'
]]
Gitlab
.
config
.
repositories
.
storages
[
row
[
'repository_storage'
]]
end
.
compact
end
.
compact
...
@@ -87,7 +84,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
...
@@ -87,7 +84,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
# Ensure old directory exists before moving it
# Ensure old directory exists before moving it
gitlab_shell
.
add_namespace
(
repository_storage_path
,
path_was
)
gitlab_shell
.
add_namespace
(
repository_storage_path
,
path_was
)
path
=
quote_string
(
rename_path
(
repository_storage_path
,
path_was
))
path
=
quote_string
(
new_path
(
path_was
,
repository_storage_path
))
unless
gitlab_shell
.
mv_namespace
(
repository_storage_path
,
path_was
,
path
)
unless
gitlab_shell
.
mv_namespace
(
repository_storage_path
,
path_was
,
path
)
Rails
.
logger
.
error
"Exception moving path
#{
repository_storage_path
}
from
#{
path_was
}
to
#{
path
}
"
Rails
.
logger
.
error
"Exception moving path
#{
repository_storage_path
}
from
#{
path_was
}
to
#{
path
}
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment