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
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
db/migrate/20161130101252_fill_projects_routes_table.rb
db/migrate/20161130101252_fill_projects_routes_table.rb
+14
-6
db/migrate/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
DOWNTIME_REASON
=
'No new projects should be created during data copy'
def
up
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
if
Gitlab
::
Database
.
postgresql?
execute
<<-
EOF
INSERT INTO routes (source_id, source_type, path)
(SELECT DISTINCT ON (namespaces.path, projects.path) projects.id, 'Project', concat(namespaces.path, '/', projects.path)
FROM projects INNER JOIN namespaces ON projects.namespace_id = namespaces.id
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
def
down
...
...
db/migrate/20161202152031_remove_duplicates_from_routes.rb
View file @
d494c9a7
...
...
@@ -7,6 +7,11 @@ class RemoveDuplicatesFromRoutes < ActiveRecord::Migration
DOWNTIME
=
false
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
|
path
=
connection
.
quote
(
row
[
'path'
])
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