Skip to content
Docs
Core platformUpdated 2026-08-20

Database and D1

Manage the Drizzle schema, local and remote migrations, Better Auth tables, and product persistence.

Schema ownership

Drizzle owns one D1-compatible schema. Generated SQL lives in drizzle/.

Better Auth tables:

  • user
  • session
  • account
  • verification

Product tables:

  • payment
  • webhook_event
  • api_key
  • file_object
  • waitlist_entry
  • activity_event

Generate a migration

Change the schema in src/db/schema.ts, then run:

bash
pnpm db:generate

Review the generated SQL before applying it.

Apply locally

bash
pnpm db:migrate:local

Local D1 state is stored under .wrangler/ and is isolated by the E2E preparation script during acceptance tests.

Apply remotely

bash
pnpm db:migrate:remote

The deployment flow applies remote migrations after the Worker resources exist and before final smoke verification.

Idempotency and indexes

Webhook events use a unique provider and event identity so repeated deliveries do not duplicate billing state. API keys store a unique hash. Better Auth account issuer fields and unique indexes are included for the pinned auth version.

Operational rules

  • Generate SQL through Drizzle rather than editing metadata by hand.
  • Back up production data before destructive migrations.
  • Keep durable product records in D1; use KV only for cache or preview state.
  • Keep file bytes in R2 and metadata in D1.
TanStarter SES documentationBuilt with TanStack Start and Content Collections.