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.

Why are the db config and generators mixed with the schema definition?

See original GitHub issue

I’m curious if there’s a reason behind this:

generator photon {
  provider = "photonjs"
}

generator nexus_prisma {
  provider = "nexus-prisma"
}

datasource db {
  provider = "sqlite"
  url      = "file:dev.db"
}

being inside the schema.prisma file. I think it makes more sense if it’s in a separate file.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
tianhuilcommented, Oct 23, 2019

@matthewmueller: I think separating out and being able to import .prisma files solves this problem but I thought I would document the use case below:

I would like to be able to separate out datasource from the schema. We often want to have the same app running on several databases (production, staging, testing, QA, dev) and being able to swap databases, while keeping the same schema would be valuable. Currently, I can do this by making each field an env variable and having separate .env fields but that’s pretty tedious. Hope you implement importing of .prisma files soon!

See also https://github.com/prisma/prisma2/issues/375 and https://github.com/prisma/prisma2/issues/150.

3reactions
matthewmuellercommented, Sep 26, 2019

@kitze Hey! I was the one that pushed for Prisma having a single syntax that supports both configuration and schema definitions in a single file. Prisma’s syntax is inspired by HCL (Terraform’s language). We like how HCL is able to nicely model relationships in text.

Additionally, we came to the conclusion that both the database configuration and the schema definition are just application configuration. The schema definition is actually just “configuration for your database”.

That being said, we anticipate that many people will prefer to separate this configuration from the schema. In the past, we used YAML for configuration and GraphQL’s SDL syntax for the schema definition. This made the separation mandatory. We wanted to make this separation optional.

It’s not implemented yet, but soon you’ll be able to import .prisma files. Here’s a spec for how that will look: https://github.com/prisma/specs/tree/master/schema#importing-schemas

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add commands for adding generator or datasource to prisma ...
Add commands for adding generator or datasource to prisma schema #375 ... Why are the db config and generators mixed with the schema...
Read more >
Database Schema Structure - DbSchema
Databases store data based on the schema definition, so understanding it is a key part of designing databases. In this chapter, we will...
Read more >
mix phx.gen.schema — Phoenix v1.6.15 - HexDocs
Settings View Source mix phx.gen.schema (Phoenix v1.6.15) ... Generates an Ecto schema and migration. ... The first argument is the schema module followed...
Read more >
Documentation for the mysql-schema Generator
Generates a MySQL schema based on the model or schema defined in the OpenAPI specification (v2, v3). #CONFIG OPTIONS. These options may be ......
Read more >
Schema Code Generation - Scala's SLICK
The Slick code generator is a convenient tool for working with an existing or evolving database schema. It can be run stand-alone or...
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