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
7103c4a7
Commit
7103c4a7
authored
Jul 04, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend stages statuses migration
parent
9c7c95c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
21 deletions
+34
-21
db/post_migrate/20170630111158_migrate_stages_statuses.rb
db/post_migrate/20170630111158_migrate_stages_statuses.rb
+34
-21
No files found.
db/post_migrate/20170630111158_migrate_stages_statuses.rb
View file @
7103c4a7
...
...
@@ -5,13 +5,17 @@ class MigrateStagesStatuses < ActiveRecord::Migration
disable_ddl_transaction!
STATUSES
=
{
created:
0
,
pending:
1
,
running:
2
,
success:
3
,
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
}
class
Stage
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_stages'
end
class
Build
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
scope
:relevant
,
->
do
where
(
status:
%w[pending running success failed canceled skipped manual]
)
end
scope
:latest
,
->
{
where
(
retried:
[
false
,
nil
])
}
scope
:created
,
->
{
where
(
status:
'created'
)
}
scope
:running
,
->
{
where
(
status:
'running'
)
}
scope
:pending
,
->
{
where
(
status:
'pending'
)
}
...
...
@@ -27,12 +31,12 @@ class MigrateStagesStatuses < ActiveRecord::Migration
scope
:exclude_ignored
,
->
do
where
(
"allow_failure = ? OR status IN (?)"
,
false
,
all_state_names
-
[
:failed
,
:canceled
,
:manual
])
false
,
%w[created pending running success skipped
]
)
end
def
status_sql
scope_relevant
=
relevan
t
.
exclude_ignored
scope_warnings
=
relevan
t
.
failed_but_allowed
def
s
elf
.
s
tatus_sql
scope_relevant
=
lates
t
.
exclude_ignored
scope_warnings
=
lates
t
.
failed_but_allowed
builds
=
scope_relevant
.
select
(
'count(*)'
).
to_sql
created
=
scope_relevant
.
created
.
select
(
'count(*)'
).
to_sql
...
...
@@ -45,24 +49,33 @@ class MigrateStagesStatuses < ActiveRecord::Migration
warnings
=
scope_warnings
.
select
(
'count(*) > 0'
).
to_sql
"(CASE
WHEN (
#{
builds
}
)=(
#{
skipped
}
) AND (
#{
warnings
}
) THEN
'success'
WHEN (
#{
builds
}
)=(
#{
skipped
}
) THEN
'skipped'
WHEN (
#{
builds
}
)=(
#{
success
}
) THEN
'success'
WHEN (
#{
builds
}
)=(
#{
created
}
) THEN
'created'
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
) THEN
'success'
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
)+(
#{
canceled
}
) THEN
'canceled'
WHEN (
#{
builds
}
)=(
#{
created
}
)+(
#{
skipped
}
)+(
#{
pending
}
) THEN
'pending'
WHEN (
#{
running
}
)+(
#{
pending
}
)>0 THEN '
running'
WHEN (
#{
manual
}
)>0 THEN
'manual'
WHEN (
#{
created
}
)>0 THEN
'running'
ELSE
'failed'
WHEN (
#{
builds
}
)=(
#{
skipped
}
) AND (
#{
warnings
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
)=(
#{
skipped
}
) THEN
#{
STATUSES
[
:skipped
]
}
WHEN (
#{
builds
}
)=(
#{
success
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
)=(
#{
created
}
) THEN
#{
STATUSES
[
:created
]
}
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
) THEN
#{
STATUSES
[
:success
]
}
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
)+(
#{
canceled
}
) THEN
#{
STATUSES
[
:canceled
]
}
WHEN (
#{
builds
}
)=(
#{
created
}
)+(
#{
skipped
}
)+(
#{
pending
}
) THEN
#{
STATUSES
[
:pending
]
}
WHEN (
#{
running
}
)+(
#{
pending
}
)>0 THEN '
#{
STATUSES
[
:running
]
}
WHEN (
#{
manual
}
)>0 THEN
#{
STATUSES
[
:manual
]
}
WHEN (
#{
created
}
)>0 THEN
#{
STATUSES
[
:running
]
}
ELSE
#{
STATUSES
[
:failed
]
}
END)"
end
end
def
up
execute
<<-
SQL
.
strip_heredoc
SQL
Stage
.
all
.
in_batches
(
of:
10000
)
do
|
relation
|
status_sql
=
Build
.
where
(
'ci_builds.commit_id = ci_stages.pipeline_id'
)
.
where
(
'ci_builds.stage = ci_stages.name'
)
.
status_sql
execute
<<-
SQL
.
strip_heredoc
UPDATE ci_stages SET status =
#{
status_sql
}
WHERE id = (
#{
relation
.
select
(
:id
).
to_sql
}
)
SQL
end
end
def
down
...
...
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