Prisma ORM makes relational database access feel natural in TypeScript. You get autocomplete on table fields, compile-time safety, and readable migration scripts.
However, moving from a local tutorial to production traffic taught me a few important lessons about managing PostgreSQL with Prisma.
Prisma makes relations simple with @relation, but it doesn't automatically add database indexes to foreign key columns. If you query orders by userId, PostgreSQL will perform a sequential table scan unless you explicitly index it:
❯prisma
model Order {
id String @id @default(uuid())
userId String
user User @relation(fields: [userId], references: [id])
total Float
createdAt DateTime @default(now())
@@index([userId])
@@index([createdAt])
}
Adding @@index on lookup fields drops query times from 200ms down to 3ms when tables grow past a few thousand rows.
When deploying Next.js API routes or Server Actions to serverless environments (like Vercel), each function invocation can create a new database connection. Without pooling, you can easily exhaust your PostgreSQL connection limits.
Always use a connection pooler like PgBouncer or connection pooling URLs provided by Supabase or Neon (?pgbouncer=true or pool mode).
Let Prisma generate your SQL migrations through prisma migrate dev --name <description>. Review the generated SQL file before committing it, and run prisma migrate deploy in your production deployment pipeline.