feat: add Prisma Compute examples#8556
Conversation
Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
WalkthroughAdds three Prisma Compute deployment examples (Hono, Next.js, TanStack Start) with READMEs, Prisma configs/schemas, seed scripts, app code, build/config files, and skipped test placeholders. ChangesPrisma Compute Deployment Examples
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
deployment-platforms/prisma-compute/nextjs/src/lib/prisma.ts (1)
13-13: ⚡ Quick winCache the PrismaClient on
globalThisto avoid dev connection exhaustion.In Next.js, module-scoped instantiation is re-run on every hot reload during
next dev, creating a new client and Postgres pool each time and eventually exhausting connections. The recommended pattern stores the instance onglobalThisoutside production.♻️ Proposed singleton pattern
const adapter = new PrismaPg({ connectionString: databaseUrl }); -export const prisma = new PrismaClient({ adapter }); +const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient }; + +export const prisma = globalForPrisma.prisma ?? new PrismaClient({ adapter }); + +if (process.env.NODE_ENV !== "production") { + globalForPrisma.prisma = prisma; +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@deployment-platforms/prisma-compute/nextjs/src/lib/prisma.ts` at line 13, The PrismaClient is instantiated per module load causing connection exhaustion in dev; change the export to use a singleton cached on globalThis: check for an existing globalThis.__prisma (or similar unique symbol) and only create new PrismaClient({ adapter }) when missing, then assign it to globalThis.__prisma and export that shared instance (use the PrismaClient constructor and adapter symbol from this file); keep normal direct instantiation in production (NODE_ENV === 'production') or still assign to globalThis to simplify.deployment-platforms/prisma-compute/tanstack-start/.gitignore (1)
5-6: ⚡ Quick winCommit the initial Prisma migration instead of ignoring it.
The README tells users to create an
initmigration, butprisma/migrationsis ignored here, so the example can't version that schema history. That makes the sample less reproducible and prevents production-stylemigrate deployflows from working out of the box.♻️ Suggested change
.env .prisma -prisma/migrations src/generated/prisma🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@deployment-platforms/prisma-compute/tanstack-start/.gitignore` around lines 5 - 6, Remove prisma/migrations from the ignore list so the initial migration can be committed; specifically update the .gitignore entry that currently ignores "prisma/migrations" (and optionally ".prisma" if that prevents committing necessary artifacts) and commit the generated init migration into the repo so the README's instructions and migrate deploy workflows work out of the box.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@deployment-platforms/prisma-compute/hono/package.json`:
- Line 13: The "compute:deploy" npm script in package.json uses POSIX shell
expansion ("$DATABASE_URL"), which fails on Windows; update that script to use a
cross-platform approach: install and use a tool like "cross-env" or a small Node
wrapper script to inject process.env.DATABASE_URL into the prisma-cli call.
Specifically update the "compute:deploy" script entry (and/or add a
"scripts/deploy.js" wrapper) so it passes the DATABASE_URL value to prisma-cli
without POSIX-only syntax, e.g., invoke cross-env with DATABASE_URL or call a
Node script that reads process.env.DATABASE_URL and executes prisma-cli with the
--env argument.
In `@deployment-platforms/prisma-compute/hono/README.md`:
- Around line 30-37: The snippet uses POSIX-only commands ("set -a" and "source
.env") which will fail on cmd.exe/PowerShell; update the README to explicitly
label the snippet as "Bash/Zsh (POSIX) only" and either add a short Windows
alternative (PowerShell and cmd equivalents) or recommend a cross-platform
approach (e.g., using a dotenv helper or npm script) so users can run "npm run
compute:deploy" on Windows too; reference the existing commands "set -a",
"source .env", and "npm run compute:deploy" when making the change.
In `@deployment-platforms/prisma-compute/hono/src/index.ts`:
- Around line 32-37: The HTML response is inserting unescaped user fields
(user.name, user.email, user.username) into a raw template literal passed to
c.html, creating XSS risk; update the route handler that builds the list (the
code block that calls c.html with the mapped users) to either use Hono's html
tagged template helper or explicitly escape those interpolated values before
interpolation so names/emails/handles cannot inject HTML/JS; locate the template
construction around the c.html call and replace the raw `${...}` interpolations
with the html`...` tagged template or a safe-escape function applied to
user.name, user.email, and user.username.
In `@deployment-platforms/prisma-compute/tanstack-start/package.json`:
- Around line 12-13: The "compute:deploy" npm script in package.json uses
POSIX-style shell variable expansion and breaks on Windows; replace it with a
cross-platform approach by creating a small Node deploy helper (e.g.,
scripts/deploy.js) that reads process.env.DATABASE_URL and spawns "prisma-cli
app deploy --framework tanstack-start" with the DATABASE_URL passed in the child
process env, then update the "compute:deploy" script to run that Node helper (or
alternatively use the cross-env package to set DATABASE_URL in a cross-platform
way).
---
Nitpick comments:
In `@deployment-platforms/prisma-compute/nextjs/src/lib/prisma.ts`:
- Line 13: The PrismaClient is instantiated per module load causing connection
exhaustion in dev; change the export to use a singleton cached on globalThis:
check for an existing globalThis.__prisma (or similar unique symbol) and only
create new PrismaClient({ adapter }) when missing, then assign it to
globalThis.__prisma and export that shared instance (use the PrismaClient
constructor and adapter symbol from this file); keep normal direct instantiation
in production (NODE_ENV === 'production') or still assign to globalThis to
simplify.
In `@deployment-platforms/prisma-compute/tanstack-start/.gitignore`:
- Around line 5-6: Remove prisma/migrations from the ignore list so the initial
migration can be committed; specifically update the .gitignore entry that
currently ignores "prisma/migrations" (and optionally ".prisma" if that prevents
committing necessary artifacts) and commit the generated init migration into the
repo so the README's instructions and migrate deploy workflows work out of the
box.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ef03e4f2-d053-45d8-aa56-cfd25e60f608
📒 Files selected for processing (43)
README.mddeployment-platforms/README.mddeployment-platforms/prisma-compute/README.mddeployment-platforms/prisma-compute/hono/.env.exampledeployment-platforms/prisma-compute/hono/.gitignoredeployment-platforms/prisma-compute/hono/README.mddeployment-platforms/prisma-compute/hono/package.jsondeployment-platforms/prisma-compute/hono/prisma.config.tsdeployment-platforms/prisma-compute/hono/prisma/schema.prismadeployment-platforms/prisma-compute/hono/prisma/seed.tsdeployment-platforms/prisma-compute/hono/src/index.tsdeployment-platforms/prisma-compute/hono/src/lib/prisma.tsdeployment-platforms/prisma-compute/hono/tsconfig.jsondeployment-platforms/prisma-compute/nextjs/.env.exampledeployment-platforms/prisma-compute/nextjs/.gitignoredeployment-platforms/prisma-compute/nextjs/README.mddeployment-platforms/prisma-compute/nextjs/next.config.tsdeployment-platforms/prisma-compute/nextjs/package.jsondeployment-platforms/prisma-compute/nextjs/prisma.config.tsdeployment-platforms/prisma-compute/nextjs/prisma/schema.prismadeployment-platforms/prisma-compute/nextjs/prisma/seed.tsdeployment-platforms/prisma-compute/nextjs/src/app/api/users/route.tsdeployment-platforms/prisma-compute/nextjs/src/app/layout.tsxdeployment-platforms/prisma-compute/nextjs/src/app/page.tsxdeployment-platforms/prisma-compute/nextjs/src/lib/prisma.tsdeployment-platforms/prisma-compute/nextjs/tsconfig.jsondeployment-platforms/prisma-compute/tanstack-start/.env.exampledeployment-platforms/prisma-compute/tanstack-start/.gitignoredeployment-platforms/prisma-compute/tanstack-start/README.mddeployment-platforms/prisma-compute/tanstack-start/package.jsondeployment-platforms/prisma-compute/tanstack-start/prisma.config.tsdeployment-platforms/prisma-compute/tanstack-start/prisma/schema.prismadeployment-platforms/prisma-compute/tanstack-start/prisma/seed.tsdeployment-platforms/prisma-compute/tanstack-start/src/lib/prisma.server.tsdeployment-platforms/prisma-compute/tanstack-start/src/routeTree.gen.tsdeployment-platforms/prisma-compute/tanstack-start/src/router.tsxdeployment-platforms/prisma-compute/tanstack-start/src/routes/__root.tsxdeployment-platforms/prisma-compute/tanstack-start/src/routes/api/users.tsdeployment-platforms/prisma-compute/tanstack-start/src/routes/index.tsxdeployment-platforms/prisma-compute/tanstack-start/src/styles.cssdeployment-platforms/prisma-compute/tanstack-start/tsconfig.jsondeployment-platforms/prisma-compute/tanstack-start/vite.config.tstests/deployment-platforms.test.ts
Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
|
Manual verification update:
Repo test run: |
Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
|
Correction after checking I was using the wrong live Compute env flow in the earlier manual deploy test. The examples should not pass
I updated the examples to add Manual verification after the fix:
Repo test still passes: |
Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@deployment-platforms/prisma-compute/nextjs/package.json`:
- Around line 12-16: Replace the nondeterministic uses of npx `@prisma/cli`@latest
in the compute scripts (compute:login, compute:database:create, compute:deploy,
compute:open, compute:logs) by pinning `@prisma/cli` to a specific tested version
that matches the project’s prisma version; update the script command strings to
use that pinned version (e.g., npx `@prisma/cli`@<version>) and apply the same
change to the identical scripts in the other package.json files referenced (hono
and tanstack-start) so deployments are reproducible.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: be700d07-5973-45da-bf66-ec8f2b4fa0b8
📒 Files selected for processing (10)
deployment-platforms/prisma-compute/README.mddeployment-platforms/prisma-compute/hono/README.mddeployment-platforms/prisma-compute/hono/package.jsondeployment-platforms/prisma-compute/hono/prisma/seed.tsdeployment-platforms/prisma-compute/nextjs/README.mddeployment-platforms/prisma-compute/nextjs/package.jsondeployment-platforms/prisma-compute/nextjs/prisma/seed.tsdeployment-platforms/prisma-compute/tanstack-start/README.mddeployment-platforms/prisma-compute/tanstack-start/package.jsondeployment-platforms/prisma-compute/tanstack-start/prisma/seed.ts
✅ Files skipped from review due to trivial changes (5)
- deployment-platforms/prisma-compute/tanstack-start/README.md
- deployment-platforms/prisma-compute/README.md
- deployment-platforms/prisma-compute/hono/package.json
- deployment-platforms/prisma-compute/tanstack-start/package.json
- deployment-platforms/prisma-compute/nextjs/README.md
🚧 Files skipped from review as they are similar to previous changes (3)
- deployment-platforms/prisma-compute/tanstack-start/prisma/seed.ts
- deployment-platforms/prisma-compute/hono/prisma/seed.ts
- deployment-platforms/prisma-compute/nextjs/prisma/seed.ts
Adds Prisma Compute examples for Hono, Next.js, and TanStack Start.
Each example includes Prisma ORM with PostgreSQL, seed data, local scripts, and deployment scripts that call
npx @prisma/cli@latestdirectly. The examples do not install or pin@prisma/cli.The Compute flow now matches the latest CLI:
compute:deploypasses.envto Prisma Compute withapp deploy --env .env, so the deployed app uses the same database URL used for local migrate/seed.Validation:
npm install --no-package-lockinhono,nextjs, andtanstack-startDATABASE_URL='postgresql://user:pass@localhost:5432/db' npm run db:generatein all three examplesDATABASE_URL='postgresql://user:pass@localhost:5432/db' npm run buildin all three examplesnpx vitest run tests/deployment-platforms.test.ts(test file is currently skipped)Summary by CodeRabbit
New Features
Documentation
Chores
Tests