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
d60ce6e9
Commit
d60ce6e9
authored
Jul 04, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement initial working stages statuses migration
parent
7103c4a7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
32 deletions
+25
-32
20170630111158_migrate_stages_statuses.rb
db/post_migrate/20170630111158_migrate_stages_statuses.rb
+15
-21
migrate_stages_statuses_spec.rb
spec/migrations/migrate_stages_statuses_spec.rb
+10
-11
No files found.
db/post_migrate/20170630111158_migrate_stages_statuses.rb
View file @
d60ce6e9
...
@@ -48,34 +48,31 @@ class MigrateStagesStatuses < ActiveRecord::Migration
...
@@ -48,34 +48,31 @@ class MigrateStagesStatuses < ActiveRecord::Migration
canceled
=
scope_relevant
.
canceled
.
select
(
'count(*)'
).
to_sql
canceled
=
scope_relevant
.
canceled
.
select
(
'count(*)'
).
to_sql
warnings
=
scope_warnings
.
select
(
'count(*) > 0'
).
to_sql
warnings
=
scope_warnings
.
select
(
'count(*) > 0'
).
to_sql
"(CASE
<<-
SQL
.
strip_heredoc
WHEN (
#{
builds
}
)=(
#{
skipped
}
) AND (
#{
warnings
}
) THEN
#{
STATUSES
[
:success
]
}
(CASE
WHEN (
#{
builds
}
)=(
#{
skipped
}
) THEN
#{
STATUSES
[
:skipped
]
}
WHEN (
#{
builds
}
) = (
#{
skipped
}
) AND (
#{
warnings
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
)=(
#{
success
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
) = (
#{
skipped
}
) THEN
#{
STATUSES
[
:skipped
]
}
WHEN (
#{
builds
}
)=(
#{
created
}
) THEN
#{
STATUSES
[
:created
]
}
WHEN (
#{
builds
}
) = (
#{
success
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
) = (
#{
created
}
) THEN
#{
STATUSES
[
:created
]
}
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
)+(
#{
canceled
}
) THEN
#{
STATUSES
[
:canceled
]
}
WHEN (
#{
builds
}
) = (
#{
success
}
) + (
#{
skipped
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
)=(
#{
created
}
)+(
#{
skipped
}
)+(
#{
pending
}
) THEN
#{
STATUSES
[
:pending
]
}
WHEN (
#{
builds
}
) = (
#{
success
}
) + (
#{
skipped
}
) + (
#{
canceled
}
) THEN
#{
STATUSES
[
:canceled
]
}
WHEN (
#{
running
}
)+(
#{
pending
}
)>0 THEN '
#{
STATUSES
[
:running
]
}
WHEN (
#{
builds
}
) = (
#{
created
}
) + (
#{
skipped
}
) + (
#{
pending
}
) THEN
#{
STATUSES
[
:pending
]
}
WHEN (
#{
manual
}
)>0 THEN
#{
STATUSES
[
:manual
]
}
WHEN (
#{
running
}
) + (
#{
pending
}
) > 0 THEN
#{
STATUSES
[
:running
]
}
WHEN (
#{
created
}
)>0 THEN
#{
STATUSES
[
:running
]
}
WHEN (
#{
manual
}
) > 0 THEN
#{
STATUSES
[
:manual
]
}
WHEN (
#{
created
}
) > 0 THEN
#{
STATUSES
[
:running
]
}
ELSE
#{
STATUSES
[
:failed
]
}
ELSE
#{
STATUSES
[
:failed
]
}
END)"
END)
SQL
end
end
end
end
def
up
def
up
Stage
.
all
.
in_batches
(
of:
10000
)
do
|
relation
|
status_sql
=
Build
status_sql
=
Build
.
where
(
'ci_builds.commit_id = ci_stages.pipeline_id'
)
.
where
(
'ci_builds.commit_id = ci_stages.pipeline_id'
)
.
where
(
'ci_builds.stage = ci_stages.name'
)
.
where
(
'ci_builds.stage = ci_stages.name'
)
.
status_sql
.
status_sql
execute
<<-
SQL
.
strip_heredoc
update_column_in_batches
(
:ci_stages
,
:status
,
Arel
.
sql
(
"(
#{
status_sql
}
)"
))
UPDATE ci_stages SET status =
#{
status_sql
}
WHERE id = (
#{
relation
.
select
(
:id
).
to_sql
}
)
SQL
end
end
end
def
down
def
down
...
@@ -83,7 +80,4 @@ class MigrateStagesStatuses < ActiveRecord::Migration
...
@@ -83,7 +80,4 @@ class MigrateStagesStatuses < ActiveRecord::Migration
UPDATE ci_stages SET status = null
UPDATE ci_stages SET status = null
SQL
SQL
end
end
private
end
end
spec/migrations/migrate_stages_statuses_spec.rb
View file @
d60ce6e9
...
@@ -15,36 +15,35 @@ describe MigrateStagesStatuses, :migration do
...
@@ -15,36 +15,35 @@ describe MigrateStagesStatuses, :migration do
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
2
,
name:
'gitlab2'
,
path:
'gitlab2'
)
projects
.
create!
(
id:
2
,
name:
'gitlab2'
,
path:
'gitlab2'
)
pipelines
.
create!
(
id:
1
,
project_id:
1
23
,
ref:
'master'
,
sha:
'adf43c3a'
)
pipelines
.
create!
(
id:
1
,
project_id:
1
,
ref:
'master'
,
sha:
'adf43c3a'
)
pipelines
.
create!
(
id:
2
,
project_id:
456
,
ref:
'feature'
,
sha:
'21a3deb'
)
pipelines
.
create!
(
id:
2
,
project_id:
2
,
ref:
'feature'
,
sha:
'21a3deb'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'test'
,
status:
'success'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'test'
,
status:
'success'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'test'
,
status:
'running'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'test'
,
status:
'running'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'build'
,
status:
'success'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'build'
,
status:
'success'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'build'
,
status:
'failed'
)
create_job
(
project:
1
,
pipeline:
1
,
stage:
'build'
,
status:
'failed'
)
create_job
(
project:
2
,
pipeline:
2
,
stage:
'test'
,
status:
'success'
)
create_job
(
project:
2
,
pipeline:
2
,
stage:
'test'
,
status:
'success'
)
create_job
(
project:
2
,
pipeline:
2
,
stage:
'test'
,
status:
'succ
c
ss'
)
create_job
(
project:
2
,
pipeline:
2
,
stage:
'test'
,
status:
'succ
e
ss'
)
stages
.
create!
(
id:
1
,
pipeline_id:
1
,
project_id:
1
,
status:
nil
)
stages
.
create!
(
id:
1
,
pipeline_id:
1
,
project_id:
1
,
name:
'test'
,
status:
nil
)
stages
.
create!
(
id:
2
,
pipeline_id:
1
,
project_id:
1
,
status:
nil
)
stages
.
create!
(
id:
2
,
pipeline_id:
1
,
project_id:
1
,
name:
'build'
,
status:
nil
)
stages
.
create!
(
id:
3
,
pipeline_id:
2
,
project_id:
2
,
status:
nil
)
stages
.
create!
(
id:
3
,
pipeline_id:
2
,
project_id:
2
,
name:
'test'
,
status:
nil
)
end
end
pending
'correctly migrates stages statuses'
do
it
'correctly migrates stages statuses'
do
expect
(
stages
.
where
(
status:
nil
).
count
).
to
eq
3
expect
(
stages
.
where
(
status:
nil
).
count
).
to
eq
3
migrate!
migrate!
expect
(
stages
.
where
(
status:
nil
)).
to
be_empty
expect
(
stages
.
where
(
status:
nil
)).
to
be_empty
expect
(
stages
.
all
.
order
(
:id
,
:asc
).
pluck
(
:stage
))
expect
(
stages
.
all
.
order
(
'id ASC'
).
pluck
(
:status
))
.
to
eq
%w[running success failed
]
.
to
eq
[
STATUSES
[
:running
],
STATUSES
[
:failed
],
STATUSES
[
:success
]
]
end
end
def
create_job
(
project
:,
pipeline
:,
stage
:,
status
:)
def
create_job
(
project
:,
pipeline
:,
stage
:,
status
:)
stage_idx
=
STAGES
[
stage
.
to_sym
]
stage_idx
=
STAGES
[
stage
.
to_sym
]
status_id
=
STATUSES
[
status
.
to_sym
]
jobs
.
create!
(
project_id:
project
,
commit_id:
pipeline
,
jobs
.
create!
(
project_id:
project
,
commit_id:
pipeline
,
stage_idx:
stage_idx
,
stage:
stage
,
status:
status
_id
)
stage_idx:
stage_idx
,
stage:
stage
,
status:
status
)
end
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