Skip to content

Allow environment expressions inside the Prisma Schema #3724

Open

Description

@matthewmueller

Problem

Today we support variable expressions within the .env file:

USERNAME="postgres"
DATABASE_URL="postgres://${USERNAME}@localhost:5432/repro"

But we don't currently support environment expression inside the Prisma Schema. This prevents us from separating configuration from the environment.

This lack of separation means you need to either hardcode values in the Prisma Schema or move more configuration into the environment.

Presently, environment expressions would mostly be a quality of life improvement and taking better advantage of our Prisma Schema as a configuration language.

In the future, I sense this will become more important as we need more configuration (e.g. prisma migrate configuration, prisma introspect configuration.)

Configuration vs. Environment

  • Configuration are settings in your application that don't change. You want this in source control.
  • Environment are settings or secrets that change across the environment. You don't want your secrets in source control.

You can find this separation in practice in popular frameworks:

Suggested solution

Extend our Prisma Schema syntax to support template expressions.

datasource pg {
  provider = "postgres"
  url = "${env("DATABASE_URL")}?sslidentity=/tmp/client-identity&sslcert=${env("SERVER_CA")}"
}

Alternatives

Extend our schema in some other way.

Related

Activity

  1. BjoernRave commented on Oct 10, 2020

    @BjoernRave

    this should get some attention, as this is something needed to run prisma in production in a serverless context

  2. janpio commented on Oct 12, 2020

    @janpio
    Contributor

    as this is something needed to run prisma in production in a serverless context

    Can you please elaborate and explain that use case? What exactly would you be doing?

  3. BjoernRave commented on Oct 12, 2020

    @BjoernRave

    @janpio this issue was created in response to: #1673 (comment)

    It would be useful to be able to connect to a DB via SSL in a serverless context.

    Currently you need to jump through a lot of hoops to get SSL working on vercel.

    This, together with the ability to pass sslcert etc. as a env var and not as a file, would make this much easier

  4. tsiege commented on Aug 24, 2021

    @tsiege

    Any news on this? Would be very helpful for configuring db urls

  5. janpio commented on Aug 25, 2021

    @janpio
    Contributor

    You can currently achieve this by composing the final string via an .env file: https://www.prisma.io/docs/guides/development-environment/environment-variables#expanding-variables
    (The env vars you can use in the file do not also have to be defined in the file, can be from the actual env)

  6. villesau commented on Mar 27, 2022

    @villesau

    @janpio This is pretty poorly compatible with Vercel. Vercel, for what ever reason, does not support secret files. And secrets are passed via env variables so .env file is not used.

  7. janpio commented on Mar 28, 2022

    @janpio
    Contributor

    I think the example from @matthewmueller above is just poorly chosen, this issue is not about being able to provide a certificate as a a string at all. Please open a new feature requests for this (or look for an existing one). Thanks.

  8. jbwc commented on Apr 28, 2023

    @jbwc

    any updates on this?

  9. ashcolor commented on May 30, 2023

    @ashcolor

    I am also eagerly awaiting the solution to this issue."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions