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
Léo-Paul Géneau
gitlab-ce
Commits
9a32ca40
Commit
9a32ca40
authored
Jun 28, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find builds that require a migration in batches
parent
b7d67232
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
...0170628080858_migrate_stage_id_reference_in_background.rb
+6
-3
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
...grations/migrate_stage_id_reference_in_background_spec.rb
+2
-0
No files found.
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
View file @
9a32ca40
...
@@ -2,6 +2,8 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
...
@@ -2,6 +2,8 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
BATCH_SIZE
=
10000
MIGRATION
=
'MigrateBuildStageIdReference'
.
freeze
disable_ddl_transaction!
disable_ddl_transaction!
...
@@ -10,9 +12,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
...
@@ -10,9 +12,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
end
end
def
up
def
up
Build
.
find_each
do
|
build
|
Build
.
find_in_batches
(
batch_size:
BATCH_SIZE
).
with_index
do
|
builds
,
batch
|
BackgroundMigrationWorker
migrations
=
builds
.
map
{
|
build
|
[
MIGRATION
,
[
build
.
id
]]
}
.
perform_async
(
'MigrateBuildStageIdReference'
,
[
build
.
id
])
BackgroundMigrationWorker
.
perform_bulk
(
*
migrations
)
end
end
end
end
...
...
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
View file @
9a32ca40
...
@@ -8,6 +8,8 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
...
@@ -8,6 +8,8 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:projects
)
{
table
(
:projects
)
}
before
do
before
do
stub_const
(
'MigrateStageIdReferenceInBackground::BATCH_SIZE'
,
1
)
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
...
...
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