Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default values for schema url fields #222

Open
HosseinAgha opened this issue Jul 23, 2019 · 10 comments
Open

Set default values for schema url fields #222

HosseinAgha opened this issue Jul 23, 2019 · 10 comments
Labels
domain/psl Issue in the "PSL" domain: Prisma Schema Language domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: env topic: schema

Comments

@HosseinAgha
Copy link

HosseinAgha commented Jul 23, 2019

My proposals

  1. Add a syntax in Prisma Schema Language for setting a default value if env variable was empty. e.g.
datasource db {
  provider = "postgresql"
  url = env('POSTGRES_URL') || "postgresql://dev@localhost/testdb"
}
  1. As a better option add support for schema definition in JavaScript/Typescript (e.g. schema.prisma.js)

Why I think creating a new schema language isn't a good idea?

  • Please re read your article on the problems of schema first development.
  • I worry that in time you reach the same conclusion and you end up with a schema language that tries to solve everything but is not as good as a real programming language.
  • I think having a real general purpose programming language at your disposal is always a good idea. (take Webpack config or many other tools for example)
  • I understand that Prisma is a cross language tool (Go driver for example) but it is also written in JS and Generator and Lift need node to run. So I see no harm in having a schema.prisma.js option.

What are the use cases for these?

I’m struggling to add Prisma 2 to my development workflow.
I have a complex NodeJS server that connects to some DBs and outside services. We try our best to keep initial configuration for new developers as simple as possible (setup everything in the first npm run dev).
We use docker to initialize and run the DBs and external services and setup some default credentials for dev databases.
In the dev server we set the same default credentials for our DB connectors so new developers don’t have to worry about DB config at all.
The current url system for Prima Schema Language only accepts environment variables. It is a good thing for production but not the dev env.
Using .env file is not a good option for us as each new developer should create it and add the default configs to it.

@pantharshit00 pantharshit00 added the kind/feature A request for a new feature. label Jul 25, 2019
@HosseinAgha
Copy link
Author

HosseinAgha commented Jul 28, 2019

It is worth mentioning that we are currently using photon's datasources argument to override the database URL like this:

const photon = new Photon({
      datasources: {
          db: {
            url: process.env.POSTGRES_URL || "postgresql://dev@localhost/testdb",
          },
      },
});

But using this approach Lift will still use the value in schema.prisma.

@janpio
Copy link
Member

janpio commented Aug 5, 2019

A note: This might also be solved by adding a second param default (of fallback) to the env() method.

@matthewmueller
Copy link
Contributor

matthewmueller commented Aug 5, 2019

Hi @HosseinAgha!

For 1., we're definitely going to add a default env argument, it'll likely look like this

env("POSTGRES_URL", default: "postgresql://dev@localhost/testdb")

For 2., thanks for bringing this up! We've created a new issue for this discussion.

timsuchanek added a commit that referenced this issue Apr 14, 2020
Former-commit-id: 24c07aa
timsuchanek added a commit that referenced this issue Apr 14, 2020
Former-commit-id: 24c07aa
Former-commit-id: 36d2e64
@matthewmueller matthewmueller added the domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. label Jan 14, 2021
@tomhoule tomhoule added the domain/psl Issue in the "PSL" domain: Prisma Schema Language label Jun 3, 2021
@blevine
Copy link

blevine commented Sep 23, 2021

Was the default for the connection url functionality ever added?

@pantharshit00
Copy link
Contributor

@blevine No, we didn't get any more requests for this so this was never pushed again up the priority classification.

@blevine
Copy link

blevine commented Sep 23, 2021

That's too bad. It seems to have been almost completely implemented and would have been a good enhancement.

@Milananas
Copy link

I guess this is still not implemented? I have a good use case for this feature at the moment as well.

@danablend
Copy link

I would be happy to see an implementation of this as well! :-)

@2pmflow
Copy link

2pmflow commented Dec 28, 2023

Would love to see this implemented. It would help with zero downtime migrations of database credentials.

Supporting something similar to env("NEW_DATABASE_URL") || env("DATABASE_URL") would let the application handle two database credentials at once.

@janpio janpio changed the title Set default values for schema url fields Set default values for schema url fields Feb 16, 2024
@janpio
Copy link
Member

janpio commented Feb 16, 2024

How would that work @2pmflow, specifically? If it falls back to the second value if the first env var is empty, can you not also just update the only single environment variable to the new value instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/psl Issue in the "PSL" domain: Prisma Schema Language domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: env topic: schema
Projects
None yet
Development

No branches or pull requests

9 participants