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
60561aca
Commit
60561aca
authored
Jun 23, 2017
by
Bob Van Landuyt
Committed by
Bob Van Landuyt
Jun 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update routes directly by ID instead of filtering by path
parent
79cdacc5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
...atabase/rename_reserved_paths_migration/v1/rename_base.rb
+12
-4
No files found.
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
View file @
60561aca
...
...
@@ -6,6 +6,7 @@ module Gitlab
attr_reader
:paths
,
:migration
delegate
:update_column_in_batches
,
:execute
,
:replace_sql
,
:say
,
to: :migration
...
...
@@ -42,14 +43,21 @@ module Gitlab
end
def
rename_routes
(
old_full_path
,
new_full_path
)
routes
=
Route
.
arel_table
main_route_ids
=
routes
.
project
(
routes
[
:id
]).
where
(
routes
[
:path
].
matches
(
old_full_path
))
child_route_ids
=
routes
.
project
(
routes
[
:id
]).
where
(
routes
[
:path
].
matches
(
"
#{
old_full_path
}
/%"
))
matching_ids
=
main_route_ids
.
union
(
child_route_ids
)
ids
=
execute
(
matching_ids
.
to_sql
).
map
{
|
entry
|
entry
[
'id'
]
}
replace_statement
=
replace_sql
(
Route
.
arel_table
[
:path
],
old_full_path
,
new_full_path
)
update_column_in_batches
(
:routes
,
:path
,
replace_statement
)
do
|
table
,
query
|
path_or_children
=
table
[
:path
].
matches_any
([
old_full_path
,
"
#{
old_full_path
}
/%"
])
query
.
where
(
path_or_children
)
end
update
=
Arel
::
UpdateManager
.
new
(
ActiveRecord
::
Base
)
.
table
(
routes
)
.
set
([[
routes
[
:path
],
replace_statement
]])
.
where
(
routes
[
:id
].
in
(
ids
))
execute
(
update
.
to_sql
)
end
def
rename_path
(
namespace_path
,
path_was
)
...
...
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