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
b55aad4c
Commit
b55aad4c
authored
Jun 06, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate stages only with correct foreign references
parent
559521ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
+23
-4
db/post_migrate/20170526185842_migrate_pipeline_stages.rb
db/post_migrate/20170526185842_migrate_pipeline_stages.rb
+4
-1
spec/migrations/migrate_build_stage_reference_spec.rb
spec/migrations/migrate_build_stage_reference_spec.rb
+7
-0
spec/migrations/migrate_pipeline_stages_spec.rb
spec/migrations/migrate_pipeline_stages_spec.rb
+12
-3
No files found.
db/post_migrate/20170526185842_migrate_pipeline_stages.rb
View file @
b55aad4c
...
...
@@ -11,7 +11,10 @@ class MigratePipelineStages < ActiveRecord::Migration
execute
<<-
SQL
.
strip_heredoc
INSERT INTO ci_stages (project_id, pipeline_id, name)
SELECT project_id, commit_id, stage FROM ci_builds
WHERE stage IS NOT NULL AND stage_id IS NULL
WHERE stage IS NOT NULL
AND stage_id IS NULL
AND EXISTS (SELECT 1 FROM projects WHERE projects.id = ci_builds.project_id)
AND EXISTS (SELECT 1 FROM ci_pipelines WHERE ci_pipelines.id = ci_builds.commit_id)
GROUP BY project_id, commit_id, stage
ORDER BY MAX(stage_idx)
SQL
...
...
spec/migrations/migrate_build_stage_reference_spec.rb
View file @
b55aad4c
...
...
@@ -9,8 +9,15 @@ describe MigrateBuildStageReference, :migration do
let
(
:jobs
)
{
table
(
:ci_builds
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
let
(
:projects
)
{
table
(
:projects
)
}
before
do
# Create projects
#
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
456
,
name:
'gitlab2'
,
path:
'gitlab2'
)
projects
.
create!
(
id:
798
,
name:
'gitlab3'
,
path:
'gitlab3'
)
# Create CI/CD pipelines
#
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
...
...
spec/migrations/migrate_pipeline_stages_spec.rb
View file @
b55aad4c
...
...
@@ -9,8 +9,14 @@ describe MigratePipelineStages, :migration do
let
(
:jobs
)
{
table
(
:ci_builds
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
let
(
:projects
)
{
table
(
:projects
)
}
before
do
# Create projects
#
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
456
,
name:
'gitlab2'
,
path:
'gitlab2'
)
# Create CI/CD pipelines
#
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
...
...
@@ -28,7 +34,8 @@ describe MigratePipelineStages, :migration do
jobs
.
create!
(
id:
8
,
commit_id:
2
,
project_id:
456
,
stage_idx:
1
,
stage:
'test:1'
)
jobs
.
create!
(
id:
9
,
commit_id:
2
,
project_id:
456
,
stage_idx:
1
,
stage:
'test:1'
)
jobs
.
create!
(
id:
10
,
commit_id:
2
,
project_id:
456
,
stage_idx:
2
,
stage:
'test:2'
)
jobs
.
create!
(
id:
11
,
commit_id:
3
,
project_id:
789
,
stage_idx:
3
,
stage:
'deploy'
)
jobs
.
create!
(
id:
11
,
commit_id:
3
,
project_id:
456
,
stage_idx:
3
,
stage:
'deploy'
)
jobs
.
create!
(
id:
12
,
commit_id:
2
,
project_id:
789
,
stage_idx:
3
,
stage:
'deploy'
)
end
it
'correctly migrates pipeline stages'
do
...
...
@@ -36,12 +43,14 @@ describe MigratePipelineStages, :migration do
migrate!
expect
(
stages
.
count
).
to
eq
7
expect
(
stages
.
count
).
to
eq
6
expect
(
stages
.
all
.
pluck
(
:name
))
.
to
match_array
%w[test build deploy test:1 test:2 deploy
deploy
]
.
to
match_array
%w[test build deploy test:1 test:2 deploy]
expect
(
stages
.
where
(
pipeline_id:
1
).
order
(
:id
).
pluck
(
:name
))
.
to
eq
%w[test build deploy]
expect
(
stages
.
where
(
pipeline_id:
2
).
order
(
:id
).
pluck
(
:name
))
.
to
eq
%w[test:1 test:2 deploy]
expect
(
stages
.
where
(
pipeline_id:
3
).
count
).
to
be_zero
expect
(
stages
.
where
(
project_id:
789
).
count
).
to
be_zero
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