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:
usersessionaccountverification
Product tables:
paymentwebhook_eventapi_keyfile_objectwaitlist_entryactivity_event
Generate a migration
Change the schema in src/db/schema.ts, then run:
pnpm db:generateReview the generated SQL before applying it.
Apply locally
pnpm db:migrate:localLocal D1 state is stored under .wrangler/ and is isolated by the E2E preparation script during acceptance tests.
Apply remotely
pnpm db:migrate:remoteThe 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.