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
Léo-Paul Géneau
gitlab-ce
Commits
9c7c95c7
Commit
9c7c95c7
authored
7 years ago
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial changes for stages statuses migration
parent
81dba76b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
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
No files found.
db/migrate/20170630105320_add_status_to_ci_stages.rb
0 → 100644
View file @
9c7c95c7
class
AddStatusToCiStages
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:ci_stages
,
:status
,
:integer
end
end
This diff is collapsed.
Click to expand it.
db/post_migrate/20170630111158_migrate_stages_statuses.rb
0 → 100644
View file @
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
This diff is collapsed.
Click to expand it.
db/schema.rb
View file @
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
...
...
This diff is collapsed.
Click to expand it.
spec/migrations/migrate_stages_statuses_spec.rb
0 → 100644
View file @
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
This diff is collapsed.
Click to expand it.
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