Skip to content

feat: add Prisma Compute examples#8556

Merged
AmanVarshney01 merged 4 commits into
latestfrom
aman/prisma-compute-examples
Jun 11, 2026
Merged

feat: add Prisma Compute examples#8556
AmanVarshney01 merged 4 commits into
latestfrom
aman/prisma-compute-examples

Conversation

@AmanVarshney01

@AmanVarshney01 AmanVarshney01 commented Jun 2, 2026

Copy link
Copy Markdown
Member

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@latest directly. The examples do not install or pin @prisma/cli.

The Compute flow now matches the latest CLI:

npm run compute:login
npm run compute:database:create
npm run db:generate
npm run db:migrate -- --name init
npm run db:seed
npm run compute:deploy

compute:deploy passes .env to Prisma Compute with app deploy --env .env, so the deployed app uses the same database URL used for local migrate/seed.

Validation:

  • npm install --no-package-lock in hono, nextjs, and tanstack-start
  • DATABASE_URL='postgresql://user:pass@localhost:5432/db' npm run db:generate in all three examples
  • DATABASE_URL='postgresql://user:pass@localhost:5432/db' npm run build in all three examples
  • npx vitest run tests/deployment-platforms.test.ts (test file is currently skipped)

Summary by CodeRabbit

  • New Features

    • Added three Prisma Compute demo apps (Hono, Next.js, TanStack Start) with runnable examples, web UIs and JSON API endpoints, database schemas, seed data, and npm scripts for dev/build/deploy.
  • Documentation

    • Added comprehensive READMEs covering local setup, database create/migrate/seed, and deployment workflows for each demo.
  • Chores

    • Added .env example templates, .gitignore files, TypeScript and build configurations per demo.
  • Tests

    • Added skipped test suites for the new Prisma Compute examples.

Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds 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.

Changes

Prisma Compute Deployment Examples

