organizationId rule, see Organizations.
Schema files
The schema is a directory,prisma/schema/, not a single file. Each module ships its own schema file, so adding a module never means editing core files.
Back-relation fields on
User and Organization are written by the kit’s generator into wa:relations regions. Don’t edit inside them by hand. npx gato generate rewrites them from installed modules:
prisma/schema/organizations.prisma
organizationId with a cascading relation.
prisma/schema/invoices.prisma
Invoice has an organizationId field, the runtime tenant-scope guard covers it automatically.
Configuration
Prisma CLI commands readprisma.config.ts:
prisma.config.ts
DATABASE_URL. A value in .env.local wins over .env, and a variable set in your shell wins over both. The app reads the same variable.
Client and connection
prisma generate writes the client to src/generated/prisma, which is git-ignored. It runs on postinstall, and manually with:
@/generated/prisma/client for types, and use the shared instance for queries:
src/shared/lib/prisma.ts
- Prisma connects through
@prisma/adapter-pgwith apgpool of up toDATABASE_POOL_MAXconnections (default10when missing or not a positive integer). - Idle connections close after 30 s, waiting for a free connection times out after 10 s, and Postgres cancels statements running longer than 30 s.
- The client carries the tenant-scope extension.
- The instance is cached on
globalThissonext devhot reloads reuse the pool.
Migrations
The kit doesn’t commit migrations; your project does. A project’s schema depends on which modules you picked, since each module adds its own schema file and relations. A migration history shipped by the kit wouldn’t match a project with a different set of modules, so each project starts its own history with an
init migration.prisma/migrations/ is ignored by a prisma/migrations/.gitignore that gato create doesn’t copy. In a project created with create-gato-app / gato create, prisma/migrations/ is not ignored, so migrations go into git with no extra steps.
Production applies only migrations committed to the repo: the deploy runs npx prisma migrate deploy, which never creates migrations from the schema. Without a committed migrations directory, the production database gets no tables. See Railway and Docker.
Your first migration
If you letcreate-gato-app run setup, it already ran npx prisma migrate dev --name init. That happens after the initial commit, so the migration is still uncommitted. Otherwise, create it yourself:
1
Make sure migrations aren't ignored
This command prints nothing when the directory isn’t ignored:
2
Create the initial migration (only if the directory is empty)
3
Commit the whole directory
Commit every migration folder with its
migration.sql and prisma/migrations/migration_lock.toml.Every schema change
- If the change could drop data or fail on existing rows (for example a new unique field with duplicates), Prisma prints
Warnings for the current datasource:and asks for confirmation. If the effect isn’t intended, answern. - Changes that can’t be executed are reported as
We found changes that cannot be executed:and nothing is created. - Never edit a migration that has been applied anywhere. Fix it with a new migration. Prisma treats a changed, already-applied migration as history drift.
After gato add, gato remove and gato update
Adding or removing a module changes prisma/schema/ (a module schema file and the wa:relations regions). The CLI prints the migration command to run next:
gato update suggests a migration only when the kit’s schema files changed between versions. Then run npm run db:generate and commit the migration with the rest of the change.
See gato add, gato remove and gato update.
Tests don’t use migrations
Integration tests build their schema withprisma db push; end-to-end tests use prisma db push --force-reset, or prisma migrate reset --force when migrations exist. Both wipe their database, so they refuse to run unless the database name ends in _test or _e2e respectively. See Testing.
Migration history drift
Prisma records applied migrations in the_prisma_migrations table. npx prisma migrate dev applies new migrations from prisma/migrations/, but refuses in two cases:
- History mismatch: the database has an applied migration that’s missing from the directory, or whose file changed since it was applied.
- Drift (
Drift detected): the database schema differs from what the migrations produce, for example because tables were created byprisma db push.
prisma migrate reset, and exits without changing anything:
First, confirm it’s your database
On a fresh clone, this message often means you’re connected to someone else’s database, for example a local Postgres or another project’s container on the same port. Migration names you never created in themissing from the local migrations directory line are the strongest signal. A reset deletes everything in the database at DATABASE_URL, so confirm all of the following first:
-
Address. The
Datasource "db": …line showslocalhostor127.0.0.1, the port you expect (DB_PORT, default5432) and your project’s database name fromdocker-compose.yml. ADATABASE_URLin your shell overrides.env.local, which overrides.env; check withecho "$DATABASE_URL". -
Port. After
docker compose stop, nothing else is listening on that port. -
Repeatable. After
docker compose up -dand a healthydbservice,npx prisma migrate devreports the same problem. -
History in the container. Reading the history directly inside your container matches Prisma’s message:
What to do
Restore migrations from git:
--source (find it with git log --oneline -- prisma/migrations).
Back up before a reset (save the file outside the repo):
prisma/migrations/. Check the Datasource line once more before answering y.