Skip to content

feat(cli): add project variable and project variable group commands - #395

Draft
clankergoose wants to merge 9 commits into
mainfrom
feat/variable-groups-cli
Draft

clankergoose wants to merge 9 commits into
mainfrom
feat/variable-groups-cli

Conversation

@clankergoose

@clankergoose clankergoose commented Nov 20, 2026 •

Copy link
Copy Markdown

Demo only. Not for merge. CLI side of the variable groups demo. Platform PRs: prisma/pdp-control-plane#6109 (API) and #6110 (Console). Spec: prisma/pdp-control-plane#5916. Review comments will not get replies.

Summary

Adds prisma project variable (add / update / delete / list) and prisma project variable group (list / create / update / delete). There is no top-level prisma variable command.

All of prisma project env is deprecated and will be removed in a later release. Its behaviour and its stdout are unchanged, so scripts keep working. Every env subcommand says "Deprecated" in its help, and every run prints one warning on stderr that names the matching prisma project variable command. This replaces the earlier warning that only branch override writes printed.

prisma project variable does not depend on any env code, so env can be removed by deleting its files only. A test follows the imports and fails if a variable file reaches an env module.

Key design decisions

  • --group <name> or --role production|preview selects the target group, on writes and on list. The two flags cannot be used together (VARIABLE.CONFLICTING_FLAGS).
  • The new commands never create overrides. --branch on a write fails with VARIABLE.NO_BRANCH_WRITE. The error says that overrides and prisma project env are deprecated, and recommends moving the value into a custom group (prisma project variable group create and prisma project variable add, or "Move to a custom group" in Console). Its last next action is still the deprecated prisma project env … --branch command, for changing an override that already exists.
  • Strict --role preview check. If the project has any custom group, --role preview fails with VARIABLE.CUSTOM_GROUP_CONFLICT. Use --group preview instead.
  • Writes check the group first. add fails with VARIABLE.ALREADY_EXISTS if a key exists; update fails with VARIABLE.NOT_FOUND if a key is missing. With --file, every key in the file is checked, all problem keys are listed, and nothing is written.
  • A failed --file write stops at that key and fails with VARIABLE.FILE_APPLY_FAILED, naming the keys already written.
  • Built-in groups follow the new API contract. The API does not store production and preview. The group list returns them with id equal to their name, builtIn: true, and no rule. group update and group delete refuse built-in groups. The builtIn handling is unchanged in this round; the API contract is being finalised separately.
  • project variable list --branch <name> shows the group the branch receives and each key's source. Overrides are labelled "Deprecated override", with a warning under the table. An unknown branch fails with VARIABLE.BRANCH_NOT_FOUND.
  • The env deprecation warning in --json mode is a separate message frame in the output stream, as for every engine warning. The result frame is unchanged. The engine has no deprecation support for live commands (only redirects for removed ones), so the warning is one function in env-shared.ts.
  • New API endpoints are not in @prisma/management-api-sdk v1.80.0. lib/variable/api.ts holds typed wrappers that cast once to the raw client.
  • Service variables cannot be set from this CLI. They are set in Console (Save and Deploy), and the spec adds prisma deploy --variable to Composer. project variable list --branch <name> --service <name> only reads them. Known gap.

Parity with prisma project env (overrides excluded)

prisma project env prisma project variable
add KEY=VALUE --role production|preview add KEY=VALUE --role … or --group <name>
add KEY (value from the shell) add KEY
add --file .env add --file .env
add: fails if the key exists VARIABLE.ALREADY_EXISTS, single key and --file
update KEY=VALUE / KEY / --file same
update: fails if a key is missing VARIABLE.NOT_FOUND, single key and --file
--file partial failure report VARIABLE.FILE_APPLY_FAILED
delete KEY --role … delete KEY --role … or --group <name>
list (overview of every scope) list (every group)
list --role … list --role … or --group <name>
list --branch <name> (what a branch gets) list --branch <name>, plus --service
list shows key, id, managed status key, id, "Managed by Prisma" note
--project, --json, stdout data lines same
Values never shown same
--branch override writes not supported, by design

Commands

Command Description
prisma project variable add KEY=VALUE --group <name> Add a variable to a group
prisma project variable update KEY=VALUE --group <name> Replace a variable's value in a group
prisma project variable delete KEY --group <name> Delete a variable from a group
prisma project variable list [--group <name> | --role …] [--branch <name>] List keys by group, or what a branch receives
prisma project variable group list List groups with their rule and branch count
prisma project variable group create <name> --equals|--starts-with <value> Create a custom group
prisma project variable group update <name> [--name] [--equals|--starts-with] Rename a custom group or change its rule
prisma project variable group delete <name> [--confirm <name>] Delete a custom group and its variables

Docs

  • docs/reference/error-reference.md: VARIABLE codes, including the new ALREADY_EXISTS, BRANCH_NOT_FOUND, FILE_APPLY_FAILED, and USAGE_ERROR. A note marks the PROJECT.ENV_* codes as coming from the deprecated commands.
  • scripts/list-error-codes.mjs: VARIABLE added to the namespace list, so check:error-reference now verifies those codes.
  • README.md, packages/cli/README.md, packages/prisma/README.md: examples use project variable.
  • skills/prisma-platform-core-concepts/SKILL.md: the "Environment variables" section is rewritten for the current model. It explains branch variables (in groups) and service variables, how a branch gets its one group, that groups do not inherit, the order a deploy applies groups, overrides and service variables, and why branch variables are recommended (a new branch gets the right configuration with no manual step). It says overrides and project env are deprecated and how to move an override into a custom group. The resource model, preview database, promote, and stale-value entries are updated to match.
  • docs/reference/glossary.md: new terms: variable group, branch variable, service variable, override (deprecated).
  • examples/hello-world/README.md: uses project variable instead of project env.
  • Command help: project variable explains branch and service variables and that groups do not inherit; list --service says it shows service variables; project env help and its --branch flag say overrides are deprecated; --role preview in project env no longer claims to reach every preview branch.

