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
Boxiang Sun
gitlab-ce
Commits
cffb3e68
Commit
cffb3e68
authored
May 07, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup pipeline build stage background migration
parent
965d0394
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
db/migrate/20180420010616_cleanup_build_stage_migration.rb
db/migrate/20180420010616_cleanup_build_stage_migration.rb
+28
-0
spec/migrations/cleanup_build_stage_migration_spec.rb
spec/migrations/cleanup_build_stage_migration_spec.rb
+53
-0
No files found.
db/migrate/20180420010616_cleanup_build_stage_migration.rb
0 → 100644
View file @
cffb3e68
class
CleanupBuildStageMigration
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
class
Build
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
end
def
up
Gitlab
::
BackgroundMigration
.
steal
(
'MigrateBuildStage'
)
Build
.
where
(
'stage_id IS NULL'
).
each_batch
(
of:
50
)
do
|
batch
|
range
=
batch
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
Gitlab
::
BackgroundMigration
::
MigrateBuildStage
.
new
.
perform
(
*
range
)
end
end
def
down
# noop
end
end
spec/migrations/cleanup_build_stage_migration_spec.rb
0 → 100644
View file @
cffb3e68
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20180420010616_cleanup_build_stage_migration.rb'
)
describe
CleanupBuildStageMigration
,
:migration
,
:sidekiq
,
:redis
do
let
(
:migration
)
{
spy
(
'migration'
)
}
before
do
allow
(
Gitlab
::
BackgroundMigration
::
MigrateBuildStage
)
.
to
receive
(
:new
).
and_return
(
migration
)
end
context
'when there are pending background migrations'
do
it
'processes pending jobs synchronously'
do
Sidekiq
::
Testing
.
disable!
do
BackgroundMigrationWorker
.
perform_in
(
2
.
minutes
,
'MigrateBuildStage'
,
[
1
,
1
])
BackgroundMigrationWorker
.
perform_async
(
'MigrateBuildStage'
,
[
1
,
1
])
migrate!
expect
(
migration
).
to
have_received
(
:perform
).
with
(
1
,
1
).
twice
end
end
end
context
'when there are no background migrations pending'
do
it
'does nothing'
do
Sidekiq
::
Testing
.
disable!
do
migrate!
expect
(
migration
).
not_to
have_received
(
:perform
)
end
end
end
context
'when there are still unmigrated builds present'
do
let
(
:builds
)
{
table
(
'ci_builds'
)
}
before
do
builds
.
create!
(
name:
'test:1'
,
ref:
'master'
)
builds
.
create!
(
name:
'test:2'
,
ref:
'master'
)
end
it
'migrates stages sequentially in batches'
do
expect
(
builds
.
all
).
to
all
(
have_attributes
(
stage_id:
nil
))
migrate!
expect
(
migration
).
to
have_received
(
:perform
).
once
end
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