Six months ago, I was debugging a 502 error on a Next.js app for a Dubai logistics client. The culprit? Prisma’s schema misalignment with a PostgreSQL database that had grown messy over time. I fixed it by rebuilding the client-facing booking flow in Tawasul Limo using Prisma 4.0's include syntax—saving 0.4 seconds per request. That’s when I realized how many production-grade habits I've picked up using Prisma in Next.js projects aren’t obvious from the official docs.
Initializing Prisma in Next.js Projects (App Router Style)
When a client in Abu Dhabi wanted bilingual property listings for Reach Home, I started every project with npx prisma init and immediately configured the .env file to point to a Neon Postgres database. Version 4.3 lets you generate types directly for Next.js app router patterns—no more manually importing types from @prisma/client in API routes.
I always add a schema.prisma field for soft-deleted records:
model Property {
id Int @id @default(autoincrement())
title String
deletedAt DateTime?
}This made it easier to recover accidentally deleted listings—something UAE clients request often after Ramadan campaigns. Use softDelete in generate block if you need automatic filtering but be cautious: Neon Postgres's performance considerations apply when using indexes on nullable columns.
Solving N+1 Queries the Hard Way
I’ll be real: Prisma’s default lazy loading bit me in a React Native property listing app. For Greeny Corner, fetching 20 plant records each with 3 related entries caused 61 queries. The fix? Eager loading with include:
prisma.plants.findMany({
include: {
careGuide: true,
photos: { take: 2 }
}
})But this can backfire. Once, a DAS Holding admin dashboard had a 9-table join through include, creating 4.3MB JSON payloads. Switching to select with explicit fields reduced that to 0.7MB—proving why UAE clients prefer lean dashboard data.
Deployment and Migration Workflows
For Tawasul Limo, we pushed schema changes to Neon Postgres using GitHub Actions. This 5-step deployment process works:
prisma migrate dev --create-onlycreates a new migration locally- Test SQL diff in staging database
- Commit migration files to
prisma/migrations/ - Use
prisma migrate deployin production deployment script - Wait 30s for Neon's DNS to sync before health checks
This saved 3 hours of panic deployment time compared to using PlanetScale in a different project. Automating migrations feels like riding a bike with training wheels—until you hit complex schema changes.
Performance Gotchas Nobody Talks About
I wasted 4 hours debugging a findFirst() that returned stale data because I forgot to set { cacheBuster: Date.now() } in a server component for an e-commerce project. Prisma caches heavily in server contexts—it’s why my Laravel API testing workflow emphasizes fresh data fetching in test cases.
Another gotcha: using raw SQL for full-text search when Postgres's to_tsvector functions and GIN indexes would’ve sufficed. The UAE market loves filtering by Arabic/English combinations, but mixing ILIKE with Prisma's search operators led to 700ms query spikes on Reach Home’s listings.
UAE-Specific Prisma Configurations
Arabic text direction and UTF-8 encoding require two things in every schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
relationMode = "foreignKeys"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["clientEnums"]
}This setup helped avoid encoding errors in Tawasul Limo's Arabic dashboard. Use utf8mb4_unicode_ci if your client needs mixed language support—UAE businesses expect this now after 2026's new e-commerce law.
Frequently Asked Questions
Can I use Prisma with MySQL in UAE-based Next.js apps?
Yes, but not ideal for complex queries. MySQL lacks native JSON type support that Postgres handles better—critical for UAE clients needing Arabic/English dual storage in the same record. Neon’s Postgres makes this smoother.
How do I handle Prisma migrations in production safely?
Create migration files locally, test SQL diff, then run prisma migrate deploy via GitHub Actions after deployment. Always add 30s delay before health checks to avoid Postgres connection issues in Neon.
How do I solve Prisma’s N+1 query performance?
Use include with relations and take filters for shallow reads. For deeper analysis, wrap queries in prisma.$executeRaw with EXPLAIN ANALYZE to benchmark before/after.
Should I generate client types before building a Next.js app?
Yes. Run prisma generate before next build in CI/CD. Skipping this causes runtime errors in API routes—something I learned painfully during a late-night deployment for a Dubai food delivery app.
Looking to optimize your Next.js app's database layer? Book a free consultation to discuss production patterns that work in real GCC business contexts. I've shipped 40+ apps using these techniques—including Tawasul Limo’s luxury booking engine that processes 200+ daily reservations in UAE.