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
6714fbad
Commit
6714fbad
authored
Jan 19, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove redundant pipeline stages from the database
parent
e2a56af9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
1 deletion
+66
-1
db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
...igrate/20180119121225_remove_redundant_pipeline_stages.rb
+26
-0
db/schema.rb
db/schema.rb
+1
-1
spec/migrations/remove_redundant_pipeline_stages_spec.rb
spec/migrations/remove_redundant_pipeline_stages_spec.rb
+39
-0
No files found.
db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
0 → 100644
View file @
6714fbad
class
RemoveRedundantPipelineStages
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
redundant_stages_ids
=
<<~
SQL
SELECT id FROM ci_stages a WHERE (
SELECT COUNT(*) FROM ci_stages b
WHERE a.pipeline_id = b.pipeline_id AND a.name = b.name
) > 1
SQL
execute
<<~
SQL
UPDATE ci_builds SET stage_id = NULL WHERE ci_builds.stage_id IN (
#{
redundant_stages_ids
}
)
SQL
execute
<<~
SQL
DELETE FROM ci_stages WHERE ci_stages.id IN (
#{
redundant_stages_ids
}
)
SQL
end
def
down
# noop
end
end
db/schema.rb
View file @
6714fbad
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2018011
3220114
)
do
ActiveRecord
::
Schema
.
define
(
version:
2018011
9121225
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
spec/migrations/remove_redundant_pipeline_stages_spec.rb
0 → 100644
View file @
6714fbad
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20180119121225_remove_redundant_pipeline_stages.rb'
)
describe
RemoveRedundantPipelineStages
,
:migration
do
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:builds
)
{
table
(
:ci_builds
)
}
before
do
projects
.
create!
(
id:
123
,
name:
'gitlab'
,
path:
'gitlab-ce'
)
pipelines
.
create!
(
id:
234
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
stages
.
create!
(
id:
6
,
project_id:
123
,
pipeline_id:
234
,
name:
'build'
)
stages
.
create!
(
id:
10
,
project_id:
123
,
pipeline_id:
234
,
name:
'build'
)
stages
.
create!
(
id:
21
,
project_id:
123
,
pipeline_id:
234
,
name:
'build'
)
stages
.
create!
(
id:
41
,
project_id:
123
,
pipeline_id:
234
,
name:
'test'
)
stages
.
create!
(
id:
62
,
project_id:
123
,
pipeline_id:
234
,
name:
'test'
)
stages
.
create!
(
id:
102
,
project_id:
123
,
pipeline_id:
234
,
name:
'deploy'
)
builds
.
create!
(
id:
1
,
commit_id:
234
,
project_id:
123
,
stage_id:
10
)
builds
.
create!
(
id:
2
,
commit_id:
234
,
project_id:
123
,
stage_id:
21
)
builds
.
create!
(
id:
3
,
commit_id:
234
,
project_id:
123
,
stage_id:
21
)
builds
.
create!
(
id:
4
,
commit_id:
234
,
project_id:
123
,
stage_id:
41
)
builds
.
create!
(
id:
5
,
commit_id:
234
,
project_id:
123
,
stage_id:
62
)
builds
.
create!
(
id:
6
,
commit_id:
234
,
project_id:
123
,
stage_id:
102
)
end
it
'removes ambiguous stages and preserves builds'
do
expect
(
stages
.
all
.
count
).
to
eq
6
expect
(
builds
.
all
.
count
).
to
eq
6
migrate!
expect
(
stages
.
all
.
count
).
to
eq
1
expect
(
builds
.
all
.
count
).
to
eq
6
expect
(
builds
.
all
.
pluck
(
:stage_id
).
compact
).
to
eq
[
102
]
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