Skip to content

Draft: Prevent Project#destroy if associated builds exist

drew stachon requested to merge projects-builds-dependent-restrict into master

What does this MR do and why?

This MR adds a callback to prevent the destruction of Projects if Ci::Build records are still persisted for that Project. This shouldn't ever be the case, since we always destroy Projects via Projects::DestroyService and we now permanently use code to preemptively destroy builds without joining ci_ and non-ci_ tables.

This makes sure that no forbidden join queries are ever fired by dependent: :destroy, which we need to prevent for the database sharding to work well. If our optimized builds destruction code fails for any reason, we'll see errors on Project#delete_error about this.

How to set up and validate locally

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

For demonstrative behavior:

  1. Check out this branch locally
  2. Change the association back to dependent: :destroy
  3. Run the added tests and see the execution failures.
  4. Change back to dependent: :restrict_with_exception and they'll pass again.

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 drew stachon

Merge request reports