refactor(api): include type segment in DO names#1520
Merged
Conversation
Change DO naming from `user:{userId}:{name}` to
`user:{userId}:{type}:{name}` so names are globally unique across
DO namespaces. Clean break—clients re-sync to new DOs.
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.
DO names currently encode the user but not the resource type—
user:{userId}:{resourceName}is the same shape for both workspace and document routes. SinceWORKSPACE_ROOMandDOCUMENT_ROOMare separate Cloudflare namespaces,idFromName()produces different DO instances, so this hasn't caused runtime issues. But the name strings themselves are ambiguous: givenuser:abc:notes, you can't tell if it's a workspace or a document without additional context.This becomes a real problem for any tracking or observability layer that stores DO names. A UNIQUE constraint on
doNamewould collide when a user has a workspace and document with the same name, and log entries become unparseable without the namespace context that produced them.The fix adds a type segment to every DO name:
Both stub functions in
app.tschange from a bare resource name to an explicit type prefix:Same pattern for
getDocumentStub—:document:instead of bare name.Migration
Clean break—same approach as the
tab-manager→epicenter.tab-managerrename. Local-first clients hold the full Y.Doc locally and re-sync to the new (empty) DO on next connection. Old DOs sit idle until cleanup. Document snapshots stored in old DO SQLite are lost, which is acceptable during early development.