| 1 | # Prisma Compute Effect |
| 2 | |
| 3 | Minimal Effect-native Prisma Compute app managed by Alchemy. |
| 4 | |
| 5 | This example is intentionally not a framework app. It shows the provider-native |
| 6 | runtime path: |
| 7 | |
| 8 | - `Prisma.Project` |
| 9 | - `Prisma.Postgres` |
| 10 | - `Prisma.Connection` |
| 11 | - `Prisma.Compute(..., Effect.gen(...))` |
| 12 | - `Prisma.Connect(Connection)` inside the deployed runtime |
| 13 | |
| 14 | `alchemy.run.ts` only wires the stack together. The Prisma data resources live |
| 15 | in `src/Database.ts`, and the Effect-native Compute app lives in |
| 16 | `src/Api.ts`. |
| 17 | |
| 18 | Prisma creates the project-owned default `main` branch as part of project |
| 19 | creation. The database and app select that branch by `branchGitName` instead of |
| 20 | trying to manage the default branch as a standalone resource. |
| 21 | |
| 22 | The deployed app responds on `/` and `/api/health`. The health route reports |
| 23 | whether the runtime database binding is available without exposing connection |
| 24 | strings or infrastructure IDs. It verifies binding delivery, not a database |
| 25 | query. |
| 26 | |
| 27 | ## Durable State Prerequisite |
| 28 | |
| 29 | This stack always uses `Cloudflare.state()`. Alchemy state is stored in a |
| 30 | Cloudflare Worker backed by a Durable Object with embedded SQLite; its bearer |
| 31 | token and encryption key live in Cloudflare Secrets Store. There is |
| 32 | intentionally no local-state fallback. Alchemy does not currently ship a |
| 33 | Prisma-hosted remote state store, so this example selects the built-in durable |
| 34 | backend explicitly. |
| 35 | |
| 36 | Before the first deploy, make one Cloudflare account available to every trusted |
| 37 | operator and CI runner that will deploy or destroy this stack, then bootstrap |
| 38 | the state store once: |
| 39 | |
| 40 | ```sh |
| 41 | export CLOUDFLARE_ACCOUNT_ID="..." |
| 42 | export CLOUDFLARE_API_TOKEN="..." |
| 43 | bunx alchemy provider cloudflare bootstrap |
| 44 | ``` |
| 45 | |
| 46 | Keep those Cloudflare credentials configured for every later deploy and |
| 47 | destroy. The default state-store Worker is shared across stacks and stages; |
| 48 | Alchemy scopes this stack's records by stack name and stage. |
| 49 | |
| 50 | ## Deploy |
| 51 | |
| 52 | ```sh |
| 53 | export CLOUDFLARE_ACCOUNT_ID="..." |
| 54 | export CLOUDFLARE_API_TOKEN="..." |
| 55 | export PRISMA_SERVICE_TOKEN="..." |
| 56 | export PRISMA_EFFECT_APP="my-team-effect-api-production" |
| 57 | bun run deploy --stage production |
| 58 | ``` |
| 59 | |
| 60 | The App name must be stable and unique within the Prisma workspace. The example |
| 61 | defaults it from the Alchemy stage for local use; production and CI should set |
| 62 | `PRISMA_EFFECT_APP` to a deterministic environment-specific value. The Project |
| 63 | name is provider-generated by default so interrupted creates can be recovered |
| 64 | safely; set `PRISMA_PROJECT` only when an externally fixed Console name is |
| 65 | required. |
| 66 | |
| 67 | Copy the `url` value from the deploy output before checking the app: |
| 68 | |
| 69 | ```sh |
| 70 | URL="https://your-app.prisma.build" |
| 71 | ``` |
| 72 | |
| 73 | ## Check It |
| 74 | |
| 75 | ```sh |
| 76 | curl --fail-with-body --show-error "$URL/" |
| 77 | curl --fail-with-body --show-error "$URL/api/health" |
| 78 | ``` |
| 79 | |
| 80 | The response should include: |
| 81 | |
| 82 | ```json |
| 83 | { |
| 84 | "ok": true, |
| 85 | "mode": "effect-native", |
| 86 | "databaseBinding": "ready" |
| 87 | } |
| 88 | ``` |
| 89 | |
| 90 | ## Destroy |
| 91 | |
| 92 | ```sh |
| 93 | export CLOUDFLARE_ACCOUNT_ID="..." |
| 94 | export CLOUDFLARE_API_TOKEN="..." |
| 95 | export PRISMA_SERVICE_TOKEN="..." |
| 96 | export PRISMA_EFFECT_APP="my-team-effect-api-production" |
| 97 | bun run destroy --stage production |
| 98 | ``` |