"Environment variables loaded from .env" is misleading
See original GitHub issueBug description
I followed the “Running migrations on different environments” guide and executed this statement in my terminal:
dotenv -e .env.test -- npx prisma migrate dev
It was giving me the following output:
Environment variables loaded from .env Prisma schema loaded from prisma\schema.prisma Datasource “db”: PostgreSQL database “tests”, schema “public” at “localhost:5433”
I was very surprised because I do have a .env
and .env.test
file in my project and thought that Pisma is not pickung up my .env.test
file because it’s reporting that it loaded variables from “.env”. In fact it used my .env.test
file.
How to reproduce
- Create a
.env
file withDATABASE_URL="postgresql://postgres:postgres@localhost:5432/root_db?schema=public"
- Create a
.env.test
file withDATABASE_URL="postgresql://prisma:prisma@localhost:5433/test_db?schema=public"
- Run
dotenv -e .env.test -- npx prisma migrate dev
Expected behavior
To avoid this confusion I suggest to change the phrasing of the console output. Preferably it should show the correct file name (e.g. loaded from .env.test) or not mention the file name at all (e.g. loaded environment variables).
Prisma information
schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model enum_role {
type String @id
description String
}
Environment & setup
- OS: Windows 10
- Database: PostgreSQL
- Node.js version: 16.10.0
Prisma Version
prisma : 3.4.0
@prisma/client : 3.4.0
Current platform : windows
Query Engine (Node-API) : libquery-engine 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at ..\..\node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at ..\..\node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at ..\..\node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at ..\..\node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85
Studio : 0.438.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Hi @janpio, your explanation makes sense to me. I think the best that can be done here is placing a note in the docs. And how about rephrasing “Environment variables loaded from .env” to just “Environment variables loaded”?
It’s super misleading, I lost two hours trying to figure out why my env variables from
.env
file were loaded during my tests whereas I followed the instructions to load a.env.test
file.Actually dotenv and prisma aren’t smart at all: if you have the same variable in the two files and used
dotenv -e .env.test
ok when prisma is initiated it won’t override the variable. HOWEVER, it will load variables from the.env
file which aren’t in the.env.test
file. This is super wrong, this is not explained in the docs, and this is a very bad pattern..env
file shouldn’t be automatically magically loaded by prisma.