summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-08 17:12:29 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-08 17:12:29 +0200
commit8624a4eddec214a4092c34202bfc0cc92e72eb19 (patch)
tree904bef4d8fa6820953fb02c56a364a4866520277 /db
parentd8d0067bf5afd555f80e55e0bed20c4161b0a7ee (diff)
downloadgitlab-ce-8624a4eddec214a4092c34202bfc0cc92e72eb19.tar.gz
Remove orphaned builds without project / pipeline reference
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180420010016_add_pipeline_build_foreign_key.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/db/migrate/20180420010016_add_pipeline_build_foreign_key.rb b/db/migrate/20180420010016_add_pipeline_build_foreign_key.rb
index 385d51b8da6..7fcd3b20d5e 100644
--- a/db/migrate/20180420010016_add_pipeline_build_foreign_key.rb
+++ b/db/migrate/20180420010016_add_pipeline_build_foreign_key.rb
@@ -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