Skip to content

Rename stage to environment: prisma deploy --environment, destroy({ environment }) - #390

Merged
wmadden merged 8 commits into
mainfrom
claude/environment-rename-fdf6ab
Oct 28, 2026
Merged

wmadden merged 8 commits into
mainfrom
claude/environment-rename-fdf6ab

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
# before
prisma deploy --stage staging
prisma deploy                          # production: the deploy with no stage

# after
prisma deploy --environment staging
prisma deploy                          # the environment production, same Branch as before
prisma deploy --stage staging
# ✘ [CLI.COMMAND_MOVED] `--stage` on `deploy` has been replaced
# → Use the replacement: prisma deploy --environment <name>
// before
await destroy({ target: { kind: 'stage', stage: 'staging' }, config });
await destroy({ target: { kind: 'production' }, config });
// after
await destroy({ environment: 'staging', config });
await destroy({ environment: 'production', config });

The decision

ADR-0059 (merged in #385) decided that a place the app runs is an environment, not a stage. This PR makes every public surface say so, as one breaking release, so users change --stage to --environment once.

Every environment now has a name, and none is special. Before, production was the deploy without a stage, and code everywhere carried stage: string | undefined, with undefined meaning production. Now core carries environment: string everywhere. prisma deploy and prisma deploy list default the flag to production. prisma dev runs as the environment dev. destroy has no default: a call without a name fails with DEPLOY.ENVIRONMENT_REQUIRED, so a missing value can still never tear down production.

Where production lives on Prisma Cloud

Core never compares a name with production. That mapping lives in the Prisma Cloud extension:

  • production resolves exactly as a deploy without --stage did: the Project's default Branch, found by its isDefault flag. Resources carry no branchId, the Build has no branch reference, and the deploy state is the same, so existing apps don't move.
  • Any other name is the Branch with that gitName, created on deploy if absent.
  • A name whose Branch is the default Branch, such as main, is refused. It would be production under a second name, and destroying it would tear production down.

Verified against Prisma Cloud with a throwaway app: --environment staging created and used a staging Branch; a deploy with no flag landed on the isDefault Branch; --environment main was refused; destroying staging deleted its Branch; destroying production removed the then-empty Project.

Mismatched versions are refused, not misread

The prisma CLI pins its Composer version, and the app installs its own @prisma/composer-prisma-cloud, so the two can differ. The released 0.35.0 extension reads the old stage field, so under this release it would read every environment as production and deploy staging into production. Core therefore checks each resolved container as the Alchemy child will rebuild it, through the extension's own deserialize(serialize()). An older extension rebuilds { appName, stage }, the environment is missing, and the deploy or destroy fails with DEPS.EXTENSION_INCOMPATIBLE before anything is deployed or destroyed. The extension, in turn, refuses a request with no environment, which is what an older Composer sends.

Verified with an app installed from npm on 0.35.0: prisma deploy --environment staging stopped with DEPS.EXTENSION_INCOMPATIBLE at the connect step.

Smaller consequences

  • --stage on deploy fails with CLI.COMMAND_MOVED naming --environment, through the CLI engine's redirect table. deploy list gets no redirect yet. The engine refuses to start when a redirect names a command the host hasn't mounted, and this repository's examples and CI run the released prisma 8.0.0-rc.26, which doesn't mount deploy list. The redirect can be added once that devDependency is a release that mounts it.
  • Error codes: DEPLOY.ENVIRONMENT_INVALID, ENVIRONMENT_UNVALIDATABLE, and ENVIRONMENT_REQUIRED are new, and DEPS.EXTENSION_INCOMPATIBLE is new. STAGE_INVALID, STAGE_UNVALIDATABLE and SCOPE_MISSING are retired. The registry in ADR-0044 is updated.
  • A plain name such as production or pr-42 validates without running git, so a deploy still needs no git on PATH.
  • The --report JSON's stage field is now environment, at report version 2.
  • Guides, the agent skill, the examples, scripts/composer-destroy.ts and the deploy-verify-destroy CI action use --environment. The deploying guide and the skill have an upgrade note.
  • Alchemy keeps its own word: Composer still passes Alchemy a --stage, whose value on Prisma Cloud is the Branch id.

For the prisma CLI repository

When it takes this release, any test that mounts Composer's family without deploy will fail at startup, because the family's --stage redirect names deploy. composer-mount.test.ts mounts only the dev commands and emulator list, so it needs deploy added.

Not in this PR

  • prisma dev --environment. Giving each environment its own complete local copy is new behaviour, not a rename, so it is the next slice (spec in .drive/projects/public-urls/slices/c3-local-environments/spec.md). That slice also stops dev url and dev stop acting on whichever app ran last in the folder.
  • Older decision records keep their history. ADR-0038, ADR-0043 and ADR-0053 get one-line amendment notes pointing to ADR-0059. docs(design): a service is public only through a declared public URL, whose hostname resolve() computes per environment #386 amends ADR-0024 and ADR-0050; until it merges, those two still show --stage with no pointer.
  • Pre-existing: the @storefront-auth/storefront page integration test fails identically on a clean main on the author's machine.

Alternatives considered

  • Keep --stage as an alias. Rejected by ADR-0059: two words for one concept drift apart in guides, errors and agent output.
  • Keep production nameless. Rejected: forgetting a flag would silently land a deploy, or a destroy, on production.
  • Send the old stage field too, for one release, for older extensions. Rejected: core would have to know that production means "no stage", which is Prisma Cloud's mapping, not core's. Refusing the mismatch is target-neutral and safe.
  • A version field on the extension interface, checked at config load. Cleaner, and it would also cover prisma dev, but it adds a field every extension must carry. The round trip uses the contract that already exists; slice C3 adds the check to prisma dev.
  • Redirect --stage on deploy list too. Rejected for now: it would crash today's released prisma CLI at startup.

Agent: achilles-41

🤖 Generated with Claude Code

wmadden-electric and others added 5 commits October 27, 2026 19:09
prisma deploy and prisma deploy list take --environment <name>, defaulting
to production. --stage is retired through the CLI engine's redirect on
deploy, so it fails with CLI.COMMAND_MOVED naming --environment. The destroy
operation takes a required environment name instead of a stage/production
target and refuses a call without one (DEPLOY.ENVIRONMENT_REQUIRED).

Core carries environment names only. The Prisma Cloud extension maps
production to the Project's default Branch by isDefault, exactly where a
deploy without --stage landed before, and any other name to the Branch with
that gitName. A name whose Branch is the default Branch is refused, since it
would be production under a second name. prisma dev runs as the environment
dev; per-environment local copies are later work.

The --report JSON's stage field becomes environment (format version 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The deploying guide explains once that on Prisma Cloud an environment is a
Branch. The examples' destroy scripts and the deploy-verify-destroy CI
action pass --environment explicitly. The deploy and local-dev domain docs
describe environments; older decision records keep their history.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The prisma CLI pins its Composer version while the app installs its own
Prisma Cloud extension, so the two can differ. An extension older than the
CLI reads every environment as production. Core now checks that each
resolved container carries the environment it asked for and fails with
DEPLOY.CONTAINER_MISMATCH before anything is deployed or destroyed; the
extension refuses a request with no environment, from a CLI older than it.

A plain name such as production, staging or pr-42 is a valid git ref by
construction, so it validates without running git and a deploy still needs
no git on PATH.

Also from review: the default-Branch refusal reads right for destroy, the
report version is pinned at 2, internal names say what they mean, the error
registry in ADR-0044 lists the new codes, older records whose examples show
the old interface point to ADR-0059, and the guide and skill carry an
upgrade note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@prisma-gizmo

prisma-gizmo Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

✅ Gizmo reviewed cbb8682 — posted 0 inline comment(s) this pass.

Open findings: 🟡 1 minor

Change walkthrough

Change walkthrough

This PR renames "stage" to "environment" everywhere users can see it — prisma deploy --environment, destroy({ environment }) — per ADR-0059, so production stops being "a deploy with no stage" and becomes the environment named production. It ships as one breaking release rather than keeping an alias.

Core operations. execute-deploy-destroy.ts and the operation inputs carry environment: string end to end; deploy and deploy list default it to production, destroy requires it (DEPLOY.ENVIRONMENT_REQUIRED), and plain names validate without git on PATH.

Version-skew guard (the latest delta). The final fix commit reworks requireContainerForEnvironment to rebuild each container the way the Alchemy child will — descriptor.deserialize(instance.serialize()) — and compare the rebuilt input.environment with the requested name, failing with DEPS.EXTENSION_INCOMPATIBLE. This closes the gap the round-2 review documents: the released 0.35.0 extension passes the input object through (so the old direct comparison always matched) while resolving from input.stage. Its deserialize rebuilds only { appName, stage }, so the round-trip exposes it. The new tests in operations.test.ts use a fixture that mimics the released extension, assert refusal before preflight, Alchemy, teardown or removal, and cover a throwing deserialize and same-version acceptance. The check is documented honestly in the deploy-cli domain doc, including that an older extension's ensure may already have created an empty Project.

Prisma Cloud mapping. The lowering's resolveBranch extracts refuseDefaultBranch and now applies the default-Branch-under-another-name refusal to the 409-race recovery path too (previously the race winner was adopted unconditionally), with a new test. production still resolves to the isDefault Branch with no branchId, so existing apps don't move; the extension refuses environment-less requests from older CLIs.

CLI surface. --stage on deploy fails with CLI.COMMAND_MOVED through the engine's redirect table; deploy list keeps no redirect and reports CLI.INVALID_ARGUMENTS, now pinned in deploy-list.test.ts, with the deferral reason corrected in the spec and docs.

Docs and records. The ADR-0044 registry, deploying guide, skill, both slice specs and the two added round-2 review records are consistent with the implemented codes and behavior; the review records are point-in-time documents whose findings the fix commit addresses.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8e7e913d-e201-43bc-9b95-8d274f75cf3f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@prisma/composer@390
npm i https://pkg.pr.new/@prisma/composer-cli@390
npm i https://pkg.pr.new/@prisma/composer-prisma-cloud@390

commit: b137d16

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: 🟡 1 minor · trace

wmadden-electric and others added 2 commits October 27, 2026 19:56
The released 0.35.0 extension keeps the input object core hands it, so
comparing instance.input.environment always passed while that extension
resolved production from input.stage. Core now checks the container as
the Alchemy child will rebuild it, through deserialize(serialize()); the
0.35.0 deserialize rebuilds { appName, stage } and the check fires. The
failure is DEPS.EXTENSION_INCOMPATIBLE, since it is an installed-version
problem. Verified against an app installed with 0.35.0 from npm.

Also: the default-Branch refusal now applies after a Branch create race,
and the deploy list --stage test asserts the engine's error code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: none · trace

Still open from previous reviews: 🟡 1 minor

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Gizmo finding is open and the head commit has been reviewed. Approving.

@wmadden
wmadden enabled auto-merge (squash) October 28, 2026 07:35
@wmadden
wmadden merged commit 3708c63 into main Oct 28, 2026
22 of 23 checks passed
@wmadden
wmadden deleted the claude/environment-rename-fdf6ab branch October 28, 2026 07:45
wmadden-electric added a commit that referenced this pull request Oct 28, 2026
Brings in ADR-0059 (environment, not stage), the stage-to-environment rename (#390), the node-addressing close-out (#391), v0.35.0 (#389) and prisma dev --environment (#392).

The secrets behaviour follows each environment: the dev preflight keeps its fingerprint key in the environment folder, and deletes a leftover secrets.json both there and in the pre-environment folder. Moving pre-environment state into dev no longer moves secrets.json; it deletes it. Tests pass the environment, and our docs say environment where main renamed stage and environment variables where they mean variables.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants