Draft: Prevent Project#destroy if associated builds exist
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:
- Check out this branch locally
- Change the association back to
dependent: :destroy
- Run the added tests and see the execution failures.
- 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.
-
I have evaluated the MR acceptance checklist for this MR.