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
d7f1dd14
Commit
d7f1dd14
authored
Sep 30, 2018
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-09-30
parents
9e8c4c66
2155ba8b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
171 additions
and
0 deletions
+171
-0
changelogs/unreleased/51651-fill-pipeline-source-for-external-pipelines.yml
...sed/51651-fill-pipeline-source-for-external-pipelines.yml
+5
-0
db/migrate/20180916011959_add_index_pipelines_project_id_source.rb
...e/20180916011959_add_index_pipelines_project_id_source.rb
+20
-0
db/post_migrate/20180916014356_populate_external_pipeline_source.rb
...grate/20180916014356_populate_external_pipeline_source.rb
+33
-0
db/schema.rb
db/schema.rb
+1
-0
lib/gitlab/background_migration/populate_external_pipeline_source.rb
...background_migration/populate_external_pipeline_source.rb
+50
-0
spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb
...round_migration/populate_external_pipeline_source_spec.rb
+62
-0
No files found.
changelogs/unreleased/51651-fill-pipeline-source-for-external-pipelines.yml
0 → 100644
View file @
d7f1dd14
---
title
:
Retroactively fill pipeline source for external pipelines.
merge_request
:
21814
author
:
type
:
other
db/migrate/20180916011959_add_index_pipelines_project_id_source.rb
0 → 100644
View file @
d7f1dd14
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddIndexPipelinesProjectIdSource
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:ci_pipelines
,
[
:project_id
,
:source
]
end
def
down
remove_concurrent_index
:ci_pipelines
,
[
:project_id
,
:source
]
end
end
db/post_migrate/20180916014356_populate_external_pipeline_source.rb
0 → 100644
View file @
d7f1dd14
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
PopulateExternalPipelineSource
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
MIGRATION
=
'PopulateExternalPipelineSource'
.
freeze
BATCH_SIZE
=
500
disable_ddl_transaction!
class
Pipeline
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'ci_pipelines'
end
def
up
Pipeline
.
where
(
source:
nil
).
tap
do
|
relation
|
queue_background_migration_jobs_by_range_at_intervals
(
relation
,
MIGRATION
,
5
.
minutes
,
batch_size:
BATCH_SIZE
)
end
end
def
down
# noop
end
end
db/schema.rb
View file @
d7f1dd14
...
...
@@ -579,6 +579,7 @@ ActiveRecord::Schema.define(version: 20180920043317) do
add_index
"ci_pipelines"
,
[
"project_id"
,
"iid"
],
name:
"index_ci_pipelines_on_project_id_and_iid"
,
unique:
true
,
where:
"(iid IS NOT NULL)"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
,
"ref"
,
"status"
,
"id"
],
name:
"index_ci_pipelines_on_project_id_and_ref_and_status_and_id"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
,
"sha"
],
name:
"index_ci_pipelines_on_project_id_and_sha"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
,
"source"
],
name:
"index_ci_pipelines_on_project_id_and_source"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
,
"status"
,
"config_source"
],
name:
"index_ci_pipelines_on_project_id_and_status_and_config_source"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
],
name:
"index_ci_pipelines_on_project_id"
,
using: :btree
add_index
"ci_pipelines"
,
[
"status"
],
name:
"index_ci_pipelines_on_status"
,
using: :btree
...
...
lib/gitlab/background_migration/populate_external_pipeline_source.rb
0 → 100644
View file @
d7f1dd14
# 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
scope
:has_pipeline
,
->
{
where
(
'ci_builds.commit_id=ci_pipelines.id'
)
}
scope
:of_type
,
->
(
type
)
{
where
(
'type=?'
,
type
)
}
end
end
def
perform
(
start_id
,
stop_id
)
external_pipelines
(
start_id
,
stop_id
)
.
update_all
(
source:
Migratable
::
Pipeline
.
sources
[
:external
])
end
private
def
external_pipelines
(
start_id
,
stop_id
)
Migratable
::
Pipeline
.
where
(
id:
(
start_id
..
stop_id
))
.
where
(
'EXISTS (?) AND NOT EXISTS (?)'
,
Migratable
::
CommitStatus
.
of_type
(
'GenericCommitStatus'
).
has_pipeline
.
select
(
1
),
Migratable
::
CommitStatus
.
of_type
(
'Ci::Build'
).
has_pipeline
.
select
(
1
)
)
end
end
end
end
spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb
0 → 100644
View file @
d7f1dd14
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
PopulateExternalPipelineSource
,
:migration
,
schema:
20180916011959
do
let
(
:migration
)
{
described_class
.
new
}
let!
(
:internal_pipeline
)
{
create
(
:ci_pipeline
,
source: :web
)
}
let
(
:pipelines
)
{
[
internal_pipeline
,
unknown_pipeline
].
map
(
&
:id
)
}
let!
(
:unknown_pipeline
)
do
build
(
:ci_pipeline
,
source: :unknown
)
.
tap
{
|
pipeline
|
pipeline
.
save
(
validate:
false
)
}
end
subject
{
migration
.
perform
(
pipelines
.
min
,
pipelines
.
max
)
}
shared_examples
'no changes'
do
it
'does not change the pipeline source'
do
expect
{
subject
}.
not_to
change
{
unknown_pipeline
.
reload
.
source
}
end
end
context
'when unknown pipeline is external'
do
before
do
create
(
:generic_commit_status
,
pipeline:
unknown_pipeline
)
end
it
'populates the pipeline source'
do
subject
expect
(
unknown_pipeline
.
reload
.
source
).
to
eq
(
'external'
)
end
it
'can be repeated without effect'
do
subject
expect
{
subject
}.
not_to
change
{
unknown_pipeline
.
reload
.
source
}
end
end
context
'when unknown pipeline has just a build'
do
before
do
create
(
:ci_build
,
pipeline:
unknown_pipeline
)
end
it_behaves_like
'no changes'
end
context
'when unknown pipeline has no statuses'
do
it_behaves_like
'no changes'
end
context
'when unknown pipeline has a build and a status'
do
before
do
create
(
:generic_commit_status
,
pipeline:
unknown_pipeline
)
create
(
:ci_build
,
pipeline:
unknown_pipeline
)
end
it_behaves_like
'no changes'
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