Layer / File(s) Summary
Documentation and project overview
README.md, deployment-platforms/README.md, deployment-platforms/prisma-compute/README.md
Root and deployment-platforms READMEs updated to document the three new Prisma Compute deployment examples with links and descriptions.
Hono Node.js HTTP server deployment
deployment-platforms/prisma-compute/hono/*
Hono example with .env.example, .gitignore, package.json, prisma.config.ts, prisma/schema.prisma, prisma/seed.ts, src/lib/prisma.ts, src/index.ts (HTML and /api/users routes), tsconfig.json, and README documenting local run and Prisma Compute deploy commands.
Next.js App Router deployment
deployment-platforms/prisma-compute/nextjs/*
Next.js App Router example with .env.example, .gitignore, package.json, next.config.ts, prisma.config.ts, prisma/schema.prisma, prisma/seed.ts, Prisma client module, src/app layout and page, src/app/api/users/route.ts, tsconfig, and README with deploy instructions.
TanStack Start fullstack deployment
deployment-platforms/prisma-compute/tanstack-start/*
TanStack Start example including .env.example, .gitignore, package.json, Prisma config/schema/seed, server Prisma client, generated routeTree.gen.ts, router wiring, root/layout/routes (/ and /api/users), styles, Vite config, tsconfig, and README with deploy steps.
Deployment platform test placeholders
tests/deployment-platforms.test.ts
Three new skipped test suites for Hono, Next.js, and TanStack Start examples marked as requiring Prisma Compute account setup.

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • prisma/prisma-examples#8260: Adds/updates prisma.config.ts using defineConfig + dotenv/config in other example subprojects; closely related configuration pattern.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add Prisma Compute examples' accurately and concisely summarizes the main change: adding new Prisma Compute deployment examples for three frameworks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
deployment-platforms/prisma-compute/nextjs/src/lib/prisma.ts (1)

13-13: ⚡ Quick win

Cache the PrismaClient on globalThis to 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 on globalThis outside 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 win

Commit the initial Prisma migration instead of ignoring it.

The README tells users to create an init migration, but prisma/migrations is ignored here, so the example can't version that schema history. That makes the sample less reproducible and prevents production-style migrate deploy flows 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

📥 Commits

Reviewing files that changed from the base of the PR and between 663c23c and 254e61f.

📒 Files selected for processing (43)
  • README.md
  • deployment-platforms/README.md
  • deployment-platforms/prisma-compute/README.md
  • deployment-platforms/prisma-compute/hono/.env.example
  • deployment-platforms/prisma-compute/hono/.gitignore
  • deployment-platforms/prisma-compute/hono/README.md
  • deployment-platforms/prisma-compute/hono/package.json
  • deployment-platforms/prisma-compute/hono/prisma.config.ts
  • deployment-platforms/prisma-compute/hono/prisma/schema.prisma
  • deployment-platforms/prisma-compute/hono/prisma/seed.ts
  • deployment-platforms/prisma-compute/hono/src/index.ts
  • deployment-platforms/prisma-compute/hono/src/lib/prisma.ts
  • deployment-platforms/prisma-compute/hono/tsconfig.json
  • deployment-platforms/prisma-compute/nextjs/.env.example
  • deployment-platforms/prisma-compute/nextjs/.gitignore
  • deployment-platforms/prisma-compute/nextjs/README.md
  • deployment-platforms/prisma-compute/nextjs/next.config.ts
  • deployment-platforms/prisma-compute/nextjs/package.json
  • deployment-platforms/prisma-compute/nextjs/prisma.config.ts
  • deployment-platforms/prisma-compute/nextjs/prisma/schema.prisma
  • deployment-platforms/prisma-compute/nextjs/prisma/seed.ts
  • deployment-platforms/prisma-compute/nextjs/src/app/api/users/route.ts
  • deployment-platforms/prisma-compute/nextjs/src/app/layout.tsx
  • deployment-platforms/prisma-compute/nextjs/src/app/page.tsx
  • deployment-platforms/prisma-compute/nextjs/src/lib/prisma.ts
  • deployment-platforms/prisma-compute/nextjs/tsconfig.json
  • deployment-platforms/prisma-compute/tanstack-start/.env.example
  • deployment-platforms/prisma-compute/tanstack-start/.gitignore
  • deployment-platforms/prisma-compute/tanstack-start/README.md
  • deployment-platforms/prisma-compute/tanstack-start/package.json
  • deployment-platforms/prisma-compute/tanstack-start/prisma.config.ts
  • deployment-platforms/prisma-compute/tanstack-start/prisma/schema.prisma
  • deployment-platforms/prisma-compute/tanstack-start/prisma/seed.ts
  • deployment-platforms/prisma-compute/tanstack-start/src/lib/prisma.server.ts
  • deployment-platforms/prisma-compute/tanstack-start/src/routeTree.gen.ts
  • deployment-platforms/prisma-compute/tanstack-start/src/router.tsx
  • deployment-platforms/prisma-compute/tanstack-start/src/routes/__root.tsx
  • deployment-platforms/prisma-compute/tanstack-start/src/routes/api/users.ts
  • deployment-platforms/prisma-compute/tanstack-start/src/routes/index.tsx
  • deployment-platforms/prisma-compute/tanstack-start/src/styles.css
  • deployment-platforms/prisma-compute/tanstack-start/tsconfig.json
  • deployment-platforms/prisma-compute/tanstack-start/vite.config.ts
  • tests/deployment-platforms.test.ts

Comment thread deployment-platforms/prisma-compute/hono/package.json Outdated
Comment thread deployment-platforms/prisma-compute/hono/README.md Outdated
Comment thread deployment-platforms/prisma-compute/hono/src/index.ts
Comment thread deployment-platforms/prisma-compute/tanstack-start/package.json Outdated
Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
@AmanVarshney01

Copy link
Copy Markdown
Member Author

Manual verification update:

  • Compared the examples against fresh official starters from create-next-app@16.2.7, create-hono@0.19.4, and @tanstack/cli@0.68.0.
  • Refreshed stale package/config bits: @prisma/cli@3.0.0-beta.2, next@16.2.7, current React typings, Vite patch, and TanStack Nitro config/path aliases matching the official CLI shape.
  • Local Prisma flow passed for all three examples with real temporary Prisma Postgres URLs from create-db: prisma generate, prisma migrate dev -- --name init, prisma db seed.
  • Build passed for all three examples: Hono tsc, Next.js next build, TanStack Start vite build.
  • Prisma Compute framework packaging check: Hono and TanStack deploy without --env; TanStack returned a running deployment. Hono deployed but restarted because DATABASE_URL was missing, as expected.
  • Usable deploy with --env DATABASE_URL=... currently fails for Hono, Next.js, and TanStack Start in @prisma/cli@3.0.0-beta.2 with DEPLOY_FAILED: Unrecognized key(s) in object: 'envVars' after local build completes. I also tested @prisma/cli@3.0.0-beta.1; it fails the same way. So the templates build and migrate/seed correctly, but the current Prisma Compute CLI/API env-var deploy path is blocked.

Repo test run: npx vitest run tests/deployment-platforms.test.ts.

Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
@AmanVarshney01

Copy link
Copy Markdown
Member Author

Correction after checking /Users/aman/dev/work/prisma-cli and rerunning the flow:

I was using the wrong live Compute env flow in the earlier manual deploy test. The examples should not pass DATABASE_URL through app deploy --env .... The working flow is:

  1. prisma-cli project create <name> or prisma-cli project link <id-or-name>
  2. Export/load DATABASE_URL locally
  3. prisma-cli project env add DATABASE_URL --role production
  4. prisma-cli app deploy --framework ...

I updated the examples to add compute:env:add / compute:env:update scripts and removed --env DATABASE_URL=... from compute:deploy.

Manual verification after the fix:

  • Hono: npm run compute:deploy -- --project ... --app ... --yes --json succeeded, and /api/users returned 2 seeded users.
  • Next.js: full flow passed (project create, compute:env:add, compute:deploy), and /api/users returned 2 seeded users.
  • TanStack Start: full flow passed (project create, compute:env:add, compute:deploy), and /api/users returned 2 seeded users.

Repo test still passes: npx vitest run tests/deployment-platforms.test.ts.

Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 07a2e1b and e91d290.

📒 Files selected for processing (10)
  • deployment-platforms/prisma-compute/README.md
  • deployment-platforms/prisma-compute/hono/README.md
  • deployment-platforms/prisma-compute/hono/package.json
  • deployment-platforms/prisma-compute/hono/prisma/seed.ts
  • deployment-platforms/prisma-compute/nextjs/README.md
  • deployment-platforms/prisma-compute/nextjs/package.json
  • deployment-platforms/prisma-compute/nextjs/prisma/seed.ts
  • deployment-platforms/prisma-compute/tanstack-start/README.md
  • deployment-platforms/prisma-compute/tanstack-start/package.json
  • deployment-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

Comment thread deployment-platforms/prisma-compute/nextjs/package.json
@AmanVarshney01
AmanVarshney01 merged commit 6d44921 into latest Jun 11, 2026
7 of 9 checks passed
@AmanVarshney01
AmanVarshney01 deleted the aman/prisma-compute-examples branch June 11, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant