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
152cba56
Commit
152cba56
authored
Jun 06, 2017
by
Bob Van Landuyt
Committed by
Bob Van Landuyt
Jun 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert namespace renames
parent
0faff42d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
17 deletions
+88
-17
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb
...e/rename_reserved_paths_migration/v1/rename_namespaces.rb
+21
-0
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb
...ase/rename_reserved_paths_migration/v1/rename_projects.rb
+2
-1
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb
...se/rename_reserved_paths_migration/v1/rename_base_spec.rb
+1
-0
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb
...ame_reserved_paths_migration/v1/rename_namespaces_spec.rb
+63
-15
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb
...ename_reserved_paths_migration/v1/rename_projects_spec.rb
+1
-1
No files found.
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb
View file @
152cba56
...
...
@@ -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
)
...
...
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb
View file @
152cba56
...
...
@@ -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
...
...
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb
View file @
152cba56
...
...
@@ -6,6 +6,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca
before
do
allow
(
migration
).
to
receive
(
:say
)
TestEnv
.
clean_test_path
end
def
migration_namespace
(
namespace
)
...
...
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb
View file @
152cba56
...
...
@@ -3,9 +3,11 @@ require 'spec_helper'
describe
Gitlab
::
Database
::
RenameReservedPathsMigration
::
V1
::
RenameNamespaces
,
:truncate
do
let
(
:migration
)
{
FakeRenameReservedPathMigrationV1
.
new
}
let
(
:subject
)
{
described_class
.
new
([
'the-path'
],
migration
)
}
let
(
:namespace
)
{
create
(
:group
,
name:
'the-path'
)
}
before
do
allow
(
migration
).
to
receive
(
:say
)
TestEnv
.
clean_test_path
end
def
migration_namespace
(
namespace
)
...
...
@@ -137,8 +139,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
end
describe
"#rename_namespace"
do
let
(
:namespace
)
{
create
(
:group
,
name:
'the-path'
)
}
it
'renames paths & routes for the namespace'
do
expect
(
subject
).
to
receive
(
:rename_path_for_routable
)
.
with
(
namespace
)
...
...
@@ -149,11 +149,27 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect
(
namespace
.
reload
.
path
).
to
eq
(
'the-path0'
)
end
it
'tracks the rename'
do
expect
(
subject
).
to
receive
(
:track_rename
)
.
with
(
'namespace'
,
'the-path'
,
'the-path0'
)
subject
.
rename_namespace
(
namespace
)
end
it
'renames things related to the namespace'
do
expect
(
subject
).
to
receive
(
:rename_namespace_dependencies
)
.
with
(
namespace
,
'the-path'
,
'the-path0'
)
subject
.
rename_namespace
(
namespace
)
end
end
describe
'#rename_namespace_dependencies'
do
it
"moves the the repository for a project in the namespace"
do
create
(
:project
,
namespace:
namespace
,
path:
"the-path-project"
)
expected_repo
=
File
.
join
(
TestEnv
.
repos_path
,
"the-path0"
,
"the-path-project.git"
)
subject
.
rename_namespace
(
namespace
)
subject
.
rename_namespace
_dependencies
(
namespace
,
'the-path'
,
'the-path0'
)
expect
(
File
.
directory?
(
expected_repo
)).
to
be
(
true
)
end
...
...
@@ -161,13 +177,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
it
"moves the uploads for the namespace"
do
expect
(
subject
).
to
receive
(
:move_uploads
).
with
(
"the-path"
,
"the-path0"
)
subject
.
rename_namespace
(
namespace
)
subject
.
rename_namespace
_dependencies
(
namespace
,
'the-path'
,
'the-path0'
)
end
it
"moves the pages for the namespace"
do
expect
(
subject
).
to
receive
(
:move_pages
).
with
(
"the-path"
,
"the-path0"
)
subject
.
rename_namespace
(
namespace
)
subject
.
rename_namespace
_dependencies
(
namespace
,
'the-path'
,
'the-path0'
)
end
it
'invalidates the markdown cache of related projects'
do
...
...
@@ -175,13 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect
(
subject
).
to
receive
(
:remove_cached_html_for_projects
).
with
([
project
.
id
])
subject
.
rename_namespace
(
namespace
)
subject
.
rename_namespace
_dependencies
(
namespace
,
'the-path'
,
'the-path0'
)
end
it
"doesn't rename users for other namespaces"
do
expect
(
subject
).
not_to
receive
(
:rename_user
)
subject
.
rename_namespace
(
namespace
)
subject
.
rename_namespace
_dependencies
(
namespace
,
'the-path'
,
'the-path0'
)
end
it
'renames the username of a namespace for a user'
do
...
...
@@ -189,14 +205,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect
(
subject
).
to
receive
(
:rename_user
).
with
(
'the-path'
,
'the-path0'
)
subject
.
rename_namespace
(
user
.
namespace
)
end
it
'tracks the rename'
do
expect
(
subject
).
to
receive
(
:track_rename
)
.
with
(
'namespace'
,
'the-path'
,
'the-path0'
)
subject
.
rename_namespace
(
namespace
)
subject
.
rename_namespace_dependencies
(
user
.
namespace
,
'the-path'
,
'the-path0'
)
end
end
...
...
@@ -231,4 +240,43 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
subject
.
rename_namespaces
(
type: :child
)
end
end
describe
'#revert_renames'
,
redis:
true
do
it
'renames the routes back to the previous values'
do
project
=
create
(
:project
,
path:
'a-project'
,
namespace:
namespace
)
subject
.
rename_namespace
(
namespace
)
expect
(
subject
).
to
receive
(
:perform_rename
)
.
with
(
kind_of
(
Gitlab
::
Database
::
RenameReservedPathsMigration
::
V1
::
MigrationClasses
::
Namespace
),
'the-path0'
,
'the-path'
).
and_call_original
subject
.
revert_renames
expect
(
namespace
.
reload
.
path
).
to
eq
(
'the-path'
)
expect
(
namespace
.
reload
.
route
.
path
).
to
eq
(
'the-path'
)
expect
(
project
.
reload
.
route
.
path
).
to
eq
(
'the-path/a-project'
)
end
it
'moves the repositories back to their original place'
do
project
=
create
(
:project
,
path:
'a-project'
,
namespace:
namespace
)
project
.
create_repository
subject
.
rename_namespace
(
namespace
)
expected_path
=
File
.
join
(
TestEnv
.
repos_path
,
'the-path'
,
'a-project.git'
)
expect
(
subject
).
to
receive
(
:rename_namespace_dependencies
)
.
with
(
kind_of
(
Gitlab
::
Database
::
RenameReservedPathsMigration
::
V1
::
MigrationClasses
::
Namespace
),
'the-path0'
,
'the-path'
).
and_call_original
subject
.
revert_renames
expect
(
File
.
directory?
(
expected_path
)).
to
be_truthy
end
end
end
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb
View file @
152cba56
...
...
@@ -9,9 +9,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr
namespace:
create
(
:namespace
,
path:
'known-parent'
))
end
before
do
allow
(
migration
).
to
receive
(
:say
)
TestEnv
.
clean_test_path
end
describe
'#projects_for_paths'
do
...
...
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