prisma: prisma migrate dev fails with Error: P1017 (prisma > 5.9.1)
Bug description
prisma migrate dev fails with P1017: Server has closed the connection for any prisma version after 5.9.1
This error happens even when the prisma.schema doesn’t have any changes.
Reverting to 5.9.1 solves the issue.
> DEBUG=* yarn prisma migrate dev --create-only
prisma:schemaEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"devDiagnostic","params":{"migrationsDirectoryPath":"/Users/<user>/src/<project>/prisma/migrations"}} +2ms
prisma:schemaEngine:stderr {"timestamp":"2024-06-14T23:42:31.423091Z","level":"INFO","fields":{"message":"Starting schema engine RPC server","git_hash":"..."},"target":"schema_engine"} +9ms
prisma:schemaEngine:stderr {"timestamp":"2024-06-14T23:43:14.769293Z","level":"ERROR","fields":{"message":"Error in PostgreSQL connection: Error { kind: Closed, cause: None }"},"target":"quaint::connector::postgres::native"} +43348ms
prisma:schemaEngine:rpc {
"jsonrpc": "2.0",
"error": {
"code": 4466,
"message": "An error happened. Check the data field for details.",
"data": {
"is_panic": false,
"message": "Server has closed the connection.",
"meta": null,
"error_code": "P1017"
}
},
"id": 1
} +2ms
Error: Error: P1017
Server has closed the connection.
at Object.<anonymous> /Users/<user>/src/<project>/node_modules/prisma/build/index.js:525:8)
at rc.handleResponse (/Users/<user>/src/<project>/node_modules/prisma/build/index.js:516:2821)
at Pl.<anonymous> (/Users/<user>/src/<project>/node_modules/prisma/build/index.js:521:490)
at Pl.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at Pl._pushBuffer (/Users/<user>/src/<project>/node_modules/prisma/build/index.js:510:369)
at Pl._transform (/Users/<user>/src/<project>/node_modules/prisma/build/index.js:510:199)
at Transform._write (node:internal/streams/transform:175:8)
How to reproduce
- Install any
prismaversion above5.9.1 - Run
yarn prisma migrate devoryarn prisma migrate dev --create-only - See error
Expected behavior
No response
Prisma information
// Add your schema.prisma
// no changes
Environment & setup
- OS:
macOS - Database:
PostgreSQL - Node.js version:
v18.19.0
Prisma Version
5.15.0
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 3
- Comments: 15 (2 by maintainers)
Have done a bit more digging here. For us, this seems to be an issue with port forwarding that surfaced when we migrated from Docker Desktop to Rancher Desktop. Using
kubectlto port forward results in the following port forwarding error when trying to generate migrations:When I instead enable port forwarding using the Rancher Desktop application,
migrate devruns successfully.Hello, I have exactly the same issue
Running a postgresql (16) database locally on macos (M1) in a kubernetes cluster set up via orbstack Thank you Andrey for finding out that version
5.9.1is workingHere are the logs of postgres when I start the server then do a
DEBUG=* npx prisma migrate dev --create-only --skip-generateThe logs of the command above are:
I’ve concluded that the problem lies in Tilt port-forwards. It’s not the same as a docker compose exposed port. Perhaps something like only accepting a single connection and
prismausing multiple during migrate? Not sure.But, a solution that works for me now is to run a locally built prisma tool container in the dev cluster and using that to handle migrations. It’s a little fiddly, could use a better way to sync files back to the project directory, but I don’t see a better way at the moment.
Here’s my setup: ./Dockerfile.prisma
./kustomize/bases/prisma.yaml
./Tiltfile
./prisma.sh
Usage:
The results of the migration are copied to the local paths, which are synced back into the container via Tilt and thus present on the next prisma tool use.
It’s kind of a hack, but it works.
I made a repo to reproduce this, with a version compatibility test system.
https://github.com/skaramicke/prisma-6.3.1-p1017
Legend
Results
This is for all major PostgreSQL versions from 10 and up, and all Prisma minor versions from 5.9 and up, including a couple of extra prisma versions that snuck in.
Results
Code:
To run this you need
make,kindandkubectlmake cleanto remove versioned test dataMIN_version variables in Makefile if needed.make versions/postgresqlto get all postgresql versions, or just specify manually.make versions/prismato get all prisma versions above the specified minumum, or just specify them manually.make version_make_targetsto fill in the test combinations.make all_versionsto run all tests.Or just run
./test_compatibility.sh <PostgreSQL version> <Prisma version>to test a specific version once.The individual results and logs are created in
./results/<PostgreSQL version>/<Prisma version>/In my case, kubectl is working, because the Postgres log shows the migration SELECT command.