Menu
docs

D1 and migrations

Forward-only SQLite migrations and explicit cross-row invariants.

Schema ownership

Drizzle defines typed application tables. Better Auth exclusively owns user, session, account, and verification; product-specific fields belong in projection tables.

Forward-only migrations

pnpm db:generate
pnpm db:migrate
pnpm test:integration
pnpm db:migrate:preview

Never edit an applied migration. Use expand/contract changes and a later forward repair when necessary.

Tenant invariants

D1 triggers protect last-owner, credit-ledger, billing-customer, workspace-deletion, media-quota, and feedback-access rules. Services still authorize every operation; triggers are the final defense against races and implementation mistakes.

SELECT RAISE(ABORT, 'cannot remove the last workspace owner');

Exact money

Store charges and invoice totals as integer minor units. Prices that can carry sub-minor precision use a decimal string with an explicit scale. Do not use JavaScript floating point for billing arithmetic.