Skip to content

Nullify merge_request_metrics pipeline_id on pipeline deletion

Patrick Bajao requested to merge 26911-nullify-metrics-pipeline-lfk into master

What does this MR do and why?

Before, when a pipeline is deleted, the associated merge_request_metrics record will be deleted as well. This is a destructive thing as merge_request_metrics include other data not related to a pipeline.

To fix this issue, instead of deleting the association record, we nullify the pipeline_id on merge_request_metrics instead. When this happens, related build data (latest_build_started_at and latest_build_finished_at) will be nullified as well. This is to ensure that when those data are requested, it'll still behave the same way as before.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Run migration.
  2. Create a MR with pipeline.
  3. Let the pipeline run.
  4. Merge the MR.
  5. Delete the pipeline.
  6. Wait for 2 minutes (this is to ensure the job to clean up loose foreign keys has already ran).
  7. Make a request to api/v4/projects/:project_id/merge_requests/:merge_request_iid and check if merged_at is not null.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bajao

Merge request reports