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
986f470d
Commit
986f470d
authored
Feb 28, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve migration robustness and speed.
parent
7a22a589
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
4 deletions
+10
-4
db/migrate/20180223120443_create_user_contributed_projects_table.rb
.../20180223120443_create_user_contributed_projects_table.rb
+0
-2
db/post_migrate/20180223124427_build_user_contributed_projects_table.rb
...e/20180223124427_build_user_contributed_projects_table.rb
+9
-1
db/schema.rb
db/schema.rb
+1
-1
No files found.
db/migrate/20180223120443_create_user_contributed_projects_table.rb
View file @
986f470d
...
...
@@ -9,8 +9,6 @@ class CreateUserContributedProjectsTable < ActiveRecord::Migration
create_table
:user_contributed_projects
,
id:
false
do
|
t
|
t
.
references
:user
,
null:
false
t
.
references
:project
,
null:
false
t
.
index
[
:user_id
,
:project_id
],
unique:
true
end
add_concurrent_foreign_key
:user_contributed_projects
,
:users
,
column: :user_id
,
on_delete: :cascade
...
...
db/post_migrate/20180223124427_build_user_contributed_projects_table.rb
View file @
986f470d
...
...
@@ -12,10 +12,14 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration
else
MysqlStrategy
.
new
end
.
up
add_concurrent_index
:user_contributed_projects
,
[
:project_id
,
:user_id
],
unique:
true
end
def
down
execute
"TRUNCATE user_contributed_projects"
remove_concurrent_index_by_name
:user_contributed_projects
,
'index_user_contributed_projects_on_project_id_and_user_id'
end
private
...
...
@@ -24,7 +28,7 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration
include
Gitlab
::
Database
::
MigrationHelpers
BATCH_SIZE
=
100_000
SLEEP_TIME
=
30
SLEEP_TIME
=
5
def
up
with_index
(
:events
,
[
:author_id
,
:project_id
],
name:
'events_user_contributions_temp'
,
where:
'project_id IS NOT NULL'
)
do
...
...
@@ -44,10 +48,14 @@ class BuildUserContributedProjectsTable < ActiveRecord::Migration
records
+=
result
.
cmd_tuples
Rails
.
logger
.
info
"Building user_contributed_projects table, batch #
#{
iteration
}
complete, created
#{
records
}
overall"
Kernel
.
sleep
(
SLEEP_TIME
)
if
result
.
cmd_tuples
>
0
rescue
ActiveRecord
::
InvalidForeignKey
=>
e
Rails
.
logger
.
info
"Retry on InvalidForeignKey:
#{
e
}
"
retry
end
while
result
.
cmd_tuples
>
0
end
execute
"ANALYZE user_contributed_projects"
end
private
...
...
db/schema.rb
View file @
986f470d
...
...
@@ -1820,7 +1820,7 @@ ActiveRecord::Schema.define(version: 20180304204842) do
t
.
integer
"project_id"
,
null:
false
end
add_index
"user_contributed_projects"
,
[
"
user_id"
,
"project_id"
],
name:
"index_user_contributed_projects_on_user_id_and_project
_id"
,
unique:
true
,
using: :btree
add_index
"user_contributed_projects"
,
[
"
project_id"
,
"user_id"
],
name:
"index_user_contributed_projects_on_project_id_and_user
_id"
,
unique:
true
,
using: :btree
create_table
"user_custom_attributes"
,
force: :cascade
do
|
t
|
t
.
datetime_with_timezone
"created_at"
,
null:
false
...
...
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