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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
397d3fd7
Commit
397d3fd7
authored
Jun 26, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only do one query for updating routes
parent
60561aca
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
5 deletions
+15
-5
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
...atabase/rename_reserved_paths_migration/v1/rename_base.rb
+15
-5
No files found.
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
View file @
397d3fd7
...
@@ -8,6 +8,7 @@ module Gitlab
...
@@ -8,6 +8,7 @@ module Gitlab
delegate
:update_column_in_batches
,
delegate
:update_column_in_batches
,
:execute
,
:execute
,
:replace_sql
,
:replace_sql
,
:quote_string
,
:say
,
:say
,
to: :migration
to: :migration
...
@@ -44,10 +45,18 @@ module Gitlab
...
@@ -44,10 +45,18 @@ module Gitlab
def
rename_routes
(
old_full_path
,
new_full_path
)
def
rename_routes
(
old_full_path
,
new_full_path
)
routes
=
Route
.
arel_table
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
}
/%"
))
quoted_old_full_path
=
quote_string
(
old_full_path
)
matching_ids
=
main_route_ids
.
union
(
child_route_ids
)
quoted_old_wildcard_path
=
quote_string
(
"
#{
old_full_path
}
/%"
)
ids
=
execute
(
matching_ids
.
to_sql
).
map
{
|
entry
|
entry
[
'id'
]
}
filter
=
if
Database
.
mysql?
"lower(routes.path) = lower('
#{
quoted_old_full_path
}
') "
\
"OR routes.path LIKE '
#{
quoted_old_wildcard_path
}
'"
else
"routes.id IN "
\
"( SELECT routes.id FROM routes WHERE lower(routes.path) = lower('
#{
quoted_old_full_path
}
') "
\
"UNION SELECT routes.id FROM routes WHERE routes.path ILIKE '
#{
quoted_old_wildcard_path
}
' )"
end
replace_statement
=
replace_sql
(
Route
.
arel_table
[
:path
],
replace_statement
=
replace_sql
(
Route
.
arel_table
[
:path
],
old_full_path
,
old_full_path
,
...
@@ -56,7 +65,8 @@ module Gitlab
...
@@ -56,7 +65,8 @@ module Gitlab
update
=
Arel
::
UpdateManager
.
new
(
ActiveRecord
::
Base
)
update
=
Arel
::
UpdateManager
.
new
(
ActiveRecord
::
Base
)
.
table
(
routes
)
.
table
(
routes
)
.
set
([[
routes
[
:path
],
replace_statement
]])
.
set
([[
routes
[
:path
],
replace_statement
]])
.
where
(
routes
[
:id
].
in
(
ids
))
.
where
(
Arel
::
Nodes
::
SqlLiteral
.
new
(
filter
))
execute
(
update
.
to_sql
)
execute
(
update
.
to_sql
)
end
end
...
...
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