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
8624a4ed
Commit
8624a4ed
authored
May 08, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove orphaned builds without project / pipeline reference
parent
d8d0067b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
20180420010016_add_pipeline_build_foreign_key.rb
db/migrate/20180420010016_add_pipeline_build_foreign_key.rb
+5
-2
add_pipeline_build_foreign_key_spec.rb
spec/migrations/add_pipeline_build_foreign_key_spec.rb
+3
-1
No files found.
db/migrate/20180420010016_add_pipeline_build_foreign_key.rb
View file @
8624a4ed
...
...
@@ -7,12 +7,15 @@ class AddPipelineBuildForeignKey < ActiveRecord::Migration
def
up
execute
<<~
SQL
DELETE FROM ci_builds WHERE project_id IS NULL OR commit_id IS NULL
SQL
execute
<<~
SQL
DELETE FROM ci_builds WHERE NOT EXISTS
(SELECT true FROM ci_pipelines WHERE ci_pipelines.id = ci_builds.commit_id)
AND commit_id IS NOT NULL
SQL
return
if
foreign_key_exists?
(
:ci_builds
,
:ci_pipelines
,
column: :commit_id
)
add_concurrent_foreign_key
(
:ci_builds
,
:ci_pipelines
,
column: :commit_id
)
end
...
...
spec/migrations/add_pipeline_build_foreign_key_spec.rb
View file @
8624a4ed
...
...
@@ -16,10 +16,12 @@ describe AddPipelineBuildForeignKey, :migration do
builds
.
create!
(
id:
102
,
commit_id:
222
,
project_id:
11
)
builds
.
create!
(
id:
103
,
commit_id:
333
,
project_id:
11
)
builds
.
create!
(
id:
104
,
commit_id:
12
,
project_id:
11
)
builds
.
create!
(
id:
106
,
commit_id:
nil
,
project_id:
11
)
builds
.
create!
(
id:
107
,
commit_id:
12
,
project_id:
nil
)
end
it
'adds foreign key after removing orphans'
do
expect
(
builds
.
all
.
count
).
to
eq
4
expect
(
builds
.
all
.
count
).
to
eq
6
expect
(
foreign_key_exists?
(
:ci_builds
,
:ci_pipelines
,
column: :commit_id
)).
to
be_falsey
migrate!
...
...
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