BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d494c9a7
Commit
d494c9a7
authored
Dec 15, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use optimized query to fill the routes table when running PostgreSQL
parent
f140ae88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
20161130101252_fill_projects_routes_table.rb
db/migrate/20161130101252_fill_projects_routes_table.rb
+14
-6
20161202152031_remove_duplicates_from_routes.rb
db/migrate/20161202152031_remove_duplicates_from_routes.rb
+5
-0
No files found.
db/migrate/20161130101252_fill_projects_routes_table.rb
View file @
d494c9a7
...
@@ -8,12 +8,20 @@ class FillProjectsRoutesTable < ActiveRecord::Migration
...
@@ -8,12 +8,20 @@ class FillProjectsRoutesTable < ActiveRecord::Migration
DOWNTIME_REASON
=
'No new projects should be created during data copy'
DOWNTIME_REASON
=
'No new projects should be created during data copy'
def
up
def
up
execute
<<-
EOF
if
Gitlab
::
Database
.
postgresql?
INSERT INTO routes
execute
<<-
EOF
(source_id, source_type, path)
INSERT INTO routes (source_id, source_type, path)
(SELECT projects.id, 'Project', concat(namespaces.path, '/', projects.path) FROM projects
(SELECT DISTINCT ON (namespaces.path, projects.path) projects.id, 'Project', concat(namespaces.path, '/', projects.path)
INNER JOIN namespaces ON projects.namespace_id = namespaces.id)
FROM projects INNER JOIN namespaces ON projects.namespace_id = namespaces.id
EOF
ORDER BY namespaces.path, projects.path, projects.id DESC)
EOF
else
execute
<<-
EOF
INSERT INTO routes (source_id, source_type, path)
(SELECT projects.id, 'Project', concat(namespaces.path, '/', projects.path)
FROM projects INNER JOIN namespaces ON projects.namespace_id = namespaces.id)
EOF
end
end
end
def
down
def
down
...
...
db/migrate/20161202152031_remove_duplicates_from_routes.rb
View file @
d494c9a7
...
@@ -7,6 +7,11 @@ class RemoveDuplicatesFromRoutes < ActiveRecord::Migration
...
@@ -7,6 +7,11 @@ class RemoveDuplicatesFromRoutes < ActiveRecord::Migration
DOWNTIME
=
false
DOWNTIME
=
false
def
up
def
up
# We can skip this migration when running a PostgreSQL database because
# we use an optimized query in the "FillProjectsRoutesTable" migration
# to fill these values that avoid duplicate entries in the routes table.
return
unless
Gitlab
::
Database
.
mysql?
select_all
(
"SELECT path FROM
#{
quote_table_name
(
:routes
)
}
GROUP BY path HAVING COUNT(*) > 1"
).
each
do
|
row
|
select_all
(
"SELECT path FROM
#{
quote_table_name
(
:routes
)
}
GROUP BY path HAVING COUNT(*) > 1"
).
each
do
|
row
|
path
=
connection
.
quote
(
row
[
'path'
])
path
=
connection
.
quote
(
row
[
'path'
])
execute
(
%Q{
execute
(
%Q{
...
...
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