Skip to content

prisma dev --environment runs a separate local copy; dev url and dev stop act on what you name - #392

Merged
wmadden merged 18 commits into
mainfrom
claude/local-environments
Oct 28, 2026
Merged

wmadden merged 18 commits into
mainfrom
claude/local-environments

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor
prisma dev --detach                              # the environment dev
prisma dev --environment test --fresh --detach   # a second, clean copy beside it
prisma dev url shop.api                          # http://localhost:3002  (dev)
prisma dev url shop.api --environment test       # http://localhost:3003  (test)
prisma dev stop --environment test               # stops test; dev keeps running

Before this change, a folder held one local copy of each app. --environment was accepted but every name shared that copy. Running another app stopped the previous one. dev url and dev stop acted on whichever app ran last.

Decision: each environment name is a complete, separate local copy

prisma dev --environment <name> runs the whole app as that environment, with its own services, databases, buckets and ports. The default is dev. Two environments of one app run at once in one folder. Elsewhere an environment is a place the app runs with its own data, and the usual reason to name one locally is a clean copy for tests that leaves working data alone.

Where each copy lives

Everything that belongs to one copy moves into .prisma-composer/dev/<environment>/: the record of local instances, the environment variable values, the placeholder secrets, the generated stack file, the artifacts and the bucket objects. The folder name is URL-encoded, because a name may contain /. Alchemy runs with --stage <environment>, so its state is already separate. Each instance gets a composer.environment label, and emulator list shows the environment at the end of each line.

Commands act on what you name

The record loses its current app. Nothing is stopped when another app or environment starts.

  • dev url <address> takes the app from the address (shop.api is the app shop) and never imports the entry.
  • dev stop takes the app from the config's entry or --name, as prisma dev and deploy list do.
  • Both take --environment, default dev. An app that never ran in that environment fails with DEV.NOT_STARTED_HERE.
  • --fresh deletes only the named environment's copy of the app. It keeps the Alchemy state of nested stages such as feature/x.

Upgrading keeps your data

The first prisma dev, dev url or dev stop after the upgrade moves the folder's existing record, environment variables, secrets and bucket objects into dev/. Databases, ports and objects survive. This overrides the per-directory record decision's rule that local state is never migrated, following the full-address decision, which rewrote the record.

Two smaller safeguards

  • On a case-insensitive filesystem, Dev and dev would share a folder. Each folder now records its environment's exact name, and a different name is refused with DEV.ENVIRONMENT_NAME_MISMATCH.
  • prisma dev now runs the extension version check that deploy runs, refusing an incompatible local target with DEPS.EXTENSION_INCOMPATIBLE.

Docs

Amendment notes on the per-directory record decision, the dev url / dev stop decision and the control subpath decision. local-dev.md, deploy-cli.md, the glossary, the running-locally and deploying guides, and the core-concepts skill are updated.

Verification

  • pnpm build, typecheck, lint and every package's tests pass. The integration tests pass, and the detach test now runs two environments side by side.
  • Manual QA against a real app passed every step, including an upgrade from the released 0.35.0 with data kept: qa.md.

Known, not fixed here

  • The two 0.35.0-dev prereleases contain the environment rename but ignore the environment locally, and they pass the extension version check. Prereleases are not a compatibility promise.
  • The build adapter's working folder, .prisma-composer/artifacts/<address>/, is still shared by every environment, so two environments starting at the same moment write to it together.

Alternatives considered

  • dev stop --environment test stops every app run as test in the folder. Rejected: the command must know which app it acts on.
  • dev url reads the app from the config's entry. Rejected: the full address already names the app, and reading the entry means importing the module.
  • Discard pre-upgrade local state. Rejected: every developer would start with empty databases.

Agent: achilles-41

🤖 Generated with Claude Code

wmadden-electric and others added 16 commits October 28, 2026 11:42
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…and environment

devEnvironmentDir(environment) names .prisma-composer/dev/<encoded name>,
percent-encoded so a / stays one folder. The devDir every local-target hook
receives is that folder, and current() is asked for one app in one
environment instead of returning the app run last.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The record (format 3) lives in the environment's folder and keeps every app
run there; nothing selects a current app or stops another one. Instances
get a composer.environment label. A pre-environment .prisma-composer/dev/
is moved into the environment dev: record, env.json, secrets.json and
bucket objects. A bucket recorded over another directory is replaced by one
over its folder, and a deployment whose artifact is no longer unpacked in
the folder is deployed again, so moved state keeps working.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Preflight writes secrets to the environment's folder, the emulators hook
ensures instances there and stops nothing else, --fresh removes only the
environment's folder and its Alchemy stage, and current() reads one app in
one environment. Preflight and teardown first move a pre-environment dev
folder into dev.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
prisma dev, dev url, dev stop and the log operation take an environment
(default dev). dev runs Alchemy at that stage with the stack file in the
environment's folder, and refuses a local target extension whose container
does not carry the environment (DEPS.EXTENSION_INCOMPATIBLE), as deploy
does. dev url reads the app from the address without importing the entry;
dev stop reads it from the entry or --name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Piped, it is the last field of each line; in human output it follows the
node and directory.

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]>
Amends the per-directory record and dev url/dev stop decisions, and updates
local-dev, the guides and the core-concepts skill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Alchemy keeps the stage feature/x inside the folder of the stage feature.
Removing the whole folder on --fresh of feature also wiped feature/x, so
its next run minted new values against instances its record still held.
Teardown now removes only the stage's own files, and its folder once empty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The move ran only inside prisma dev. After the upgrade, prisma dev stop
could not see an app started with --detach under the previous version
and failed with DEV.NOT_STARTED_HERE while the app kept running. The
local target's current lookup now runs the same idempotent move first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
On a case-insensitive filesystem, such as the default on macOS, Dev and
dev share one folder, so prisma dev --environment Dev reused dev's copy
and --fresh deleted it. The first prisma dev in an environment now writes
the exact name into the folder, --fresh keeps it, and dev, dev url,
dev stop and the log operation fail with DEV.ENVIRONMENT_NAME_MISMATCH
when it differs, before anything is torn down or read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Each layer was tested on its own, but nothing ran the real prisma dev
pipeline twice in one directory. The detach script now starts test beside
dev and checks that dev url gives each its own URL, that --fresh on test
keeps dev's bucket object, and that stopping test leaves dev answering.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Writing the name before teardown turned an unwritable .prisma-composer into
a raw ENOTDIR instead of DEV.STACK_WRITE_FAILED. The name is still checked
before teardown, and is now written in the step that already reports a
failed write of the environment's folder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
So a first run after the upgrade with a name differing only in case is
refused instead of taking over dev's data.

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 28, 2026 •

