mirror of
https://github.com/VibedByKaKi/t3-code-android-nightly.git
synced 2026-10-10 20:31:16 +02:00
98 lines
3 KiB
Markdown
98 lines
3 KiB
Markdown
# 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:
|
|
|
|
```sh
|
|
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
|
|
|
|
```sh
|
|
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:
|
|
|
|
```sh
|
|
URL="https://your-app.prisma.build"
|
|
```
|
|
|
|
## Check It
|
|
|
|
```sh
|
|
curl --fail-with-body --show-error "$URL/"
|
|
curl --fail-with-body --show-error "$URL/api/health"
|
|
```
|
|
|
|
The response should include:
|
|
|
|
```json
|
|
{
|
|
"ok": true,
|
|
"mode": "effect-native",
|
|
"databaseBinding": "ready"
|
|
}
|
|
```
|
|
|
|
## Destroy
|
|
|
|
```sh
|
|
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
|
|
```
|