Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions compute/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Prisma Compute examples

These examples show Prisma ORM apps deployed to Prisma Compute.
These examples show Prisma 8 apps deployed to Prisma Compute with Prisma
Composer.

| Example | Description |
| --- | --- |
| [`hono`](./hono) | Hono API on Node.js. |
| [`nextjs`](./nextjs) | Next.js App Router app using standalone output for Prisma Compute. |
| [`tanstack-start`](./tanstack-start) | TanStack Start app using the Nitro Vite plugin output supported by Prisma Compute. |

Each example includes Prisma ORM, a PostgreSQL schema, seed data, and scripts for
local development and Prisma Compute deployment.
Each example includes a Prisma 8 contract, generated typed client metadata,
seed data, a Composer module, and a GitHub Actions deployment workflow.
Deploy the companion Console change before publishing these templates so the
one-click flow can validate and copy their Composer files.

The Compute scripts call `bunx @prisma/cli@next` directly, so the examples do
not pin or install the Prisma CLI. They use `@next` because these examples
target the Prisma 8 release candidate, while the `latest` npm tag still points
at the earlier 3.x beta CLI with a different command set. When Prisma 8 reaches
general availability, the `@next` references will switch to `@latest`.
The templates pin the Prisma 8 release candidate and its compatible Composer
integration. They use `bunx @prisma/cli@next` for Prisma Cloud commands because
the `latest` tag still points at the earlier CLI command set. These pins can
move to stable releases after Prisma 8 and the matching Composer integration
reach general availability.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
2 changes: 2 additions & 0 deletions compute/hono/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/prisma/contract.json linguist-generated
src/prisma/contract.d.ts linguist-generated
42 changes: 42 additions & 0 deletions compute/hono/.github/workflows/prisma-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: prisma-deploy

on:
push:
delete:

concurrency:
group: prisma-deploy-${{ github.event_name == 'delete' && github.event.ref || github.ref_name }}
cancel-in-progress: false
Comment thread
coderabbitai[bot] marked this conversation as resolved.

permissions:
contents: read
id-token: write
pull-requests: write

jobs:
deploy:
if: github.event_name == 'push' && github.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: prisma/cloud-deploy-action@v1
with:
build-command: bun run build

teardown:
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: prisma/cloud-deploy-action@v1
with:
mode: destroy
stage: ${{ github.event.ref }}
4 changes: 2 additions & 2 deletions compute/hono/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ node_modules
dist
.env
.prisma
prisma/migrations
src/generated/prisma
.prisma-composer
.alchemy
23 changes: 17 additions & 6 deletions compute/hono/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Prisma Compute Hono example

This is a small Hono API that uses Prisma ORM with PostgreSQL and deploys to
Prisma Compute with `@prisma/cli@next` (Prisma 8 release candidate).
This is a small Hono API that uses Prisma 8 with PostgreSQL. Prisma Composer
provisions its database and service, applies its schema, and deploys it to
Prisma Compute.

## Run locally

Expand All @@ -15,8 +16,8 @@ bun run compute:database:create

# Copy the printed DATABASE_URL into .env.

bun run db:generate
bun run db:migrate --name init
bun run contract:emit
bun run db:init
bun run db:seed
bun run dev
```
Expand All @@ -26,13 +27,23 @@ available at [http://localhost:8080/api/users](http://localhost:8080/api/users).

## Deploy to Prisma Compute

Connect this repository to a Prisma Compute project. Every push to the
connected branch then builds and deploys automatically.
Connect this repository to Prisma Cloud, then push the branch. The included
GitHub Actions workflow runs Composer, which provisions Prisma Postgres,
applies the Prisma 8 contract, and deploys the Hono service.

```bash
bun run compute:connect
```

When you change `src/prisma/contract.prisma`, emit the updated contract and
author a migration before pushing:

```bash
bun run contract:emit
bun run migration:plan --name describe-the-change
bun run db:update
```

After connecting, open the running service with:

```bash
Expand Down
947 changes: 891 additions & 56 deletions compute/hono/bun.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions compute/hono/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[install]
# Composer needs the alchemy binary and deployable builds cannot contain symlinks.
linker = "hoisted"
20 changes: 20 additions & 0 deletions compute/hono/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { module } from '@prisma/composer'
import { pnPostgres } from '@prisma/composer-prisma-cloud/prisma-next'

import { databaseContract } from './src/prisma/composer.ts'
import service from './src/service.ts'

