→ cards/10-prisma7-next16

Chapter

10 · Next 16 + Prisma 7 Upgrade

Prereqs, config, and client patterns for Prisma 7 (adapter-first) on Next 16.

Upgrade Snapshot

  • Node: =20.19+ (Prisma 7 engine requirement).
  • Packages: prisma@7.x + @prisma/client@7.x (match versions).
  • Adapter-first: Postgres/MySQL need an adapter (e.g., @prisma/adapter-pg).
  • Config lives in prisma.config.ts; prisma/schema.prisma stays for models.
  • Regenerate after any schema bump: npx prisma generate.

Prisma 7 Setup Steps

  • Install: npm install prisma@7 @prisma/client@7 @prisma/adapter-pg (swap adapter per DB).
  • Init/upgrade config: keep schema at prisma/schema.prisma; add prisma.config.ts with env-driven URLs.
  • Client init: supply adapter for Postgres/MySQL; cache PrismaClient in dev to avoid HMR bloat.
  • Commands: npx prisma generate then npx prisma db push (or migrate) after schema edits.
  • Deployment: ensure envs (DATABASE_URL, SHADOW_DATABASE_URL) and Node 20 runtime on the platform.

Config Snippets (Prisma 7)

// prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
schema: "prisma/schema.prisma",
migrations: { path: "prisma/migrations", seed: "tsx prisma/seed.ts" },
datasource: {
url: env("DATABASE_URL"),
shadowDatabaseUrl: env("SHADOW_DATABASE_URL", { optional: true }),
},
});
// lib/prisma.ts — Postgres example
import { PrismaClient } from "@prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";

const globalForPrisma = globalThis as { prisma?: PrismaClient };
const adapter = new PrismaPg();
const prisma =
globalForPrisma.prisma ??
new PrismaClient({
adapter,
log: process.env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
export default prisma;

Next 16 Alignment

  • Stay on Next 16.x with React 19.x; rerun npm install after dependency bumps.
  • Run npm run lint and npm run build to surface React/Next breaking changes.
  • Use Node 20+ locally and on deploy (Vercel will read .node-version/engines).

Future Work · Dynamic Chapters/Cards (note)

// Prompt to generalize chapters/cards registry
// - Add actions (app/cards/actions) to create/update chapters + auto-generate cards from section snippets.
// - Add interface (form) to add chapters/sections; derive card summary + snippets automatically.
// - Add context/provider to refresh via Suspense (Next 13+/16 patterns) after mutations.
// - Persist chapters/cards to DB or file; revalidate paths after writes.