Skip to content

Commit a215357

Browse files
committed
docs(backend): document prisma.config.ts and its role alongside schema.prisma
Closes #1095
1 parent 4bd2cc2 commit a215357

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

backend/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ We use Prisma as our ORM to interact with PostgreSQL.
3232
- Configuration (schema path, migrations path, datasource URL) is defined in `prisma.config.ts`.
3333
- Run `npx prisma studio` to view the database through a web UI.
3434

35+
### `prisma.config.ts` vs `prisma/schema.prisma`
36+
37+
There are two Prisma files, and they do different jobs:
38+
39+
| File | Owns |
40+
| ---- | ---- |
41+
| `prisma/schema.prisma` | The **data model** — models, enums, relations, the `datasource` and `generator` blocks. This is what `prisma generate` turns into the client. |
42+
| `prisma.config.ts` | The **Prisma CLI configuration** — where the CLI looks for things and how it connects when you run `prisma generate`, `prisma migrate`, `prisma db push`, or `prisma studio`. |
43+
44+
`prisma.config.ts` exists as a separate file because it is TypeScript that Node evaluates before the CLI runs, so it can do things `schema.prisma` cannot — most importantly read environment variables. Prisma 7 (this project is on `prisma@^7.4.1`) no longer auto-loads `.env` for CLI commands, which is why the file starts with `import "dotenv/config"`.
45+
46+
What it currently sets:
47+
48+
- `schema: "prisma/schema.prisma"` — path to the schema, so CLI commands work from the `backend/` directory without a `--schema` flag.
49+
- `migrations.path: "prisma/migrations"` — where migration folders are read from and written to.
50+
- `datasource.url: process.env["DATABASE_URL"]` — the connection string the CLI uses.
51+
3552
### Seeding the database
3653

3754
`prisma/seed.ts` populates the database with demo fixtures for local development. Run it with:
@@ -50,6 +67,14 @@ The script is idempotent (it uses `upsert`/fixed IDs), so it's safe to run multi
5067

5168
These fixtures are intended purely for local development/demo purposes so the frontend has data to render out of the box; they are not used in automated tests.
5269

70+
### Troubleshooting
71+
72+
If a `prisma generate` / `prisma migrate` command misbehaves, check `prisma.config.ts` before assuming the schema is at fault:
73+
74+
- **"Environment variable not found: DATABASE_URL"** or the CLI connecting to the wrong database — the config resolves `DATABASE_URL` at load time via `dotenv/config`, so it reads `backend/.env`. A variable exported only in your shell after the process starts, or set in a `.env` outside `backend/`, will not be picked up.
75+
- **CLI can't find the schema or migrations** — these paths are relative to `backend/`. Running `prisma` from the repo root will not resolve them.
76+
- **`npm run prisma:seed` not running the seed script** — the seed command is declared in the legacy `prisma.seed` field in `package.json`. Prisma 7 expects it as `migrations.seed` in `prisma.config.ts`, so if seeding silently does nothing, check both places.
77+
5378
## /v1 API
5479

5580
All REST API endpoints are prefixed with `/v1`. Refer to the API Documentation in the root `README.md` and the `docs/` folder for versioning and authentication details.

docs/DEVELOPMENT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ npm run prisma:generate
6868
npm run prisma:migrate
6969
```
7070

71+
These commands read their paths and connection string from `backend/prisma.config.ts`, which configures the Prisma CLI separately from the data model in `backend/prisma/schema.prisma`. See [Prisma Database](../backend/README.md#prismaconfigts-vs-prismaschemaprisma) in the backend README for what each file owns and what to check when a `generate`/`migrate` command misbehaves.
72+
7173
Start backend:
7274

7375
```bash
@@ -199,6 +201,7 @@ Configure in `.env`:
199201
* Check `DATABASE_URL`
200202
* Run `prisma generate`
201203
* Reset DB if schema drift occurs
204+
* Check `backend/prisma.config.ts` — it sets the schema path, migrations path, and the `DATABASE_URL` the CLI uses ([details](../backend/README.md#troubleshooting))
202205

203206
---
204207

0 commit comments

Comments
 (0)