Skip to content

Remove cve_alias_alias_fkey to support GHSA aliases without CVE rows#272

Open
ybelMekk wants to merge 5 commits intomainfrom
fix/drop-cve-alias-alias-fkey
Open

Remove cve_alias_alias_fkey to support GHSA aliases without CVE rows#272
ybelMekk wants to merge 5 commits intomainfrom
fix/drop-cve-alias-alias-fkey

Conversation

@ybelMekk
Copy link
Copy Markdown
Contributor

@ybelMekk ybelMekk commented May 5, 2026

This pull request updates the database schema to remove a foreign key constraint from the cve_alias table. The change allows aliases (such as GHSA IDs) to exist without requiring a corresponding row in the cve table, making the schema more flexible for non-CVE aliases.

Database schema change:

  • Dropped the cve_alias_alias_fkey foreign key constraint from the cve_alias table, so aliases are no longer required to reference an existing cve row. This supports cases where aliases (like GHSA IDs) do not have a direct CVE entry.

Copilot AI review requested due to automatic review settings May 5, 2026 21:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Postgres schema to allow cve_alias.alias values (e.g., GHSA IDs) to exist without requiring a corresponding row in cve, by removing the cve_alias_alias_fkey foreign key constraint.

Changes:

  • Add migration to drop the cve_alias_alias_fkey constraint from cve_alias in the Up direction.
  • Add Down migration to re-create the dropped foreign key constraint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/database/migrations/0027_drop_cve_alias_alias_fkey.sql
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/updater/updater_integration_test.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/updater/updater_integration_test.go Outdated
ybelMekk added 5 commits May 6, 2026 09:23
The cve_alias_alias_fkey constraint required every alias (e.g. GHSA IDs)
to exist as a row in the cve table. This was incorrect — GHSA IDs are
aliases, not canonical CVEs, and should not require their own cve rows.

With the companion fix in nais/dependencytrack (fix/promote-github-cve-canonical),
GITHUB findings now set Cve.Id to the CVE canonical. This means:
- cve row is upserted for the CVE canonical (satisfies canonical_fkey)
- cve_alias row is inserted with alias=GHSA-xxx (no longer needs alias_fkey)

Keeping cve_alias_canonical_fkey intact — canonicals must still be
valid cve rows, which the promotion guarantees.
…ding FK

The Down migration re-adds cve_alias_alias_fkey which requires every
alias to exist in cve(cve_id). After the Up migration, GHSA aliases
can exist without a cve row. Without the DELETE, a rollback would fail
with a FK violation on any such rows.
…inding promotion

- TestBatchUpdateVulnerabilityData_GithubFindingPromotion: verifies full
  pipeline for a GITHUB finding after ParseFinding promotion — cve row
  upserted for CVE canonical, cve_alias row inserted without FK error,
  vulnerabilities row references CVE canonical, GetCanonicalCveIdByAlias
  returns correct canonical for the GHSA alias
- TestCveAliasCanonicalFkeyStillEnforced: verifies cve_alias_canonical_fkey
  remains active after migration 0027 — inserting an alias with a
  non-existent canonical is still rejected
- Improve Down migration comment to make the intentional data loss explicit
…atch

Replace assert.Contains(err.Error(), constraintName) with errors.As to
a *pgconn.PgError and check Code == ForeignKeyViolation and
ConstraintName directly — avoids false negatives across driver/PG versions.
@ybelMekk ybelMekk force-pushed the fix/drop-cve-alias-alias-fkey branch from a83a11e to ba7b5d7 Compare May 6, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants