Skip to content

Data model & migrations

The EdgeCart D1 schema, Drizzle migrations, and store scoping.

EdgeCart keeps commerce, Better Auth, plugin control-plane, and outbox data in one Cloudflare D1 database. The schema is managed with Drizzle and applied through Wrangler migrations.

Schema ownership

Area Tables live in
Commerce packages/commerce-core/src/schemas and the commerce modules.
Auth Better Auth schema generated into commerce-core.
Plugins Plugin installs, releases, settings, KV, documents.
Outbox Audit, outbox events, webhook endpoints, deliveries, email.

Commerce rows are scoped by store_id. The admin is single-store, but the data model and Admin API still use store_id / x-store-id.

Generate and apply migrations

pnpm db:generate       # generate Drizzle migrations
pnpm db:migrate:local  # apply to the local D1 database
pnpm db:migrate:remote # apply to the remote D1 database

Migrations live in apps/edgecart/drizzle/migrations. Better Auth’s schema is generated separately:

pnpm ba:generate
pnpm db:generate
pnpm db:migrate:local

Design rules

  • Money is stored as integer minor units with a currency code.
  • Status fields are constrained to known values; invalid states are rejected.
  • Audit and outbox rows are written with the mutation that caused them.
  • Plugin secrets are encrypted at rest and never serialized into invocations.

The Commerce modules explain each domain’s concepts without the schema detail.

Type to search…

↑↓ navigate↵ selectEsc close