t3-code-android-nightly/.repos/alchemy-effect/examples/prisma-compute-effect
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00
..
src chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170) 2026-10-05 13:22:30 -07:00
alchemy.run.ts chore(refs): sync Alchemy reference to beta.76 (#10654) 2026-09-07 21:54:45 -07:00
package.json chore(refs): sync Effect and Alchemy references to rc.115 and beta.78 (#12327) 2026-09-17 23:21:25 -07:00
README.md chore(refs): sync Effect and Alchemy references to rc.115 and beta.78 (#12327) 2026-09-17 23:21:25 -07:00
tsconfig.json chore(refs): sync Alchemy reference to beta.76 (#10654) 2026-09-07 21:54:45 -07:00

Prisma Compute Effect

Minimal Effect-native Prisma Compute app managed by Alchemy.

This example is intentionally not a framework app. It shows the provider-native runtime path:

  • Prisma.Project
  • Prisma.Postgres
  • Prisma.Connection
  • Prisma.Compute(..., Effect.gen(...))
  • Prisma.Connect(Connection) inside the deployed runtime

alchemy.run.ts only wires the stack together. The Prisma data resources live in src/Database.ts, and the Effect-native Compute app lives in src/Api.ts.

Prisma creates the project-owned default main branch as part of project creation. The database and app select that branch by branchGitName instead of trying to manage the default branch as a standalone resource.

The deployed app responds on / and /api/health. The health route reports whether the runtime database binding is available without exposing connection strings or infrastructure IDs. It verifies binding delivery, not a database query.

Durable State Prerequisite

This stack always uses Cloudflare.state(). Alchemy state is stored in a Cloudflare Worker backed by a Durable Object with embedded SQLite; its bearer token and encryption key live in Cloudflare Secrets Store. There is intentionally no local-state fallback. Alchemy does not currently ship a Prisma-hosted remote state store, so this example selects the built-in durable backend explicitly.

Before the first deploy, make one Cloudflare account available to every trusted operator and CI runner that will deploy or destroy this stack, then bootstrap the state store once:

export CLOUDFLARE_ACCOUNT_ID="..."
export CLOUDFLARE_API_TOKEN="..."
bunx alchemy provider cloudflare bootstrap

Keep those Cloudflare credentials configured for every later deploy and destroy. The default state-store Worker is shared across stacks and stages; Alchemy scopes this stack's records by stack name and stage.

Deploy

export CLOUDFLARE_ACCOUNT_ID="..."
export CLOUDFLARE_API_TOKEN="..."
export PRISMA_SERVICE_TOKEN="..."
export PRISMA_EFFECT_APP="my-team-effect-api-production"
bun run deploy --stage production

The App name must be stable and unique within the Prisma workspace. The example defaults it from the Alchemy stage for local use; production and CI should set PRISMA_EFFECT_APP to a deterministic environment-specific value. The Project name is provider-generated by default so interrupted creates can be recovered safely; set PRISMA_PROJECT only when an externally fixed Console name is required.

Copy the url value from the deploy output before checking the app:

URL="https://your-app.prisma.build"

Check It

curl --fail-with-body --show-error "$URL/"
curl --fail-with-body --show-error "$URL/api/health"

The response should include:

{
  "ok": true,
  "mode": "effect-native",
  "databaseBinding": "ready"
}

Destroy

export CLOUDFLARE_ACCOUNT_ID="..."
export CLOUDFLARE_API_TOKEN="..."
export PRISMA_SERVICE_TOKEN="..."
export PRISMA_EFFECT_APP="my-team-effect-api-production"
bun run destroy --stage production