diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-06-05 13:46:42 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-06-05 13:46:42 +0200 |
commit | 3326291f7e6c6b4452ca6aa4fc65faf1bd821220 (patch) | |
tree | 49baf9ce476f0c13ac4e9fdcc4b911334063a329 /db | |
parent | 06898af38f46daaa1c75cb4adead971062684875 (diff) | |
download | gitlab-ce-3326291f7e6c6b4452ca6aa4fc65faf1bd821220.tar.gz |
Remove obsolete stages/build before adding foreign keys
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170526190708_create_foreign_keys_for_pipeline_stages.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/db/post_migrate/20170526190708_create_foreign_keys_for_pipeline_stages.rb b/db/post_migrate/20170526190708_create_foreign_keys_for_pipeline_stages.rb index 40060d12d74..8a01de1fce6 100644 --- a/db/post_migrate/20170526190708_create_foreign_keys_for_pipeline_stages.rb +++ b/db/post_migrate/20170526190708_create_foreign_keys_for_pipeline_stages.rb @@ -6,6 +6,22 @@ class CreateForeignKeysForPipelineStages < ActiveRecord::Migration disable_ddl_transaction! def up + execute <<~SQL + DELETE FROM ci_stages + WHERE NOT EXISTS ( + SELECT true FROM projects + WHERE projects.id = ci_stages.project_id + ) + SQL + + execute <<~SQL + DELETE FROM ci_builds + WHERE NOT EXISTS ( + SELECT true FROM ci_stages + WHERE ci_stages.id = ci_builds.stage_id + ) + SQL + add_concurrent_foreign_key :ci_stages, :projects, column: :project_id, on_delete: :cascade add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade end |