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
...
@@ -28,6 +28,10 @@ module Gitlab
track_rename
(
'namespace'
,
old_full_path
,
new_full_path
)
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_repositories
(
namespace
,
old_full_path
,
new_full_path
)
move_uploads
(
old_full_path
,
new_full_path
)
move_uploads
(
old_full_path
,
new_full_path
)
move_pages
(
old_full_path
,
new_full_path
)
move_pages
(
old_full_path
,
new_full_path
)
...
@@ -35,6 +39,23 @@ module Gitlab
...
@@ -35,6 +39,23 @@ module Gitlab
remove_cached_html_for_projects
(
projects_for_namespace
(
namespace
).
map
(
&
:id
))
remove_cached_html_for_projects
(
projects_for_namespace
(
namespace
).
map
(
&
:id
))
end
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
)
def
rename_user
(
old_username
,
new_username
)
MigrationClasses
::
User
.
where
(
username:
old_username
)
MigrationClasses
::
User
.
where
(
username:
old_username
)
.
update_all
(
username:
new_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
...
@@ -38,7 +38,8 @@ module Gitlab
move_project_folders
(
project
,
current_path
,
path_before_rename
)
move_project_folders
(
project
,
current_path
,
path_before_rename
)
else
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
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
...
@@ -6,6 +6,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca
before
do
before
do
allow
(
migration
).
to
receive
(
:say
)
allow
(
migration
).
to
receive
(
:say
)
TestEnv
.
clean_test_path
end
end
def
migration_namespace
(
namespace
)
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'
...
@@ -3,9 +3,11 @@ require 'spec_helper'
describe
Gitlab
::
Database
::
RenameReservedPathsMigration
::
V1
::
RenameNamespaces
,
:truncate
do
describe
Gitlab
::
Database
::
RenameReservedPathsMigration
::
V1
::
RenameNamespaces
,
:truncate
do
let
(
:migration
)
{
FakeRenameReservedPathMigrationV1
.
new
}
let
(
:migration
)
{
FakeRenameReservedPathMigrationV1
.
new
}
let
(
:subject
)
{
described_class
.
new
([
'the-path'
],
migration
)
}
let
(
:subject
)
{
described_class
.
new
([
'the-path'
],
migration
)
}
let
(
:namespace
)
{
create
(
:group
,
name:
'the-path'
)
}
before
do
before
do
allow
(
migration
).
to
receive
(
:say
)
allow
(
migration
).
to
receive
(
:say
)
TestEnv
.
clean_test_path
end
end
def
migration_namespace
(
namespace
)
def
migration_namespace
(
namespace
)
...
@@ -137,8 +139,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
...
@@ -137,8 +139,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
end
end
describe
"#rename_namespace"
do
describe
"#rename_namespace"
do
let
(
:namespace
)
{
create
(
:group
,
name:
'the-path'
)
}
it
'renames paths & routes for the namespace'
do
it
'renames paths & routes for the namespace'
do
expect
(
subject
).
to
receive
(
:rename_path_for_routable
)
expect
(
subject
).
to
receive
(
:rename_path_for_routable
)
.
with
(
namespace
)
.
with
(
namespace
)
...
@@ -149,11 +149,27 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
...
@@ -149,11 +149,27 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect
(
namespace
.
reload
.
path
).
to
eq
(
'the-path0'
)
expect
(
namespace
.
reload
.
path
).
to
eq
(
'the-path0'
)
end
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
it
"moves the the repository for a project in the namespace"
do
create
(
:project
,
namespace:
namespace
,
path:
"the-path-project"
)
create
(
:project
,
namespace:
namespace
,
path:
"the-path-project"
)
expected_repo
=
File
.
join
(
TestEnv
.
repos_path
,
"the-path0"
,
"the-path-project.git"
)
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
)
expect
(
File
.
directory?
(
expected_repo
)).
to
be
(
true
)
end
end
...
@@ -161,13 +177,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
...
@@ -161,13 +177,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
it
"moves the uploads for the namespace"
do
it
"moves the uploads for the namespace"
do
expect
(
subject
).
to
receive
(
:move_uploads
).
with
(
"the-path"
,
"the-path0"
)
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
end
it
"moves the pages for the namespace"
do
it
"moves the pages for the namespace"
do
expect
(
subject
).
to
receive
(
:move_pages
).
with
(
"the-path"
,
"the-path0"
)
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
end
it
'invalidates the markdown cache of related projects'
do
it
'invalidates the markdown cache of related projects'
do
...
@@ -175,13 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
...
@@ -175,13 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect
(
subject
).
to
receive
(
:remove_cached_html_for_projects
).
with
([
project
.
id
])
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
end
it
"doesn't rename users for other namespaces"
do
it
"doesn't rename users for other namespaces"
do
expect
(
subject
).
not_to
receive
(
:rename_user
)
expect
(
subject
).
not_to
receive
(
:rename_user
)
subject
.
rename_namespace
(
namespace
)
subject
.
rename_namespace
_dependencies
(
namespace
,
'the-path'
,
'the-path0'
)
end
end
it
'renames the username of a namespace for a user'
do
it
'renames the username of a namespace for a user'
do
...
@@ -189,14 +205,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
...
@@ -189,14 +205,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect
(
subject
).
to
receive
(
:rename_user
).
with
(
'the-path'
,
'the-path0'
)
expect
(
subject
).
to
receive
(
:rename_user
).
with
(
'the-path'
,
'the-path0'
)
subject
.
rename_namespace
(
user
.
namespace
)
subject
.
rename_namespace_dependencies
(
user
.
namespace
,
'the-path'
,
'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
end
end
end
...
@@ -231,4 +240,43 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
...
@@ -231,4 +240,43 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
subject
.
rename_namespaces
(
type: :child
)
subject
.
rename_namespaces
(
type: :child
)
end
end
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
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
...
@@ -9,9 +9,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr
namespace:
create
(
:namespace
,
path:
'known-parent'
))
namespace:
create
(
:namespace
,
path:
'known-parent'
))
end
end
before
do
before
do
allow
(
migration
).
to
receive
(
:say
)
allow
(
migration
).
to
receive
(
:say
)
TestEnv
.
clean_test_path
end
end
describe
'#projects_for_paths'
do
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