prisma / prisma/orm

environment variable expansion does not support defaults

Open
#14,865 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug/1-unconfirmed kind/bug topic: .env
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}.

See https://github.com/motdotla/dotenv-expand/blob/ed5fea5bf517a09fd743ce2c63150e88c8a5f6d1/tests/.env#L8-L14

variable expansion in prisma does not support this syntax

How to reproduce
  1. Make a .env file
# In your .env file
DATABASE_URL=postgresql://${USER}@localhost:5432/myapp_${DATABASE_ENV:-development}
  1. Create an initial schema that references the DATABASE_URL in the source
  2. run the migration to create the database
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.