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
Jérome Perrin
gitlab-ce
Commits
389057f0
Commit
389057f0
authored
Apr 18, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Projects & Namespaces based on entire paths
parent
e50f4bc0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
9 deletions
+38
-9
db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb
...t_migrate/20170412174900_rename_reserved_dynamic_paths.rb
+2
-1
lib/gitlab/database/rename_reserved_paths_migration/rename_base.rb
...b/database/rename_reserved_paths_migration/rename_base.rb
+4
-0
lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb
...base/rename_reserved_paths_migration/rename_namespaces.rb
+5
-5
lib/gitlab/database/rename_reserved_paths_migration/rename_projects.rb
...tabase/rename_reserved_paths_migration/rename_projects.rb
+4
-3
spec/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces_spec.rb
...rename_reserved_paths_migration/rename_namespaces_spec.rb
+13
-0
spec/lib/gitlab/database/rename_reserved_paths_migration/rename_projects_spec.rb
...e/rename_reserved_paths_migration/rename_projects_spec.rb
+10
-0
No files found.
db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb
View file @
389057f0
...
@@ -27,7 +27,8 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration
...
@@ -27,7 +27,8 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration
users
users
]
]
DISALLOWED_WILDCARD_PATHS
=
%w[objects folders file]
DISALLOWED_WILDCARD_PATHS
=
%w[info/lfs/objects gitlab-lfs/objects
environments/folders]
def
up
def
up
rename_root_paths
(
DISALLOWED_ROOT_PATHS
)
rename_root_paths
(
DISALLOWED_ROOT_PATHS
)
...
...
lib/gitlab/database/rename_reserved_paths_migration/rename_base.rb
View file @
389057f0
...
@@ -13,6 +13,10 @@ module Gitlab
...
@@ -13,6 +13,10 @@ module Gitlab
@migration
=
migration
@migration
=
migration
end
end
def
path_patterns
@path_patterns
||=
paths
.
map
{
|
path
|
"%
#{
path
}
"
}
end
def
rename_path_for_routable
(
routable
)
def
rename_path_for_routable
(
routable
)
old_path
=
routable
.
path
old_path
=
routable
.
path
old_full_path
=
routable
.
full_path
old_full_path
=
routable
.
full_path
...
...
lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb
View file @
389057f0
...
@@ -16,9 +16,9 @@ module Gitlab
...
@@ -16,9 +16,9 @@ module Gitlab
elsif
type
==
:top_level
elsif
type
==
:top_level
MigrationClasses
::
Namespace
.
where
(
parent_id:
nil
)
MigrationClasses
::
Namespace
.
where
(
parent_id:
nil
)
end
end
with_paths
=
MigrationClasses
::
Namespac
e
.
arel_table
[
:path
].
with_paths
=
MigrationClasses
::
Rout
e
.
arel_table
[
:path
].
matches_any
(
paths
)
matches_any
(
path
_pattern
s
)
namespaces
.
where
(
with_paths
)
namespaces
.
joins
(
:route
).
where
(
with_paths
)
end
end
def
rename_namespace
(
namespace
)
def
rename_namespace
(
namespace
)
...
@@ -43,8 +43,8 @@ module Gitlab
...
@@ -43,8 +43,8 @@ module Gitlab
end
end
def
repo_paths_for_namespace
(
namespace
)
def
repo_paths_for_namespace
(
namespace
)
projects_for_namespace
(
namespace
).
projects_for_namespace
(
namespace
).
distinct
.
select
(
:repository_storage
).
select
(
'distinct(repository_storage)'
).
map
(
&
:repository_storage_path
)
map
(
&
:repository_storage_path
)
end
end
def
projects_for_namespace
(
namespace
)
def
projects_for_namespace
(
namespace
)
...
...
lib/gitlab/database/rename_reserved_paths_migration/rename_projects.rb
View file @
389057f0
...
@@ -28,9 +28,10 @@ module Gitlab
...
@@ -28,9 +28,10 @@ module Gitlab
end
end
def
projects_for_paths
def
projects_for_paths
with_paths
=
MigrationClasses
::
Project
.
arel_table
[
:path
]
with_paths
=
MigrationClasses
::
Route
.
arel_table
[
:path
]
.
matches_any
(
paths
)
.
matches_any
(
path_patterns
)
MigrationClasses
::
Project
.
where
(
with_paths
)
MigrationClasses
::
Project
.
joins
(
:route
).
where
(
with_paths
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces_spec.rb
View file @
389057f0
...
@@ -14,6 +14,19 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameNamespaces do
...
@@ -14,6 +14,19 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameNamespaces do
end
end
describe
'#namespaces_for_paths'
do
describe
'#namespaces_for_paths'
do
context
'nested namespaces'
do
let
(
:subject
)
{
described_class
.
new
([
'parent/the-Path'
],
migration
)
}
it
'includes the namespace'
do
parent
=
create
(
:namespace
,
path:
'parent'
)
child
=
create
(
:namespace
,
path:
'the-path'
,
parent:
parent
)
found_ids
=
subject
.
namespaces_for_paths
(
type: :wildcard
).
map
(
&
:id
)
expect
(
found_ids
).
to
contain_exactly
(
child
.
id
)
end
end
context
'for wildcard namespaces'
do
context
'for wildcard namespaces'
do
it
'only returns child namespaces with the correct path'
do
it
'only returns child namespaces with the correct path'
do
_root_namespace
=
create
(
:namespace
,
path:
'THE-path'
)
_root_namespace
=
create
(
:namespace
,
path:
'THE-path'
)
...
...
spec/lib/gitlab/database/rename_reserved_paths_migration/rename_projects_spec.rb
View file @
389057f0
...
@@ -9,6 +9,16 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameProjects do
...
@@ -9,6 +9,16 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameProjects do
end
end
describe
'#projects_for_paths'
do
describe
'#projects_for_paths'
do
it
'searches using nested paths'
do
namespace
=
create
(
:namespace
,
path:
'hello'
)
project
=
create
(
:empty_project
,
path:
'THE-path'
,
namespace:
namespace
)
result_ids
=
described_class
.
new
([
'Hello/the-path'
],
migration
).
projects_for_paths
.
map
(
&
:id
)
expect
(
result_ids
).
to
contain_exactly
(
project
.
id
)
end
it
'includes the correct projects'
do
it
'includes the correct projects'
do
project
=
create
(
:empty_project
,
path:
'THE-path'
)
project
=
create
(
:empty_project
,
path:
'THE-path'
)
_other_project
=
create
(
:empty_project
)
_other_project
=
create
(
:empty_project
)
...
...
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