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

  1. Run bundle exec rails db:migrate.
  2. Run bundle exec rspec spec/models/repositories/tags/gpg_signature_spec.rb.
  3. Confirm db/structure.sql updates the tag_gpg_signatures.project_id foreign key from ON DELETE SET NULL to ON DELETE CASCADE NOT VALID.
  4. Destroy a project with associated tag_gpg_signatures and 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.

Edited by Vasilii Iakliushin

Merge request reports

Loading
Loading