diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-14 16:01:05 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-18 10:51:19 +0200 |
commit | 4aab52b20f9af44f03f2452875eb43bb40f2a6c6 (patch) | |
tree | 71f72e5f9e3843a548f841ee0df6690c47d72cba /db | |
parent | 5cd6f8c76ec74c85e6ff6dae9736b27baeb55988 (diff) | |
download | gitlab-ce-4aab52b20f9af44f03f2452875eb43bb40f2a6c6.tar.gz |
Nullify orphaned head_pipeline_ids in merge_requests
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb b/db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb index 78ff7527967..8a4e1062314 100644 --- a/db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb +++ b/db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb @@ -6,6 +6,14 @@ class AddForeignKeyToMergeRequests < ActiveRecord::Migration disable_ddl_transaction! def up + execute <<-SQL.strip_heredoc + UPDATE merge_requests SET head_pipeline_id = null + WHERE NOT EXISTS ( + SELECT 1 FROM ci_pipelines + WHERE ci_pipelines.id = merge_requests.head_pipeline_id + ) + SQL + unless foreign_key_exists?(:merge_requests, :head_pipeline_id) add_concurrent_foreign_key(:merge_requests, :ci_pipelines, column: :head_pipeline_id, on_delete: :nullify) |