Commit 4aab52b2 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Nullify orphaned head_pipeline_ids in merge_requests

parent 5cd6f8c7
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment