From 9bd2716d5d6f2178a6f6883baa4b60c222f0acc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=89=E1=85=B5=E1=86=AB=E1=84=83=E1=85=A9=E1=86=BC?= =?UTF-8?q?=E1=84=92=E1=85=A7=E1=86=AB?= Date: Thu, 14 May 2026 16:08:07 +0900 Subject: [PATCH] fix(skills): fix code block formatting in prisma-patterns - Split bash/TS mixed block in expand-and-contract example into separate blocks - Replace DATABASE_URL string concatenation with env var embedding pattern --- skills/prisma-patterns/SKILL.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/skills/prisma-patterns/SKILL.md b/skills/prisma-patterns/SKILL.md index f53f2f27..8524ec40 100644 --- a/skills/prisma-patterns/SKILL.md +++ b/skills/prisma-patterns/SKILL.md @@ -211,15 +211,20 @@ Catch at the service boundary and translate to domain errors. Never expose raw P ### Connection Pool — Serverless +Embed connection params directly in `DATABASE_URL` — string concatenation breaks if the URL already has query parameters (e.g. `?schema=public`): + +```bash +# .env — preferred: embed params in the URL +DATABASE_URL="postgresql://user:pass@host/db?connection_limit=1&pool_timeout=20" + +# With an external pooler (PgBouncer, Supabase pooler) +DATABASE_URL="postgresql://user:pass@host/db?pgbouncer=true&connection_limit=1" +``` + ```ts // Vercel, AWS Lambda, and similar serverless runtimes: cap pool to 1 per instance -const prisma = new PrismaClient({ - datasources: { - db: { url: process.env.DATABASE_URL + '?connection_limit=1&pool_timeout=20' }, - }, -}); -// Recommended: add an external pooler (PgBouncer, Supabase pooler) in front of the DB -// DATABASE_URL="postgresql://...?pgbouncer=true&connection_limit=1" +// connection_limit and pool_timeout are controlled via DATABASE_URL +const prisma = new PrismaClient(); ``` ## Anti-Patterns @@ -291,10 +296,14 @@ Adding `NOT NULL` to an existing column or renaming a column in one migration wi # Step 1: create migration locally, then deploy npx prisma migrate dev --name add_new_column # local only npx prisma migrate deploy # staging / production +``` -# Step 2: backfill data +```ts +// Step 2: backfill data (run in a script or migration job, not in the shell) await prisma.user.updateMany({ data: { newColumn: derivedValue } }); +``` +```bash # Step 3: create the NOT NULL constraint migration locally, then deploy npx prisma migrate dev --name make_new_column_required # local only npx prisma migrate deploy # staging / production