Skip to content

Commit 6c89b9c

Browse files
feat(cli): support compute app regions (#101)
## Summary - adds `prisma-cli app deploy --region <region>` for new app creation - reads typed `region` defaults from `prisma.compute.ts` through `@prisma/compute-sdk@0.31.0` - keeps existing apps in their current region; explicit `--region` mismatches fail with a usage error - documents deploy-all behavior and rejects `--region` as a per-app flag for bare multi-app deploys ## Examples ```ts import { defineComputeConfig } from \"@prisma/compute-sdk/config\"; export default defineComputeConfig({ region: \"us-west-1\", apps: { api: { root: \"apps/api\", framework: \"hono\" }, web: { root: \"apps/web\", framework: \"nextjs\", region: \"eu-west-3\" }, }, }); ``` ```sh prisma-cli app deploy --app my-app --region us-west-1 prisma-cli app deploy api ``` `region` only applies when deploy creates a new app. Existing apps are not moved between regions. ## Testing - `pnpm --filter @prisma/cli test` - `pnpm --recursive exec tsc --noEmit` - `pnpm lint`
1 parent 7833e62 commit 6c89b9c

14 files changed

Lines changed: 769 additions & 287 deletions

File tree

docs/product/command-spec.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Out of scope for the current beta:
5858
non-TTY stderr, and when `NO_UPDATE_NOTIFIER` is set. When shown, update
5959
notifications are stderr-only human output and do not change the original
6060
command result.
61-
- Public Beta does not read or write committed config files such as `prisma.config.ts` or `.prisma/settings.json` for Project -> Branch resolution. `.prisma/local.json` is a gitignored local pin/cache, not a declarative repo config file. `prisma.app.json` is legacy and no longer read or written. `prisma.compute.ts` supplies typed `app deploy` defaults (app name, app root, framework, entrypoint, HTTP port, env inputs) and never selects Project or Branch scope.
61+
- Public Beta does not read or write committed config files such as `prisma.config.ts` or `.prisma/settings.json` for Project -> Branch resolution. `.prisma/local.json` is a gitignored local pin/cache, not a declarative repo config file. `prisma.app.json` is legacy and no longer read or written. `prisma.compute.ts` supplies typed `app deploy` defaults (app name, app region, app root, framework, entrypoint, HTTP port, env inputs) and never selects Project or Branch scope.
6262
- Remote commands do not silently change local context.
6363

6464
## Authentication
@@ -126,6 +126,9 @@ multiple targets, no argument, and nothing inferred from the invocation
126126
directory, they fall back to the selection order above — except step 7;
127127
management commands never create apps or mutate remote state to resolve one.
128128

129+
Config `region` and `--region` are not app selectors. They are used only when
130+
`app deploy` creates a new app; existing apps keep their current region.
131+
129132
`.prisma/local.json` pins the directory to a Workspace and Project only. It does
130133
not pin an App ID. App services are branch-scoped; a service ID from `main`
131134
must not be reused automatically when the user deploys from `feat/billing`.
@@ -927,7 +930,7 @@ prisma-cli app run --build-type bun --entry server.ts --port 3000
927930
prisma-cli app run api
928931
```
929932

930-
## `prisma-cli app deploy [app] --project <id-or-name> --create-project <name> --app <name> --branch <name> --framework <nextjs|nuxt|astro|hono|nestjs|tanstack-start|custom|bun> --entry <path> --http-port <port> --env <name=value|file> --db --no-db --prod`
933+
## `prisma-cli app deploy [app] --project <id-or-name> --create-project <name> --app <name> --branch <name> --framework <nextjs|nuxt|astro|hono|nestjs|tanstack-start|custom|bun> --entry <path> --http-port <port> --region <region> --env <name=value|file> --db --no-db --prod`
931934

932935
Purpose:
933936

@@ -943,7 +946,8 @@ Compute config file (`prisma.compute.ts`):
943946
- the config defines exactly one of:
944947
- `app` — a single-app repository
945948
- `apps` — a multi-app or monorepo repository, keyed by deploy target name
946-
- each app accepts `name`, `root`, `framework`, `entry`, `httpPort`, `env`, and `build`:
949+
- each app accepts `name`, `region`, `root`, `framework`, `entry`, `httpPort`, `env`, and `build`:
950+
- `region` is the Compute region id used when deploy creates a new app; existing apps keep their current region
947951
- `env` is a dotenv file path, or `{ file, vars }` with file path(s) and inline assignments
948952
- `build` is `{ command, outputDirectory, entrypoint }`; all fields are optional except where a framework requires enough information to stage a runnable artifact, and `command: null` skips the build step
949953
- `build.entrypoint` is the built artifact entrypoint when `outputDirectory` is set, and is the source entrypoint for Bun/Hono configs that do not set an output directory
@@ -959,14 +963,15 @@ with ORM config keys, and `database.schema` will become unnecessary once the
959963
unified file's own `schema` field is in scope. Project, branch, and
960964
production targeting stay out of committed config in the unified file for the
961965
same reasons they are excluded today.
962-
- config values are deploy defaults; explicit flags always win: `--framework`, `--entry`, `--http-port` override per value, and any `--env` flag replaces the config env inputs entirely
966+
- config values are deploy defaults; explicit flags always win: `--framework`, `--entry`, `--http-port`, and `--region` override per value, and any `--env` flag replaces the config env inputs entirely
963967
- the config `name` (or the `apps` key when `name` is absent) selects the app like `--app`, but ranks below both `--app` and `PRISMA_APP_ID`
968+
- `--region` and config `region` apply only when the resolved app does not exist yet and deploy creates it; `--app` and `PRISMA_APP_ID` still control which app is selected
964969
- `root` is a relative path inside the repository; framework detection, entrypoint resolution, build settings, and the build/upload run in that directory while Project binding and the local pin stay in the config file's directory
965970
- `prisma.compute.ts` never selects Project or Branch scope; project resolution is unchanged
966971
- the `[app]` argument selects an `apps` target by key:
967972
- without an `[app]` argument, a command run from inside a target's `root` selects that target, so `cd apps/api && prisma-cli app deploy` deploys `api`; the deepest matching root wins and an ambiguous tie selects nothing
968973
- with multiple `apps` entries, no `[app]` argument, and no target inferred from the invocation directory, deploy deploys every target sequentially in declaration order — the config declares the system, and a bare `prisma-cli app deploy` ships it
969-
- deploying all targets rejects per-app inputs (`--app`, `--framework`, `--entry`, `--http-port`, `--env`, `PRISMA_APP_ID`) with a usage error; project- and branch-level flags (`--project`, `--create-project`, `--branch`, `--db`, `--no-db`, `--prod`, `--yes`) apply to the whole run, with `--create-project` creating and binding the Project once before the first target
974+
- deploying all targets rejects per-app inputs (`--app`, `--framework`, `--entry`, `--http-port`, `--region`, `--env`, `PRISMA_APP_ID`) with a usage error; project- and branch-level flags (`--project`, `--create-project`, `--branch`, `--db`, `--no-db`, `--prod`, `--yes`) apply to the whole run, with `--create-project` creating and binding the Project once before the first target
970975
- a deploy-all run stops at the first failure and reports the targets already live; `--json` output aggregates one full deploy result per target
971976
- `app build` and `app run` still require a target in multi-app configs and fail with `COMPUTE_CONFIG_TARGET_REQUIRED` (a dev server cannot run N apps at once; build keeps the same shape)
972977
- an `[app]` argument that matches no target fails with `COMPUTE_CONFIG_TARGET_UNKNOWN`
@@ -983,6 +988,7 @@ import { defineComputeConfig } from "@prisma/compute-sdk/config";
983988
export default defineComputeConfig({
984989
app: {
985990
name: "api",
991+
region: "eu-central-1",
986992
framework: "hono",
987993
httpPort: 8080,
988994
env: ".env",
@@ -1079,6 +1085,7 @@ prisma-cli app deploy
10791085
prisma-cli app deploy --project proj_123
10801086
prisma-cli app deploy --create-project my-app --yes
10811087
prisma-cli app deploy --app my-app --env DATABASE_URL=postgresql://example
1088+
prisma-cli app deploy --app my-app --region us-west-1
10821089
prisma-cli app deploy --db
10831090
prisma-cli app deploy --db --yes
10841091
prisma-cli app deploy --no-db

docs/product/resource-model.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Rules:
104104
- the runtime app service is scoped by branch in the platform model
105105
- the app may be selected or created as part of app deployment workflows
106106
- app selection is local CLI state when needed for the beta package
107+
- app region is set at app creation time; `prisma.compute.ts` can provide the new-app default, but deploys to existing apps do not move them between regions
107108
- app build settings live in the `build` block of `prisma.compute.ts` (`command`, `outputDirectory`, `entrypoint`); `prisma.app.json` is legacy and no longer read
108109

109110
### Deployment

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"dependencies": {
4646
"@clack/prompts": "^1.5.0",
47-
"@prisma/compute-sdk": "0.30.0",
47+
"@prisma/compute-sdk": "0.31.0",
4848
"@prisma/credentials-store": "^7.8.0",
4949
"@prisma/management-api-sdk": "^1.44.0",
5050
"better-result": "^2.9.2",

packages/cli/src/commands/app/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ function createDeployCommand(runtime: CliRuntime): Command {
228228
"HTTP port override for the deployed app",
229229
),
230230
)
231+
.addOption(
232+
new Option(
233+
"--region <region>",
234+
"Region for a newly created app; existing apps keep their region",
235+
),
236+
)
231237
.addOption(
232238
new Option(
233239
"--env <name=value|file>",
@@ -250,6 +256,7 @@ function createDeployCommand(runtime: CliRuntime): Command {
250256
const branchName = (options as { branch?: string }).branch;
251257
const framework = (options as { framework?: string }).framework;
252258
const httpPort = (options as { httpPort?: string }).httpPort;
259+
const region = (options as { region?: string }).region;
253260
const envAssignments = (options as { env?: string[] }).env;
254261
const projectRef = (options as { project?: string }).project;
255262
const createProjectName = (options as { createProject?: string })
@@ -281,6 +288,7 @@ function createDeployCommand(runtime: CliRuntime): Command {
281288
entrypoint: entry,
282289
framework,
283290
httpPort,
291+
region,
284292
envAssignments,
285293
prod: prod === true,
286294
db,

0 commit comments

Comments
 (0)