Skip to content

Support multiple .env files natively #11050

@rojlarge

Description

@rojlarge

Problem

The Prisma documentation suggests using multiple .env files to separate configuration between different environments (for instance, connecting to different databases for local development vs. running integration tests). However, the ability to load different .env files isn't supported directly by Prisma-- the recommendation is to install a separate dependency dotenv-cli and proxy all commands/scripts that involve prisma through that instead.

This is unfortunate, since it means installing another 3rd-party dependency for something that Prisma handles natively when using a single .env file. It also means changing the entry point to all of a project scripts to something like dotenv-cli instead of npx or jest, for example.

Suggested solution

It seems like a new environment variable such as PRISMA_ENV_FILE could be added to allow overriding the default name that gets appended to all the locations Prisma currently looks for .env in getEnvPaths.ts. Or Prisma could directly support the DOTENV_CONFIG_PATH environment variable used to define a custom .env file location in dotenv, and skip trying to search the default locations if that variable is present.

Alternatives

Loading a custom .env file using dotenv-cli:

dotenv -e .env.test jest
dotenv -e .env.test -- npx prisma migrate dev --name postgres-init

Loading a custom .env file using dotenv's DOTENV_CONFIG_PATH env var:

DOTENV_CONFIG_PATH=.env.test node -r dotenv/config ./node_modules/.bin/jest
DOTENV_CONFIG_PATH=.env.test node -r dotenv/config ./node_modules/.bin/prisma migrate dev --name postgres-init

If there is another way to accomplish this that I'm missing, please let me know! I think the inclusion of this kind of support directly would really improve Prisma's testing story in particular, without too much overhead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions