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
c2fbd867
Commit
c2fbd867
authored
Sep 19, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add background migration to fill pipeline source
parent
97fbc2e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
0 deletions
+89
-0
lib/gitlab/background_migration/populate_external_pipeline_source.rb
...background_migration/populate_external_pipeline_source.rb
+54
-0
spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb
...round_migration/populate_external_pipeline_source_spec.rb
+35
-0
No files found.
lib/gitlab/background_migration/populate_external_pipeline_source.rb
0 → 100644
View file @
c2fbd867
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module
Gitlab
module
BackgroundMigration
class
PopulateExternalPipelineSource
module
Migratable
class
Pipeline
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_pipelines'
def
self
.
sources
{
unknown:
nil
,
push:
1
,
web:
2
,
trigger:
3
,
schedule:
4
,
api:
5
,
external:
6
}
end
end
class
CommitStatus
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
end
class
Build
<
CommitStatus
end
class
GenericCommitStatus
<
CommitStatus
end
end
def
perform
(
start_id
,
stop_id
)
external_pipelines
(
start_id
,
stop_id
).
each
do
|
pipeline
|
pipeline
.
update_attribute
(
:source
,
Migratable
::
Pipeline
.
sources
[
:external
])
end
end
private
def
external_pipelines
(
start_id
,
stop_id
)
Migratable
::
Pipeline
.
where
(
id:
(
start_id
..
stop_id
))
.
where
(
'EXISTS (?) AND NOT EXISTS (?)'
,
Migratable
::
GenericCommitStatus
.
where
(
"type='CommitStatus'"
).
where
(
'ci_builds.commit_id=ci_pipelines.id'
).
select
(
1
),
Migratable
::
Build
.
where
(
"type='Ci::Build'"
).
where
(
'ci_builds.commit_id=ci_pipelines.id'
).
select
(
1
)
)
end
end
end
end
spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb
0 → 100644
View file @
c2fbd867
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
PopulateExternalPipelineSource
,
:migration
,
schema:
20180916011959
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
let
(
:statuses
)
{
table
(
:ci_builds
)
}
let
(
:builds
)
{
table
(
:ci_builds
)
}
let!
(
:internal_pipeline
)
{
pipelines
.
create
(
id:
1
,
source:
described_class
::
Migratable
::
Pipeline
.
sources
[
:web
])
}
let!
(
:external_pipeline
)
{
pipelines
.
create
(
id:
2
,
source:
nil
)
}
let!
(
:second_external_pipeline
)
{
pipelines
.
create
(
id:
3
,
source:
nil
)
}
let!
(
:status
)
{
statuses
.
create
(
id:
1
,
commit_id:
2
,
type:
'CommitStatus'
)
}
let!
(
:build
)
{
builds
.
create
(
id:
2
,
commit_id:
1
,
type:
'Ci::Build'
)
}
subject
{
migration
.
perform
(
1
,
2
)
}
it
'populates the pipeline source'
do
subject
expect
(
external_pipeline
.
reload
.
source
).
to
eq
(
described_class
::
Migratable
::
Pipeline
.
sources
[
:external
])
end
it
'only processes a single batch of links at a time'
do
subject
expect
(
second_external_pipeline
.
reload
.
source
).
to
eq
(
nil
)
end
it
'can be repeated without effect'
do
subject
expect
{
subject
}.
not_to
change
{
external_pipeline
.
reload
.
source
}
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