fix(prisma): Prisma.Database with omitted branch attaches the project default branch - #1359
Open
kristof-siket wants to merge 4 commits into
Open
Conversation
… default branch
Prisma.Database read omitted branchId/branchGitName as desired-UNASSIGNED:
branchNeedsSync converged toward branchId null and reconcile's patch path
actively PATCHed { branchId: null }, re-detaching an out-of-band-attached
database on every deploy — while sibling Prisma.App resolves the project's
default branch for the same omission and Prisma.Bucket lets the Management
API attach the default branch server-side.
Omitted branch props now resolve to the project's default branch, mirroring
App's desiredBranchId (defaultBranchIdOf + resolvedBranchAttachment):
- branchNeedsSync compares the observed branchId against the RESOLVED
default branch id, so a pre-existing unassigned database converges with
one in-place PATCH on its next reconcile (never a replace), and a
database already attached to the default branch is left alone.
- The reconcile patch path never emits branchId: null; the create path
passes the resolved default branch id for generated-name creates, so a
fresh database is born attached.
- Explicit branchId: null / branchGitName: null are removed from the prop
types and rejected at validate and diff — an unassigned database is no
longer expressible as desired state.
- The explicit-name + branch-attachment create refusal stays: an
explicitly named create (branch omitted) is created project-scoped and
converges onto the default branch via PATCH in the same reconcile.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Change return type from discriminated union to string | undefined - Use limit: 2 for all gitName branch lookups (Branches.ts, SourceRepository.ts) - Resolve default branch once before if (!database) for generated-name creates; plain createBranchId local replaces resolvedBranch cast and reuse dance - Remove the 3-line skip-listBranches comment; restore invariant comment at conflict recovery site - Update all callers in App.ts and Database.ts to check === undefined
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
The three Prisma resources that take an optional branch attachment interpret the same omission three different ways:
branchId/branchGitNameomitted meansPrisma.AppdesiredBranchId; fails loudly when the project has no default branch)Prisma.BucketPrisma.DatabaseThe
Prisma.Databasereading is the odd one out, and it bites in two ways:branchNeedsSyncreturnsdatabase.branchId !== nullwhen both props are omitted, and the reconcile patch path maps omission to an explicit{ branchId: null }PATCH;Prisma.Databasewith no branch props show up as "Unassigned" in the Prisma Console.Downstream consumers currently work around the asymmetry by always passing
branchIdexplicitly (see prisma/composer#258).What changes
Prisma.Databasenow treats an omitted branch exactly likePrisma.App: resolve the project's default branch and converge toward it.branchId: nullis never emitted.defaultBranchIdOf+resolvedBranchAttachmenthelpers mirrorApp'sdesiredBranchId, including the same-shaped errors for a missing or ambiguous default branch ("has no default branch to attach database … Create or promote a default branch, or specify branchId/branchGitName").branchNeedsSync's omitted arm compares the observedbranchIdagainst the resolved default branch id instead of!== null.{ branchId: null }detach PATCH is gone.branchIdin the create body, so a fresh database is born attached.DatabaseProps.branchId/branchGitNamelose| null; runtimenullis rejected invalidateDatabasePropsand an earlydiffguard with a clear error (mirroringvalidateAppProps), rather than silently resolving to the default — a caller who meant "detach" gets a loud contract error.name+ branch attachment at create is kept verbatim (the Management API still creates before attaching with no idempotency key).Behavior notes
branchId: null/branchGitName: null— previously the only way to request detachment — now fails validation. Anyone who deliberately wanted an unassigned database loses that expressibility; an unassigned database is no longer representable as desired state, matchingPrisma.App.Tests
New
test/Prisma/Database.test.ts(fake-client provider tests in theApp.test.tsstyle) pins:updateDatabasedies if called (regression test for the old behavior);diffplans an update, not a replace;branchIdstays authoritative (no default-branch lookup);nullbranch props are rejected at reconcile and diff;Existing suites updated to the new contract: the old "detaches an observed branch when branch props are omitted" regression test is inverted into "keeps the observed branch attachment", and the fake Management clients in
Resources.test.ts/ManagementLifecycle.test.tsgainedlistBranches/ branch-awarecreateDatabase/updateDatabase.pnpm test test/Prisma— 376 passed, 0 failed.pnpm tsc -bandpnpm docs:check-jsdocclean.🤖 Generated with Claude Code