question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set default values for schema url fields

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
matthewmuellercommented, 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.

3reactions
HosseinAghacommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting default values in the schema of a component in a Job
You can set default values in the schema of certain components to replace null values retrieved from the data source. Note: At present,...
Read more >
How to add default URL in Sections Schema
I have been trying to create a schema for a dynamic section, and use some predefined default URL for some pages but liquid...
Read more >
use function to set default value of a field inside schema
when i try to use function to set default value in realm schema mCustomerId: {type: 'string', default: CreateGuid()}.
Read more >
Set default values for fields or controls
You can set a default value for table fields set to the Text, Memo, Number, Date/Time, Currency, Yes/No, and Hyperlink data types. If...
Read more >
Default Field Values
Prepopulate field values with defaults to save your users time and improve consistency. Default field values make your users more productive by reducing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found