Add docker-compose for local Postgres and fix the setup docs

Adds docker-compose.yml (Postgres on host port 5433, to avoid clashing
with another project's container already using 5432 on this machine)
and .env.example so `docker compose up -d` + `cp .env.example .env.local`
gets a working local DB. Adds a db:seed script alongside the existing
db:* scripts.

Rewrites README's "Adding a Database" section, which still described
Better Auth's DB as optional/hypothetical even though this project
already requires Postgres for both its own data and Better Auth's
tables. Fills in CLAUDE.md's Data layer connection-details placeholder
and fixes two more stale pnpm references and a wrong migrations path
(src/db/migrations/ instead of the actual drizzle/) found nearby.

Also fixes a real bug the new docs surfaced: `npm run db:seed` didn't
load .env.local the way drizzle-kit does, so DATABASE_URL was silently
unset when run as documented. seed.ts now loads env the same way
drizzle.config.ts already does.

Verified the full documented flow end-to-end against a fresh container:
migrate, better-auth migrate, seed, dev server, real page render.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-09 21:05:07 +02:00
co-authored by Claude Sonnet 5
parent ea459e72b3
commit ff8fc388c0
6 changed files with 69 additions and 37 deletions
+13 -9
View File
@@ -44,12 +44,13 @@ src/
├── db/
│ ├── schema.ts # Drizzle schema definitions
│ ├── index.ts # Drizzle client instance
│ └── migrations/ # generated SQL migrations — never hand-edit
│ └── seed.ts # sample data for local dev / tests
├── styles/
│ ├── globals.scss # global styles, resets
│ └── _variables.scss # shared SCSS variables/mixins (partial)
public/ # static assets
drizzle.config.ts # Drizzle Kit config (schema path, out dir, dialect)
drizzle/ # generated SQL migrations — never hand-edit
```
### Routing conventions
@@ -116,14 +117,17 @@ drizzle.config.ts # Drizzle Kit config (schema path, out dir, dialect)
- After changing `schema.ts`, generate a migration rather than editing the
database by hand:
```bash
pnpm drizzle-kit generate # create a migration from schema changes
pnpm drizzle-kit migrate # apply pending migrations
npm run db:generate # create a migration from schema changes
npm run db:migrate # apply pending migrations
```
- Never hand-edit files under `db/migrations/` — they're generated and
should be treated as a history, not touched retroactively.
- [Connection details: env var name for `DATABASE_URL`, whether using a
connection pool like `postgres.js` or `node-postgres`, local dev DB setup
e.g. Docker Compose]
- Never hand-edit files under `drizzle/` (the migrations output directory,
configured in `drizzle.config.ts`) — they're generated and should be
treated as a history, not touched retroactively.
- Connection string comes from `DATABASE_URL` (see `.env.example`), read via
`drizzle-orm/node-postgres`. Local dev DB is a `docker-compose.yml`
Postgres container — see the README's "Local development database"
section. `.env.local` is picked up automatically by both the dev server
and `drizzle-kit`; no manual sourcing needed.
## Testing
@@ -134,7 +138,7 @@ drizzle.config.ts # Drizzle Kit config (schema path, out dir, dialect)
## Things to avoid
- Don't hand-edit `routeTree.gen.ts` or files under `db/migrations/`.
- Don't hand-edit `routeTree.gen.ts` or files under `drizzle/`.
- Don't run destructive Drizzle commands (`drizzle-kit push` against a
populated DB, or anything that drops columns/tables) without confirming
first — prefer `generate` + `migrate` so changes are reviewable.