fix: handle OgImage unique constraint conflict when multiple origins share the same OG image URL#791
Open
tarai-dl wants to merge 1 commit into
Open
Conversation
…share the same OG image URL Previously, when two different origins (e.g., subdomain.example.com and example.com) shared the same OG image URL, the registration would fail with a unique constraint error. This fix: 1. First checks if an OgImage with the same URL already exists for the current origin 2. If it exists, updates it with the new metadata 3. If it doesn't exist, tries to create a new one 4. If creation fails due to a unique constraint on the URL (used by another origin), it logs a warning and skips creation This allows multiple origins to share the same OG image URL without causing registration failures. Closes Merit-Systems#287
Contributor
|
@tarai-dl is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
| title, | ||
| description, | ||
| }, | ||
| }); |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #287
This PR fixes the database unique constraint error that occurs when registering resources from different origins that share the same OG image URL.
Problem
When attempting to register a new resource, the registration fails with a database unique constraint error:
This happens when:
https://subdomain.example.com/api/endpointregisters with origin:https://subdomain.example.comhttps://example.com/api/endpointhas origin:https://example.comSolution
The fix modifies the
upsertOriginfunction inapps/scan/src/services/db/resources/origin.tsto handle the case where an OG image URL is already used by another origin:This allows multiple origins to share the same OG image URL without causing registration failures.
Changes
upsertOriginfunction to handle unique constraint errors gracefullyTesting
The fix has been tested to ensure: