Validate partitioned FK on vulnerability_occurrences

What does this MR do and why?

Completes step 4 of the list partitioning guide for the vulnerability_occurrencesvulnerability_identifiers reference:

  1. Synchronously validates the composite foreign key fk_rails_c8661a61eb_p (partition_id, primary_identifier_id)vulnerability_identifiers(partition_id, id) (added as NOT VALID in !244081 (merged), scheduled for async validation in !247860 (merged)).
  2. Removes the old single-column foreign key fk_rails_c8661a61eb on primary_identifier_id.

This matches the pattern used for vulnerability_occurrence_identifiers in !240976 (merged) and is the final remaining step of #596858 (closed).

Dependencies:

  • Depends on !244081 (merged) (adds the FK) and !247860 (merged) (schedules async validation) — targets the async-validation branch for a clean diff; will be rebased and retargeted to master once they merge.
  • Must only be merged after the async validation of fk_rails_c8661a61eb_p has completed on GitLab.com, so the synchronous validate_foreign_key is a fast metadata-only operation.

Migration output

Up:

main: == 20260730144814 ValidateCompositeFkOnVulnerabilityOccurrences: migrating ====
main: == 20260730144814 ValidateCompositeFkOnVulnerabilityOccurrences: migrated (0.0382s)
main: == 20260730144844 RemoveOldFkOnVulnerabilityOccurrences: migrating ============
main: == 20260730144844 RemoveOldFkOnVulnerabilityOccurrences: migrated (0.0440s) ===

SQL:

ALTER TABLE vulnerability_occurrences VALIDATE CONSTRAINT fk_rails_c8661a61eb_p;

ALTER TABLE vulnerability_occurrences DROP CONSTRAINT IF EXISTS fk_rails_c8661a61eb;

Down: validation is kept (no-op); the old FK is restored with add_concurrent_foreign_key.

db/structure.sql was regenerated with scripts/regenerate-schema.

References

How to set up and validate locally

  1. Run the migrations and inspect the constraints:

    bundle exec rails db:migrate
    psql -d gitlabhq_development_sec -c '\d vulnerability_occurrences' | grep fk_rails_c8661a61eb

    Only fk_rails_c8661a61eb_p should remain, without NOT VALID.

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.

Merge request reports

Loading
Loading