[Adapters] Stop sku_owners/customer_emails declaring a unique index that leaks onto sibling collections - #297
Merged
Conversation
…hat leaks onto sibling collections The host materializes a declared uniqueIndexes entry as one physical index per plugin, scoped to (plugin_id, collection, field) with no per-collection WHERE clause. reservation_keys and reservation_index also carry a top-level sku field (one row per reserve attempt, many rows legitimately sharing a sku), so they collided on sku_owners' declared unique index the moment a second reserve happened for any SKU: the first add-to-cart for a product worked, every later one threw a raw D1 UNIQUE constraint error. Both collections' own create-if-absent CAS against the sku/email-as-id was always the real enforcement (the module comments already said so, wrongly adding "no physical index exists in any tier" as the reason it was safe to declare unique anyway). Switched both to a plain (non-unique) indexes entry and corrected the comments. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HPywdmMJ9B4V1ME6GrxuDu
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
UNIQUE constraint failederror, surfacing to shoppers as a generic "Something went wrong."sku_owners(and identicallycustomer_emails) declared their natural key as auniqueIndexesentry, on the belief that "no physical index exists in any tier." On the currently pinned host release that's no longer true — a declared unique index materializes as one physical SQLite index per plugin, keyed(plugin_id, collection, field), with no per-collection scoping.reservation_keysandreservation_index(inventory) also carry a top-levelskufield, one row per reserve attempt, many rows legitimately sharing a sku — so those collections collided onsku_owners' declared index the moment a second reserve happened for any SKU: the first add-to-cart for a product worked, every subsequent one threw.indexesentry instead. The create-if-absent compare-and-set against the sku/email-as-document-id was always the real enforcement; the unique index was redundant for its own collection and unsafe for its neighbors. Corrected the stale comments claiming no physical index exists.Test plan
pnpm lint— cleanpnpm typecheck— cleanpnpm vitest run packages/store-emdash— 744 passed, 0 failed (817 skipped, PG-dialect-gated)pnpm vitest run packages/plugin/test/commerce-storage.test.ts packages/plugin/test/sandbox— 21 passed, 0 failed🤖 Generated with Claude Code
https://claude.ai/code/session_01HPywdmMJ9B4V1ME6GrxuDu