Skip to content

Commit faa0d2a

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

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
@@ -31,6 +31,31 @@ We use Prisma as our ORM to interact with PostgreSQL.
3131
- Schema is located at `prisma/schema.prisma`.
3232
- Run `npx prisma studio` to view the database through a web UI.
3333

34+
### `prisma.config.ts` vs `prisma/schema.prisma`
35+
36+
There are two Prisma files, and they do different jobs:
37+
38+
| File | Owns |
39+
| ---- | ---- |
40+
| `prisma/schema.prisma` | The **data model** — models, enums, relations, the `datasource` and `generator` blocks. This is what `prisma generate` turns into the client. |
41+
| `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`. |
42+
43+
`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"`.
44+
45+
What it currently sets:
46+
47+
- `schema: "prisma/schema.prisma"` — path to the schema, so CLI commands work from the `backend/` directory without a `--schema` flag.
48+
- `migrations.path: "prisma/migrations"` — where migration folders are read from and written to.
49+
- `datasource.url: process.env["DATABASE_URL"]` — the connection string the CLI uses.
50+
51+
### Troubleshooting
52+
53+
If a `prisma generate` / `prisma migrate` command misbehaves, check `prisma.config.ts` before assuming the schema is at fault:
54+
55+
- **"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.
56+
- **CLI can't find the schema or migrations** — these paths are relative to `backend/`. Running `prisma` from the repo root will not resolve them.
57+
- **`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.
58+
3459
## /v1 API
3560

3661
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)