Dev migration breaking with new release (4.4.0)
See original GitHub issueBug description
I have a Docker + Docker-compose setup for my Typescript + Fastify + Prisma project. Everything was working fine till yesterday when all of a sudden my docker container would hang at startup. It would happen at the step when running Prisma migrations (on migrate dev), soon realized that it was not creating new migrations. I had changed the schema.prisma file (modified and removed some columns). When I reverted the changes the docker container ran successfully and my server was up. To understand the issue I moved to a previous release(4.3.1) of Prisma and then made changes to schema.prism again, this time it worked as expected.
Dockerfile:
FROM node:lts As development
WORKDIR /app
RUN npm install -g pnpm
RUN npm install -g ts-node
COPY wait-for-it.sh .
RUN chmod +x wait-for-it.sh
COPY package*.json .
RUN npm i
COPY tsconfig.json .
COPY prisma .
COPY .env .
EXPOSE 3000
docker-compose
version: "3.8"
networks:
app-network:
driver: bridge
services:
server:
build: .
container_name: server
ports:
- 3000:3000
links:
- postgres
depends_on:
- postgres
environment:
DATABASE_URL: postgresql://postgres:topsecret@postgres:5432/luminai-local?schema=public&connect_timeout=600
volumes:
- ./src:/app/src
networks:
- app-network
command: bash -c "./wait-for-it.sh postgres:5432 -- npx prisma generate && npx prisma migrate dev && npm run dev"
postgres:
image: postgres:14
container_name: postgres
hostname: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: topsecret
POSTGRES_DB: luminai-local
restart: always
networks:
- app-network
pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
depends_on:
- postgres
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: root
ports:
- 5050:80 # Access to pgadmin: localhost:5050
networks:
- app-network
package.json
"dependencies": {
"@prisma/client": "4.4.0",
.....
},
"devDependencies": {
"prisma": "4.4.0",
.....
}
Dropping the ^ fixed the issue for now.
How to reproduce
- Go to schema.prisma and change the columns
- run docker-compose on local machine
- docker container gets stuck
- No error per say, it just gets stuck:
wait-for-it.sh: waiting 15 seconds for postgres:5432
wait-for-it.sh: postgres:5432 is available after 5 seconds
Environment variables loaded from .env
Prisma schema loaded from schema.prisma
✔ Generated Prisma Client (4.4.0 | library) to ./node_modules/@prisma/client in 182ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
Environment variables loaded from .env
Prisma schema loaded from schema.prisma
Datasource "db": PostgreSQL database "luminai-local", schema "public" at "postgres:5432"
Applying migration `20220914231319_`
The following migration(s) have been applied:
migrations/
└─ 20220914231319_/
└─ migration.sql
Expected behavior
The expected behavior: it proceeds to print the line Your database is now in sync with your schema.
after running migrations.
Prisma information
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
binaryTargets = ["rhel-openssl-1.0.x", "native"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
role Role @default(Agent)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
firebaseId String? @unique
active Boolean @default(true)
team Team @relation(fields: [teamId], references: [id])
teamId Int
}
model Team {
id Int @id @default(autoincrement())
name String @unique
user User[]
active Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum Role {
Agent
Admin
}
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export default prisma;
Environment & setup
- OS: macOS
- Database: PostgreSQL
- Node.js version: v16.15.0
Prisma Version
4.4.0
Issue Analytics
- State:
- Created a year ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Yes definitely said it the wrong way. However was not saying the change was in the translation, saying that wether 4.3.1 or 4.4.0 you would get a precision = 3 as transaltion and if the client were doing an insertion with higher precision it will not work. Nevertheless you are right on your initial point, as long as the client is not involve you should not face any issue.
We did not change the Prisma schema type and what it is translated to in the database in 4.4.0 @iiAku. We changed how values are modified before being inserted into the database. No changes for database schema and migrations, only for Prisma Client queries handling.