Skip to content

Add .env file imports to project env writes#68

Merged
luanvdw merged 2 commits into
mainfrom
feat/env-file-import
Jun 4, 2026
Merged

Add .env file imports to project env writes#68
luanvdw merged 2 commits into
mainfrom
feat/env-file-import

Conversation

@luanvdw
Copy link
Copy Markdown
Member

@luanvdw luanvdw commented Jun 4, 2026

Overview

Adds dotenv file imports to project env add and project env update so agents and humans can bulk-create or bulk-replace environment variables while keeping write scopes explicit.

Changes

  • Extends project env add and project env update to accept either a single assignment or --file <path>, with mutual-exclusion validation in packages/cli/src/commands/env.ts and packages/cli/src/controllers/app-env.ts.
  • Adds dotenv parsing in packages/cli/src/lib/app/env-file.ts, using dotenv.parse while separately validating duplicate keys, key shape, empty values, export prefixes, quoted values, and multiline values without logging secrets.
  • Adds dedicated bulk write orchestration in packages/cli/src/controllers/app-env-file.ts, including exact-scope preflight for add conflicts and update misses, sequential API writes, value-safe metadata output, and partial-failure recovery metadata.
  • Shares exact-scope env lookup and metadata shaping through packages/cli/src/controllers/app-env-api.ts to keep the main env controller below the local review size gate.
  • Updates command spec, help metadata, README snippets, and tests for parser behavior, command wiring, preflight failures, branch overrides, JSON output, and partial apply failure.

Why

Using --file preserves the existing add/update semantics instead of introducing a new import verb or upsert behavior. The implementation keeps scope explicit, avoids echoing values, validates before mutation, and reports partial state when true atomic bulk writes are unavailable from the Management API.

Validation

  • pnpm --filter @prisma/cli test
  • pnpm --filter @prisma/cli build
  • git diff --check
  • Local tmp-code-review and thermonuclear-review; resolved the strict file-size/controller-structure finding before opening this PR.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Warning

Review limit reached

@luanvdw, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 33 minutes. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 83a58c0a-7b79-4615-a415-30b32844173b

📥 Commits

Reviewing files that changed from the base of the PR and between da1dd89 and 9bdf5bb.

📒 Files selected for processing (4)
  • packages/cli/src/controllers/app-env-file.ts
  • packages/cli/src/lib/app/env-file.ts
  • packages/cli/tests/app-env-vars.test.ts
  • packages/cli/tests/app-env.test.ts

Walkthrough

This PR adds dotenv file support to the Prisma CLI's project env add and project env update commands. Users can now provide multiple environment variables via --file .env --role preview instead of single KEY=VALUE assignments. The implementation includes new type contracts for file-based results, dotenv file parsing with validation, an extracted API abstraction layer, batch operation controllers with transaction-like failure handling, refactored main controllers, updated command definitions, multi-variable output rendering, comprehensive test coverage, and updated documentation. All changes maintain backward compatibility with single-assignment workflows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding .env file import capability to project environment variable write commands.
Description check ✅ Passed The description comprehensively details the changes, implementation approach, design decisions, and validation steps related to the .env file import feature.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/env-file-import
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/env-file-import

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@luanvdw luanvdw self-assigned this Jun 4, 2026
@luanvdw luanvdw marked this pull request as ready for review June 4, 2026 09:35
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/controllers/app-env-file.ts`:
- Around line 44-56: The thrown CliError for existingKeys should tell the user
to split the input by conflict type or use split-file placeholders rather than
running the full-file command; update the error's fix and nextSteps (in the
block that constructs the CliError when existingKeys is non-empty) to reference
existingKeys and formatKeyList(existingKeys)/formatScopeLabel(resolved.scope)
and instruct creating two files (one for new keys and one for updates) or
providing a "<file>.existing" and "<file>.new" placeholder before running
`prisma-cli project env update --file`, and make the analogous change in the
other similar error block (the one around lines 129-141) so both preflight
errors give explicit split-by-conflict guidance using the reported keys.

In `@packages/cli/src/lib/app/env-file.ts`:
- Around line 140-147: The catch block around validateKey currently swallows the
original validation error; change the catch clause to capture the error (e.g.,
catch (err)) and include the original validation message when throwing
usageError so the real reason from validateKey is preserved (reference
validateKey, usageError, key, filePath, line, command); ensure the thrown
usageError combines your existing contextual text with err.message (or passes
err as a cause) so over-length and other specific validation failures are
reported accurately.

In `@packages/cli/tests/app-env-vars.test.ts`:
- Around line 139-147: The test currently uses try/catch around
parseEnvFileContents("EMPTY=\n", ".env", "add") without asserting that an error
was thrown, allowing false-positive passes; update the test to explicitly assert
the throw path (e.g., wrap the call in an expect(...).toThrow()/toThrowError or
add a failing assertion immediately after the call and before the catch) so that
parseEnvFileContents is required to throw, then keep the existing assertions
inside the catch to validate error.code, error.summary, and that the serialized
error does not contain "secret".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 49dc5090-d488-48b9-99ab-48f05d28779c

📥 Commits

Reviewing files that changed from the base of the PR and between 3e444d8 and da1dd89.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • README.md
  • docs/product/command-spec.md
  • packages/cli/README.md
  • packages/cli/package.json
  • packages/cli/src/commands/env.ts
  • packages/cli/src/controllers/app-env-api.ts
  • packages/cli/src/controllers/app-env-file.ts
  • packages/cli/src/controllers/app-env.ts
  • packages/cli/src/lib/app/env-file.ts
  • packages/cli/src/presenters/app-env.ts
  • packages/cli/src/shell/command-meta.ts
  • packages/cli/src/types/app-env.ts
  • packages/cli/tests/app-env-vars.test.ts
  • packages/cli/tests/app-env.test.ts

Comment thread packages/cli/src/controllers/app-env-file.ts
Comment thread packages/cli/src/lib/app/env-file.ts
Comment thread packages/cli/tests/app-env-vars.test.ts
@luanvdw luanvdw merged commit f2fba0b into main Jun 4, 2026
5 checks passed
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.

1 participant