Fix tag_gpg_signatures project deletion
What does this MR do and why?
Problem
Project deletion fails with ActiveRecord::NotNullViolation
because the tag_gpg_signatures.project_id foreign key uses
ON DELETE SET NULL, but the column has a NOT NULL
constraint. PostgreSQL cannot nullify the column on cascade.
Similar tables like ssh_signatures, tag_ssh_signatures and gpg_signatures already set ON DELETE CASCADE for project_id column. So tag_gpg_signatures is the only exception.
Solution
Replace the foreign key with ON DELETE CASCADE so that
tag_gpg_signatures rows are deleted when the parent project
is destroyed. The FK is added with validate: false and
asynchronous validation is scheduled for a low-traffic window
to avoid a long-running table scan during deployment.
A follow-up MR will add the synchronous validate_foreign_key
migration after confirming the FK is valid in production.
References
Screenshots or screen recordings
Not applicable — no UI changes.
How to set up and validate locally
- Run
bundle exec rails db:migrate. - Run
bundle exec rspec spec/models/repositories/tags/gpg_signature_spec.rb. - Confirm
db/structure.sqlupdates thetag_gpg_signatures.project_idforeign key fromON DELETE SET NULLtoON DELETE CASCADE NOT VALID. - Destroy a project with associated
tag_gpg_signaturesand verify deletion succeeds.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.