**Option A — Postgres in Docker (no local install, e.g. Mac)**
From `backend/`, with `.env` present (copy from `.env.example` first):
- Ensure `DATABASE_URL` uses **`localhost`** as the host (not `postgres`). Match user, password, and DB name to `POSTGRES_USER`, `POSTGRES_PASSWORD`, and `POSTGRES_DB` in the same file.
```bash
docker compose -f docker-compose.postgres.yml up -d
```
Wait until Postgres is healthy (`docker compose -f docker-compose.postgres.yml ps`). The container creates the database on first start.
To stop Postgres (data is kept in the named volume): `docker compose -f docker-compose.postgres.yml down`
**Option B — Postgres installed on the machine**
Create an empty database, then point `DATABASE_URL` at it.
This **does not** wipe your database. It only upserts lookup data: organization types (`CLINIC`, `LAB`), subscription plans, and tab permissions. Existing users, organizations, memberships, patients, appointments, and links are **left unchanged**.
To start from an empty database with fresh tables and reference data, see [Reset database (clean slate)](#reset-database-clean-slate) below.
## Reset database (clean slate)
Use this when you want to **delete all application data** (users, organizations, patients, sessions, etc.) and rebuild the schema from migrations, then run the seed.
From `backend/`:
```bash
npx prisma migrate reset
```
Prisma will prompt for confirmation, drop the database, re-apply all migrations, and run `prisma/seed.ts` automatically.
**What gets removed:** everything in the database, including organizations and all related rows.
**What the seed adds back:** only reference data (types, plans, permissions) — not demo users or organizations. Register again or use your own test data after a reset.
**Docker Postgres dev:** if you also want to wipe the Docker volume (not only tables), stop the container and remove the volume:
```bash
docker compose -f docker-compose.postgres.yml down -v
docker compose -f docker-compose.postgres.yml up -d
npm run prisma:migrate
npm run prisma:seed
```
Do **not** run `migrate reset` against production or shared staging databases.