Tests

  • tests/variable.test.ts (46 tests, one now checks the full VARIABLE.NO_BRANCH_WRITE text): flags, group resolution, add/update/delete/list, the checks before writing, --file import and partial failure, key validation, list --role, unknown group and branch, and the group commands.
  • tests/variable-imports.test.ts: no file under commands/project/variable or lib/variable reaches an env module, directly or through other modules. Verified to fail on a multi-line type import.
  • tests/project.test.ts (7 tests): the warning on each env subcommand (add, add --file, update, delete, list, and a failed run), with exact stdout checks, and the --json result unchanged.

Checks

  • pnpm format, pnpm lint: pass.
  • pnpm typecheck: passes (9 of 9 tasks).
  • pnpm --filter @prisma/cli test: 1275 passed, 2 skipped, 0 failed.
  • pnpm check:error-reference: all 155 codes listed.
  • pnpm check:skill-packaging, pnpm check:grammar: pass.

🤖 Generated with Claude Code

Adds `prisma variable` with add/update/delete/list subcommands and
`prisma variable group` with list/create/update/delete subcommands.

Variables write to named groups (--group <name> or --role
production|preview). --branch is rejected on write commands; use a
variable group or send a service variable with the deploy. --role
preview fails when the project has custom groups (Decided 37).

New API endpoints (variable-groups, resolved-variables, groupId filter
on environment-variables) are not in @prisma/management-api-sdk v1.80.0
so they are called through typed wrappers in lib/variable/api.ts that
cast once to the raw client.

Also:
- Renames "Env map" column to "Variable group" in `branch list`.
- Adds a deprecation warning to all `project env` write/list commands.
- Adds the 8 new commands to the e2e-coverage exclusion list (endpoints
  not yet deployed to the standard CI environment) and to the
  mount-coverage snapshot.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npx https://pkg.pr.new/@prisma/cli@395
npx https://pkg.pr.new/@prisma/cli-engine@395

commit: a2fc73c

tylerhogarth and others added 4 commits November 20, 2026 08:08
…lint

`variable update --file` looked each key up by role, so in a custom
group it changed the preview group's row. It now looks keys up by group
id, the same way the single-key path does. Also fixes lint: removes an
unused import and test helper, a nested ternary and non-null assertions,
and gives a reason for each remaining cast and sequential await.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…verrides

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xamples

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… override writes [skip ci]

- Move `prisma variable` and `prisma variable group` to `prisma project
  variable` and `prisma project variable group`. Remove the top-level
  `variable` command.
- Restore `prisma project env` to its main-branch behaviour. Remove the
  warning on every env command. Warn on stderr only when an env write sets a
  branch override (`--branch`, or a `Deprecation` header on the response).
- Built-in groups are not stored: their id is `production` or `preview`,
  `builtIn` is true, and their variables have `groupId: null`. Update the
  typed wrappers and fixtures. `group update` and `group delete` refuse
  built-in groups.
- `project variable list --branch` labels overrides as deprecated and
  `COMPOSER_` keys as "Managed by Prisma".
- Add the `VARIABLE` codes to the error reference, and mention the new
  commands in the package READMEs and the platform skill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clankergoose clankergoose changed the title feat(cli): add variable and variable-group commands feat(cli): add project variable and project variable group commands Nov 25, 2026
tylerhogarth and others added 4 commits November 25, 2026 10:56
…ne [skip ci]

Every `prisma project env` command is now marked deprecated in its help,
and each run prints one warning on stderr that names the matching
`prisma project variable` command. Data on stdout is unchanged. This
replaces the warning that only branch override writes printed.

`prisma project variable` no longer imports any env module, so `env` can
be removed later by deleting its files. Key and dotenv parsing moved to
lib/variable/assignment.ts, and API errors use the variable library's own
error. A test follows the imports and fails if an env module is reached.

The variable commands now match what `env` can do, except overrides:
- add and update check the group before writing, for one key and for
  --file, and write nothing when a key already exists or is missing
- a failed --file write reports the keys already written
- list accepts --role, shows ids, and fails on an unknown group or branch

The error-code scanner now includes the VARIABLE namespace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…deprecated [skip ci]

The VARIABLE.NO_BRANCH_WRITE error now says that overrides and
`prisma project env` are deprecated, and recommends moving the value
into a custom group. It still shows the `prisma project env --branch`
command for changing an existing override.

The platform skill, glossary, error reference, example README and
command help now describe branch variables in groups, service
variables, the order a deploy applies them in, and why branch
variables are the recommended kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing an override [skip ci]

The steps for moving an override into a custom group now say that the
new group does not include the preview group's values. Users must add
every key the branch needs, or use the Console, which can copy them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Switch createEnvVarInGroup, findEnvVarInGroup, and listEnvVarsInGroup
from /v1/environment-variables to the new /v1/variable-groups/{groupId}/variables
routes, with groupId in the path instead of the query or body.

Add updateGroupVariable and deleteGroupVariable wrappers for
PATCH and DELETE /v1/variable-groups/{groupId}/variables/{variableId}.
update.ts and delete.ts now call these wrappers and no longer inline
the SDK calls.

Drop the groupId: null comment from RawGroupVariable; the new routes
always return groupId as a non-null string.

Update all test mocks and assertions to match the new paths and
path-param locations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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