environment variable expansion does not support defaults
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 47.6k
- Forks
- 2.5k
- Avg merge
- 21h 59m
- Merged PRs (30d)
- 95
Description
Bug description
The documentation for Accessing Environment Variables from the Schema explicitly references dotenv-expand for how to do environment variable expansion.
dotenv-expand supports the syntax ${MACHINE:-default}.
variable expansion in prisma does not support this syntax
How to reproduce
- Make a .env file
# In your .env file
DATABASE_URL=postgresql://${USER}@localhost:5432/myapp_${DATABASE_ENV:-development}
- Create an initial schema that references the DATABASE_URL in the source
- run the migration to create the database
- The database name will be
myapp_$%7BDATABASE_ENV:-development%7D
Expected behavior
A new database is created on first migration run with the name of myapp_development
Prisma information
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
@@map("users")
// fields
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String?
}
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: v16.15.1
Prisma Version
Environment variables loaded from .env
Environment variables loaded from db/.env
prisma : 3.15.2
@prisma/client : 3.15.2
Current platform : darwin-arm64
Query Engine (Node-API) : libquery-engine 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine : migration-engine-cli 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine : introspection-core 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary : prisma-fmt 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash : 461d6a05159055555eb7dfb337c9fb271cbd4d7e
Studio : 0.462.0
Preview Features : interactiveTransactions
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the .env example and the datasource url env("DATABASE_URL") entry in the schema, then compare its expansion with dotenv-expand's referenced tests/.env syntax. Done means ${DATABASE_ENV:-development} resolves to development when the variable is unset, producing the expected database name during migration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, postgresql, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100