BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
33a0fd99
Commit
33a0fd99
authored
May 26, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate build stage reference in a separate migration
parent
b8c39649
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
11 deletions
+78
-11
20170526101042_migrate_pipeline_stages.rb
db/post_migrate/20170526101042_migrate_pipeline_stages.rb
+0
-8
20170526185921_migrate_build_stage_reference.rb
...t_migrate/20170526185921_migrate_build_stage_reference.rb
+21
-0
schema.rb
db/schema.rb
+1
-1
migrate_build_stage_reference_spec.rb
spec/migrations/migrate_build_stage_reference_spec.rb
+56
-0
migrate_pipeline_stages_spec.rb
spec/migrations/migrate_pipeline_stages_spec.rb
+0
-2
No files found.
db/post_migrate/20170526101042_migrate_pipeline_stages.rb
View file @
33a0fd99
...
...
@@ -15,14 +15,6 @@ class MigratePipelineStages < ActiveRecord::Migration
GROUP BY project_id, commit_id, stage, stage_idx
ORDER BY stage_idx
SQL
stage_id
=
Arel
.
sql
(
'(SELECT id FROM ci_stages '
\
'WHERE ci_stages.pipeline_id = ci_builds.commit_id '
\
'AND ci_stages.name = ci_builds.stage)'
)
update_column_in_batches
(
:ci_builds
,
:stage_id
,
stage_id
)
# add_concurrent_foreign_key :ci_stages, :projects, column: :project_id, on_delete: :cascade
# add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade
end
def
down
...
...
db/post_migrate/20170526185921_migrate_build_stage_reference.rb
0 → 100644
View file @
33a0fd99
class
MigrateBuildStageReference
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
disable_statement_timeout
stage_id
=
Arel
.
sql
(
'(SELECT id FROM ci_stages '
\
'WHERE ci_stages.pipeline_id = ci_builds.commit_id '
\
'AND ci_stages.name = ci_builds.stage)'
)
update_column_in_batches
(
:ci_builds
,
:stage_id
,
stage_id
)
end
def
down
disable_statement_timeout
update_column_in_batches
(
:ci_builds
,
:stage_id
,
nil
)
end
end
db/schema.rb
View file @
33a0fd99
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201705261
01042
)
do
ActiveRecord
::
Schema
.
define
(
version:
201705261
85921
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
spec/migrations/migrate_build_stage_reference_spec.rb
0 → 100644
View file @
33a0fd99
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170526185921_migrate_build_stage_reference.rb'
)
describe
MigrateBuildStageReference
,
:migration
,
schema:
20170526185602
do
##
# Create test data - pipeline and CI/CD jobs.
#
let
(
:jobs
)
{
table
(
:ci_builds
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
before
do
# Create CI/CD pipelines
#
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
pipelines
.
create!
(
id:
2
,
project_id:
456
,
ref:
'feature'
,
sha:
'21a3deb'
)
# Create CI/CD jobs
#
jobs
.
create!
(
id:
1
,
commit_id:
1
,
project_id:
123
,
stage_idx:
2
,
stage:
'build'
)
jobs
.
create!
(
id:
2
,
commit_id:
1
,
project_id:
123
,
stage_idx:
2
,
stage:
'build'
)
jobs
.
create!
(
id:
3
,
commit_id:
1
,
project_id:
123
,
stage_idx:
1
,
stage:
'test'
)
jobs
.
create!
(
id:
4
,
commit_id:
1
,
project_id:
123
,
stage_idx:
3
,
stage:
'deploy'
)
jobs
.
create!
(
id:
5
,
commit_id:
2
,
project_id:
456
,
stage_idx:
2
,
stage:
'test:2'
)
jobs
.
create!
(
id:
6
,
commit_id:
2
,
project_id:
456
,
stage_idx:
1
,
stage:
'test:1'
)
jobs
.
create!
(
id:
7
,
commit_id:
2
,
project_id:
456
,
stage_idx:
1
,
stage:
'test:1'
)
jobs
.
create!
(
id:
8
,
commit_id:
3
,
project_id:
789
,
stage_idx:
3
,
stage:
'deploy'
)
# Create CI/CD stages
#
stages
.
create
(
id:
101
,
pipeline_id:
1
,
project_id:
123
,
name:
'test'
)
stages
.
create
(
id:
102
,
pipeline_id:
1
,
project_id:
123
,
name:
'build'
)
stages
.
create
(
id:
103
,
pipeline_id:
1
,
project_id:
123
,
name:
'deploy'
)
stages
.
create
(
id:
104
,
pipeline_id:
2
,
project_id:
456
,
name:
'test:1'
)
stages
.
create
(
id:
105
,
pipeline_id:
2
,
project_id:
456
,
name:
'test:2'
)
stages
.
create
(
id:
106
,
pipeline_id:
2
,
project_id:
456
,
name:
'deploy'
)
end
it
'correctly migrate build stage references'
do
expect
(
jobs
.
where
(
stage_id:
nil
).
count
).
to
eq
8
migrate!
expect
(
jobs
.
where
(
stage_id:
nil
).
count
).
to
eq
1
expect
(
jobs
.
find
(
1
).
stage_id
).
to
eq
102
expect
(
jobs
.
find
(
2
).
stage_id
).
to
eq
102
expect
(
jobs
.
find
(
3
).
stage_id
).
to
eq
101
expect
(
jobs
.
find
(
4
).
stage_id
).
to
eq
103
expect
(
jobs
.
find
(
5
).
stage_id
).
to
eq
105
expect
(
jobs
.
find
(
6
).
stage_id
).
to
eq
104
expect
(
jobs
.
find
(
7
).
stage_id
).
to
eq
104
expect
(
jobs
.
find
(
8
).
stage_id
).
to
eq
nil
end
end
spec/migrations/migrate_pipeline_stages_spec.rb
View file @
33a0fd99
...
...
@@ -43,7 +43,5 @@ describe MigratePipelineStages, :migration, schema: 20170525132202 do
.
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
(
jobs
.
where
(
stage_id:
nil
)).
to
be_empty
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