Repository navigation
feat(server): canonical organization_domains writers (#4159 Stage 3a) - #4329
Merged
Merged
Conversation
Introduce db/organization-domains-db.ts with two primitives: - linkDomain: INSERT a row, ON CONFLICT DO NOTHING, log when the existing row is owned by a different org (#4321 pattern, generalized). When isPrimary=true and the row was actually inserted, also denormalize organizations.email_domain — closes the latent drift in the prior member-profiles and prospect call sites that updated only one side. - setPrimaryDomain: atomic clear-existing-primary + set-new-primary + update organizations.email_domain. Locks the org row via FOR UPDATE. Optional requireSource allowlist (e.g. ['workos'] for member self-service). Migrate the simpler call sites: prospect.ts, organization-bootstrap.ts, member-profiles.ts (bootstrap), me-organization-domains.ts, bolt-app.ts. WorkOS webhook (FOR UPDATE locking + idempotency invariants) and admin/domains.ts (~10 call sites with diverging flows) are deferred to Stage 3b/3c. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 10, 2026
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
Stage 3a of #4159. Stage 2 collapsed four overlapping domain columns onto `organization_domains.is_primary=true`. This PR consolidates the write paths behind two canonical primitives so every caller goes through the same SQL with the same invariants.
New module: `db/organization-domains-db.ts`
`linkDomain({orgId, domain, source, verified, isPrimary?})` — INSERT a row. `ON CONFLICT (domain) DO NOTHING`. Logs when the existing row is owned by a different org (organization_domains.is_primary write paths bypass member-self-service WorkOS-source gate #4321 pattern, generalized). When `isPrimary=true` and the row was actually inserted, also denormalizes `organizations.email_domain` — closes a latent drift in the prior member-profiles / prospect call sites that updated only one side.
`setPrimaryDomain({orgId, domain, requireSource?})` — atomic clear-existing-primary + set-new-primary + update `organizations.email_domain`. Locks the org row via FOR UPDATE. Optional `requireSource` allowlist (e.g. `['workos']` for member self-service).
Migrated call sites
Out of scope
Deferred to Stage 3b/3c:
Test plan
🤖 Generated with Claude Code