Reputation: 65
I was training on writing integration tests on a simple app and I had some of the working. After some errors I terminated the yarn command running the tests in watch mode and when restarting the same command I got the error in the object:
Error: P1017: Server has closed the connection
I am using prisma, nestjs and mySql as a database, containerized in docker. I used a code from a tutorial as a base and that one works (it is identical to the following one except for the ports, since the tutorial is using postgres)
This it the docker-compose file
version: '3.8'
services:
dev-db:
image: mysql:5.7
#platform: linux/amd64
ports:
- 3308:3306
environment:
MYSQL_ROOT_PASSWORD: 123
MYSQL_DB: dbfornest
test-db:
image: mysql:5.7
#platform: linux/amd64
ports:
- 3305:3306
environment:
MYSQL_ROOT_PASSWORD: 123
MYSQL_DB: dbfornest
These are the scripts in the json file
"db:restart": "docker compose down && docker compose up -d && sleep 1",
"pretest:int": "yarn db:restart && dotenv -e .env.test -- prisma migrate reset --force",
"test:int": "dotenv -e .env.test -- jest -i --no-cache --watch --config jest-int.json"
this is the .env file
DATABASE_URL=mysql://root:123@localhost:3308/dbfornest
this is the .env.test file
DATABASE_URL=mysql://root:123@localhost:3305/dbfornest
Upvotes: 0
Views: 1835
Reputation: 65
the error was in the docker-compose file. The correct way of naming the database for mySQL is MYSQL_DATABASE
Upvotes: 0