Rebasely Beta: data may be purged

examples/storefront Public

Markdown · 949 B · at 80dbc76

id: 0001-d1-for-shop-data
type: decision
owner: justin
status: accepted
reviewed: 2026-10-01

0001 One D1 database for the shop's data

Context

The storefront needs products, carts and, soon, orders. Checkout has to read a cart, take stock and create an order as one step that either happens completely or not at all.

Decision

All of it lives in one D1 database, storefront. Tables are created and changed only by numbered migrations in migrations/. Multi-statement writes go through db.batch(), which D1 runs as a single transaction.

Consequences

  • Checkout can take stock and create the order in one batch, and a CHECK constraint can refuse the whole batch.
  • The tests run the same migrations against SQLite (see [[testing]]), so the SQL the tests exercise is the SQL that ships.
  • One database is one write path. A shop of this size is far from D1's limits; if that changes, carts are the first table to move out.