Nullify `deployments.deployable_id` when a corresponding `ci_builds` row is deleted
Problem
As we discovered in this issue, deployments
table has a data integrity issue that, even if deployments.deployable_id
is present, the corresponding row in ci_builds
might not exist. Currently, we don't have any FK constraints.
Proposal
Nullify deployable_id
when a corresponding ci_builds
row is deleted.
Implementation Details
- Add a foreign key to prevent invalid deployable_id entries
- Add a migration to clean up older invalid entries
- Validate the foreign key in the next release
https://docs.gitlab.com/ee/development/database/add_foreign_key_to_existing_column.html
Edited by Allen Cook