Skip to content

fix: blueprint apply fails with UNIQUE constraint on certificates.dom…#3199

Open
Adityakk9031 wants to merge 1 commit into
fosrl:devfrom
Adityakk9031:#2937
Open

fix: blueprint apply fails with UNIQUE constraint on certificates.dom…#3199
Adityakk9031 wants to merge 1 commit into
fosrl:devfrom
Adityakk9031:#2937

Conversation

@Adityakk9031

Copy link
Copy Markdown
Contributor

Problem
Applying a blueprint with a resource under a wildcard subdomain (e.g. *.web.domain.com) fails with:

SqliteError: UNIQUE constraint failed: certificates.domain

Resources under a top-level wildcard (e.g. *.domain.com) succeed. Only deeper wildcard domains are affected.

Root Cause
createCertificate checked for an existing cert by filtering on both domainId and domain. However, certificates.domain has a global unique constraint (not per-domainId).

When getDomainId() resolves a full-domain to a parent domain (e.g. domain.com → domainId = "domain1") instead of the more specific web.domain.com domain, the domainId used in the check doesn't match the existing cert's stored domainId. The check silently misses the cert and falls through to INSERT — which then crashes on the global unique constraint.

Fix
Removed domainId from the existing-cert WHERE clause. Since certificates.domain is globally unique, checking by domain value alone is correct and sufficient.
Added .onConflictDoNothing() to the INSERT as a safety net for any remaining edge cases.
Files Changed
server/private/routers/certificates/createCertificate.ts
Fixes
Closes #2937

@LaurenceJJones

Copy link
Copy Markdown
Contributor

Please take a look at our contributing guide before we can proceed with your PR you are pointing at the wrong merge branch.

@Adityakk9031 Adityakk9031 changed the base branch from main to dev June 1, 2026 09:52
@Adityakk9031

Copy link
Copy Markdown
Contributor Author

@LaurenceJJones done

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.

Blueprint apply: UNIQUE constraint failed: certificates.domain

2 participants