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
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
db/migrate/20180420010016_add_pipeline_build_foreign_key.rb
db/migrate/20180420010016_add_pipeline_build_foreign_key.rb
+5
-2
spec/migrations/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
...
@@ -6,13 +6,16 @@ class AddPipelineBuildForeignKey < ActiveRecord::Migration
...
@@ -6,13 +6,16 @@ class AddPipelineBuildForeignKey < ActiveRecord::Migration
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
execute
<<~
SQL
DELETE FROM ci_builds WHERE project_id IS NULL OR commit_id IS NULL
SQL
execute
<<~
SQL
execute
<<~
SQL
DELETE FROM ci_builds WHERE NOT EXISTS
DELETE FROM ci_builds WHERE NOT EXISTS
(SELECT true FROM ci_pipelines WHERE ci_pipelines.id = ci_builds.commit_id)
(SELECT true FROM ci_pipelines WHERE ci_pipelines.id = ci_builds.commit_id)
AND commit_id IS NOT NULL
SQL
SQL
return
if
foreign_key_exists?
(
:ci_builds
,
:ci_pipelines
,
column: :commit_id
)
add_concurrent_foreign_key
(
:ci_builds
,
:ci_pipelines
,
column: :commit_id
)
add_concurrent_foreign_key
(
:ci_builds
,
:ci_pipelines
,
column: :commit_id
)
end
end
...
...
spec/migrations/add_pipeline_build_foreign_key_spec.rb
View file @
8624a4ed
...
@@ -16,10 +16,12 @@ describe AddPipelineBuildForeignKey, :migration do
...
@@ -16,10 +16,12 @@ describe AddPipelineBuildForeignKey, :migration do
builds
.
create!
(
id:
102
,
commit_id:
222
,
project_id:
11
)
builds
.
create!
(
id:
102
,
commit_id:
222
,
project_id:
11
)
builds
.
create!
(
id:
103
,
commit_id:
333
,
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:
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
end
it
'adds foreign key after removing orphans'
do
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
expect
(
foreign_key_exists?
(
:ci_builds
,
:ci_pipelines
,
column: :commit_id
)).
to
be_falsey
migrate!
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