Copy link
Copy Markdown

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

Open findings: none

Change walkthrough

This PR makes each environment name (prisma dev --environment <name>, default dev) a complete, separate local copy of an app — with its own services, databases, buckets and ports under .prisma-composer/dev/<environment>/ — instead of one shared copy per folder. It also makes dev url and dev stop act on the app you name rather than whichever app ran last, and migrates pre-upgrade local state on first run.

Local dev (lowering + extensions packages). Dev state (instance record, env values, secrets, buckets) moves into per-environment folders keyed by a URL-encoded environment name, each stamped with its exact name to catch case-collisions on case-insensitive filesystems (DEV.ENVIRONMENT_NAME_MISMATCH). Alchemy already isolates state via --stage <environment>. prisma dev now runs the same extension version check as deploy, refusing incompatible local targets with DEPS.EXTENSION_INCOMPATIBLE.

The local-target seam. The current app concept is gone: currentApp now takes an explicit app and environment, reads only that environment's record, and returns undefined for an app that never ran there (DEV.NOT_STARTED_HERE). devAttach and teardown are environment-scoped the same way, and nothing is stopped when another app or environment starts.

Upgrade migration. movePreEnvironmentDevState moves a legacy folder's record, env values, secrets and bucket objects into the dev environment's folder (port/data preserving), deleting only regenerated artifacts. It is called from every entry point — prisma dev preflight, dev url/dev stop (currentApp), the dev-session attach, and teardown — is idempotent via a target-record check, and deliberately relaxes the earlier "never migrate local state" rule, matching the full-address record precedent.

Docs and skills. The design decision records, local-dev.md, the deploying and running-locally guides, the glossary, and the core-concepts skill describe the new model, the migration trigger commands, and the two safeguards.

Tests. Coverage spans the narrow layers: migration of a pre-C3 fixture folder, per-environment isolation (the detach test now runs two environments side by side), name-addressed url/stop, the environment label in emulator list, and the version check.

Known limitations acknowledged in the description: the shared .prisma-composer/artifacts/<address>/ working folder can race when two environments start simultaneously, and the 0.35.0-dev prereleases neither isolate environments nor promise compatibility.

@coderabbitai

coderabbitai Bot commented Oct 28, 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: 50b77eac-8faf-467d-8d6d-f8e94d436640
  • 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 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 8a1f601

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: 🟡 2 minor · trace

Findings outside the diff

  • 🟡 Minor · correctness packages/0-framework/2-authoring/node/src/control/build.ts — Build adapters' working folder .prisma-composer/artifacts/<address>/ is shared by every environment, racing concurrent prisma dev runs
    The PR's headline claim is that two environments of one app run at once in one folder (acceptance criterion 1), but the build adapters' working folder is still shared by every environment: nextjs() and node() build into <cwd>/.prisma-composer/artifacts/<address>/ (packages/0-framework/2-authoring/nextjs/src/control/build.ts:286, packages/0-framework/2-authoring/node/src/control/build.ts:417 — untouched by this PR). Two prisma dev --environment processes starting at the same moment assemble into the same per-address folder concurrently. The Deployment provider's own artifact unpack was made per-environment and race-safe by hash in this PR, so this is the one remaining shared root. The PR description lists it under "Known, not fixed here"; recording it so it is tracked against the files that own the path.
    Recommended fix: Scope the adapters' workDir by environment too (e.g. <cwd>/.prisma-composer/artifacts/<environment>/<address>/, or under the environment's dev folder like the Deployment provider's artifacts), or make the assembler take the environment into the working-directory layout it documents at core/src/control/deploy.ts:251.

devAttach runs the move, so log on a folder written before environments
had folders finds the running app instead of reporting nothing.

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

@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 12:33
@wmadden
wmadden merged commit 1d4017c into main Oct 28, 2026
25 checks passed
@wmadden
wmadden deleted the claude/local-environments branch October 28, 2026 12:41
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