Skip to main content

Database

Migrations

The schema lives in app/db/schema.ts. Migrations are managed with Drizzle Kit and applied to D1 through Wrangler.

bun run db:generate # generate SQL from app/db/schema.ts changes
bun run db:migrate:dev # apply migrations to local/dev D1
bun run db:migrate:prod # apply migrations to production D1

Use drizzle/ for all schema migrations and tracked one-time data migrations. For schema changes, edit app/db/schema.ts first and run bun run db:generate.

For one-time data fixes, add a numbered SQL migration in drizzle/ so Wrangler records it in D1.

Resource names and bindings live in wrangler.jsonc:

DB D1
PHOTOS R2

Seeding Test Data

Populate a local or remote D1 with realistic fake data using Faker.

bun run seed # 1000 persons, about 30% found, plus tips
bun run seed --reset # clear previous seed rows, then seed
bun run seed --dry-run # preview sample rows, no DB writes
bun run seed --count=5000 # more rows
bun run seed:remote --reset # seed production D1

Seeded rows use seed_-prefixed IDs, so --reset only removes data this script created. Output is deterministic with faker.seed(42) and safe to rerun with INSERT OR IGNORE.

Flags:

--count
--tip-ratio
--found-ratio
--batch-size

Drizzle Studio

Inspect live D1 without being added to the Cloudflare account by using a scoped API token.

cp .env.example .env
bun run db:studio

Create the token at dashboard > My Profile > API Tokens with Account > D1 > Edit permission, or Read to browse only.

The token is the only secret. Rotate or revoke it per person.