export default module('prisma-compute-hono', ({ provision }) => {
const database = provision(
pnPostgres({
name: 'database',
contract: databaseContract,
config: 'prisma-next.config.ts',
}),
)

provision(service, {
id: 'web',
deps: { db: database },
})
})
21 changes: 11 additions & 10 deletions compute/hono/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@
"packageManager": "bun@1.3.14",
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "prisma generate && tsc",
"build": "bun run contract:emit && tsc",
"start": "node dist/index.js",
"db:generate": "prisma generate",
"db:migrate": "prisma migrate dev",
"db:seed": "prisma db seed",
"contract:emit": "prisma-next contract emit",
"migration:plan": "prisma-next migration plan",
"db:init": "prisma-next db init",
"db:update": "prisma-next db update",
"db:seed": "tsx src/prisma/seed.ts",
"compute:login": "bunx @prisma/cli@next auth login",
"compute:database:create": "bunx @prisma/cli@next postgres create prisma-compute-hono --branch main",
"compute:connect": "bunx @prisma/cli@next git connect",
"compute:open": "bunx @prisma/cli@next service open"
},
"dependencies": {
"@hono/node-server": "2.0.4",
"@prisma/adapter-pg": "7.8.0",
"@prisma/client": "7.8.0",
"@prisma/composer": "0.6.0-dev.20",
"@prisma/composer-prisma-cloud": "0.6.0-dev.20",
"@prisma/orm-postgres": "8.0.0-rc.1",
"dotenv": "17.4.2",
"hono": "4.12.23",
"pg": "8.21.0"
"hono": "4.12.23"
},
"devDependencies": {
"@types/node": "24.12.4",
"@types/pg": "8.20.0",
"prisma": "7.8.0",
"alchemy": "2.0.0-beta.67",
"tsx": "4.22.4",
"typescript": "5.9.3"
}
Expand Down
8 changes: 8 additions & 0 deletions compute/hono/prisma-composer.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from '@prisma/composer/config'
import { nodeBuild } from '@prisma/composer/node/control'
import { prismaCloud, prismaState } from '@prisma/composer-prisma-cloud/control'

export default defineConfig({
extensions: [prismaCloud(), nodeBuild()],
state: prismaState(),
})
9 changes: 9 additions & 0 deletions compute/hono/prisma-next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'dotenv/config'
import { defineConfig } from '@prisma/orm-postgres/config'

export default defineConfig({
contract: './src/prisma/contract.prisma',
db: {
connection: process.env['DATABASE_URL']!,
},
})
8 changes: 0 additions & 8 deletions compute/hono/prisma.compute.json

This file was deleted.

14 changes: 0 additions & 14 deletions compute/hono/prisma.config.ts

This file was deleted.

62 changes: 0 additions & 62 deletions compute/hono/prisma/seed.ts

This file was deleted.

47 changes: 23 additions & 24 deletions compute/hono/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { serve } from '@hono/node-server'
import { Hono } from 'hono'

import { prisma } from "./lib/prisma.js";
import { getDb } from './prisma/db.js'

const app = new Hono();
const app = new Hono()

app.get("/", async (c) => {
const users = await prisma.user.findMany({
include: { posts: true },
orderBy: { createdAt: "desc" },
});
app.get('/', async (c) => {
const users = await getDb()
.orm.public.User.include('posts')
.orderBy((user) => user.createdAt.desc())
.all()

return c.html(`<!doctype html>
<html lang="en">
Expand All @@ -32,26 +32,25 @@ app.get("/", async (c) => {
${users
.map(
(user) =>
`<li><strong>${user.name ?? user.email}</strong> <span>@${user.username ?? "no-handle"}</span> - ${user.posts.length} post(s)</li>`,
`<li><strong>${user.name ?? user.email}</strong> <span>@${user.username ?? 'no-handle'}</span> - ${user.posts.length} post(s)</li>`,
)
.join("")}
.join('')}
</ul>
</body>
</html>`);
});
</html>`)
})

app.get("/api/users", async (c) => {
const users = await prisma.user.findMany({
include: { posts: true },
orderBy: { createdAt: "desc" },
});
app.get('/api/users', async (c) => {
const users = await getDb()
.orm.public.User.include('posts')
.orderBy((user) => user.createdAt.desc())
.all()

return c.json(users);
});
return c.json(users)
})

const port = Number(process.env.PORT ?? 8080);
const port = Number(process.env.PORT ?? 8080)

serve({ fetch: app.fetch, port }, (info) => {
console.log(`Server is running on http://localhost:${info.port}`);
});

console.log(`Server is running on http://localhost:${info.port}`)
})
14 changes: 0 additions & 14 deletions compute/hono/src/lib/prisma.ts

This file was deleted.

6 changes: 6 additions & 0 deletions compute/hono/src/prisma/composer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { pnContract } from '@prisma/composer-prisma-cloud/prisma-next'

import type { Contract } from './contract.d.js'
import contractJson from './contract.json' with { type: 'json' }

export const databaseContract = pnContract<Contract>(contractJson)
Loading
Loading