Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9c7c95c7
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9c7c95c7
编写于
6月 30, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add initial changes for stages statuses migration
上级
81dba76b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
137 addition
and
1 deletion
+137
-1
db/migrate/20170630105320_add_status_to_ci_stages.rb
db/migrate/20170630105320_add_status_to_ci_stages.rb
+9
-0
db/post_migrate/20170630111158_migrate_stages_statuses.rb
db/post_migrate/20170630111158_migrate_stages_statuses.rb
+76
-0
db/schema.rb
db/schema.rb
+2
-1
spec/migrations/migrate_stages_statuses_spec.rb
spec/migrations/migrate_stages_statuses_spec.rb
+50
-0
未找到文件。
db/migrate/20170630105320_add_status_to_ci_stages.rb
0 → 100644
浏览文件 @
9c7c95c7
class
AddStatusToCiStages
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:ci_stages
,
:status
,
:integer
end
end
db/post_migrate/20170630111158_migrate_stages_statuses.rb
0 → 100644
浏览文件 @
9c7c95c7
class
MigrateStagesStatuses
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
class
Build
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
scope
:relevant
,
->
do
where
(
status:
%w[pending running success failed canceled skipped manual]
)
end
scope
:created
,
->
{
where
(
status:
'created'
)
}
scope
:running
,
->
{
where
(
status:
'running'
)
}
scope
:pending
,
->
{
where
(
status:
'pending'
)
}
scope
:success
,
->
{
where
(
status:
'success'
)
}
scope
:failed
,
->
{
where
(
status:
'failed'
)
}
scope
:canceled
,
->
{
where
(
status:
'canceled'
)
}
scope
:skipped
,
->
{
where
(
status:
'skipped'
)
}
scope
:manual
,
->
{
where
(
status:
'manual'
)
}
scope
:failed_but_allowed
,
->
do
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
])
end
scope
:exclude_ignored
,
->
do
where
(
"allow_failure = ? OR status IN (?)"
,
false
,
all_state_names
-
[
:failed
,
:canceled
,
:manual
])
end
def
status_sql
scope_relevant
=
relevant
.
exclude_ignored
scope_warnings
=
relevant
.
failed_but_allowed
builds
=
scope_relevant
.
select
(
'count(*)'
).
to_sql
created
=
scope_relevant
.
created
.
select
(
'count(*)'
).
to_sql
success
=
scope_relevant
.
success
.
select
(
'count(*)'
).
to_sql
manual
=
scope_relevant
.
manual
.
select
(
'count(*)'
).
to_sql
pending
=
scope_relevant
.
pending
.
select
(
'count(*)'
).
to_sql
running
=
scope_relevant
.
running
.
select
(
'count(*)'
).
to_sql
skipped
=
scope_relevant
.
skipped
.
select
(
'count(*)'
).
to_sql
canceled
=
scope_relevant
.
canceled
.
select
(
'count(*)'
).
to_sql
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'
END)"
end
end
def
up
execute
<<-
SQL
.
strip_heredoc
SQL
end
def
down
execute
<<-
SQL
.
strip_heredoc
UPDATE ci_stages SET status = null
SQL
end
private
end
db/schema.rb
浏览文件 @
9c7c95c7
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201706
22162730
)
do
ActiveRecord
::
Schema
.
define
(
version:
201706
30111158
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -337,6 +337,7 @@ ActiveRecord::Schema.define(version: 20170622162730) do
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"name"
t
.
integer
"status"
end
add_index
"ci_stages"
,
[
"pipeline_id"
,
"name"
],
name:
"index_ci_stages_on_pipeline_id_and_name"
,
using: :btree
...
...
spec/migrations/migrate_stages_statuses_spec.rb
0 → 100644
浏览文件 @
9c7c95c7
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170630111158_migrate_stages_statuses.rb'
)
describe
MigrateStagesStatuses
,
:migration
do
let
(
:jobs
)
{
table
(
:ci_builds
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
let
(
:projects
)
{
table
(
:projects
)
}
STATUSES
=
{
created:
0
,
pending:
1
,
running:
2
,
success:
3
,
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
}
STAGES
=
{
test:
1
,
build:
2
,
deploy:
3
}
before
do
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
2
,
name:
'gitlab2'
,
path:
'gitlab2'
)
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
pipelines
.
create!
(
id:
2
,
project_id:
456
,
ref:
'feature'
,
sha:
'21a3deb'
)
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:
'build'
,
status:
'success'
)
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:
'succcss'
)
stages
.
create!
(
id:
1
,
pipeline_id:
1
,
project_id:
1
,
status:
nil
)
stages
.
create!
(
id:
2
,
pipeline_id:
1
,
project_id:
1
,
status:
nil
)
stages
.
create!
(
id:
3
,
pipeline_id:
2
,
project_id:
2
,
status:
nil
)
end
pending
'correctly migrates stages statuses'
do
expect
(
stages
.
where
(
status:
nil
).
count
).
to
eq
3
migrate!
expect
(
stages
.
where
(
status:
nil
)).
to
be_empty
expect
(
stages
.
all
.
order
(
:id
,
:asc
).
pluck
(
:stage
))
.
to
eq
%w[running success failed]
end
def
create_job
(
project
:,
pipeline
:,
stage
:,
status
:)
stage_idx
=
STAGES
[
stage
.
to_sym
]
status_id
=
STATUSES
[
status
.
to_sym
]
jobs
.
create!
(
project_id:
project
,
commit_id:
pipeline
,
stage_idx:
stage_idx
,
stage:
stage
,
status:
status_id
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录