Performance: Prisma migrations
Prisma migrations affect backend database schema updates and can indirectly impact frontend load times if migrations block API responses.
Run migrations as a separate deployment step before starting the app, or use Prisma migrate deploy CLI asynchronously.
await prisma.$executeRaw`ALTER TABLE users ADD COLUMN age INT;` // run migration synchronously on app start
| Pattern | Backend Blocking | API Startup Delay | User Impact | Verdict |
|---|---|---|---|---|
| Synchronous migration during app start | Yes | High (seconds) | Slower API response, delayed page load | [X] Bad |
| Separate migration step before app start | No | None | Fast API startup, better user experience | [OK] Good |
npx prisma migrate dev --name is used to create and apply migrations during development.migrate deploy applies migrations in production, generate creates Prisma client code, and migrate reset resets the database.model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
// Command run:
npx prisma migrate dev --name addNameFieldnpx prisma migrate dev --name addNameField creates a migration file reflecting this change and applies it to the database.npx prisma migrate deploy in production but get an error saying migrations are missing. What is the likely cause?migrate deploy applies existing migration files to production; it does not create them.age Int to your User model in Prisma. However, your database already has existing users without this field. What is the best way to handle this migration safely?Pass the test and this pattern moves unknown