Skip to content

Add ability to configure custom schema location instead of requiring --schema arg #3144

Closed

Description

@flybayer

Problem

For people who use a custom schema location, the current DX is super painful. All of the CLI commands fail unless you explicitly pass --schema. When you are using the cli a lot in a project with a custom schema, this gets super annoying having to type --schema all the time.

Additionally, using a custom schema means the prisma postinstall hook fails, requiring projects to add their own postinstall hook to manually generate the client.

And then also of course we use a custom schema location in Blitz and abstract most of the prisma CLI commands. But when a user needs to drop down a level and use the prisma cli directly, they often get stuck because they don't know they need to provide --schema

Suggested solution

I want to be able to define prisma config in the package.json file. Something like this:

{
  "scripts": {},
  "prisma": {
    "schema": "db/schema.prisma"
  },
  "dependencies": {}
}

Alternatives

An alternative is to add a config file at the repo root, like .prisma.config.js or something.

Activity

  1. janpio commented on Jul 27, 2020

    @janpio
    Contributor

    I agree that having a way to change the expected standard schema path is useful, vs. having to supply the --schema for each command execution. Even though if your framework (like Blitz) uses that internally, it makes your experience a lot worse if you ever want to use prisma directly as you probably do not know about this requirement.

    Not sure about the suggested solution though - maybe there are other alternatives.

  2. added
    tech/typescript
    kind/feature
    and removed on Aug 5, 2020
  3. added this to the Backlog 2.5.0 milestone on Aug 5, 2020
  4. timsuchanek commented on Aug 6, 2020

    @timsuchanek
    Contributor

    Thanks @flybayer for raising this! I totally agree that this makes things quite cumbersome to use.

    Before diving into solutions, I would like to understand your situation a bit better.
    What is the reasoning for having the schema in a custom location?
    It looks like you have it in a folder called db instead of prisma.
    An option would also be to add db to the "watch list" where we check for the file.

  5. timsuchanek commented on Aug 6, 2020

    @timsuchanek
    Contributor

    The reason I don't want to immediately jump into discussing custom solutions: The solutions introduce new challenges.
    Let's say we introduce a section in the package.json to configure the schema location.
    What about the Prisma Go Client? Should it also have a custom location configured? Should go users have a package.json? The Go Client is not part of the official offering yet, but we will have multiple languages at some point. The design of this needs to take that into account.

    To get something language agnostic, one could think of a dot file. Like .prismarc. That would however introduce more dotfiles to your project root, which can already be quite full sometimes. What would the purpose of the dot file be? As of now just to point to the schema.prisma.

    So no matter which solution we will choose, there will be trade-offs.

  6. 21 remaining items

  7. janpio commented on Sep 8, 2020

    @janpio
    Contributor

    Some technical details for the implementation after discussion with @timsuchanek and @Jolg42:

    • Right now we 1) use --schema or 2) fall back to ./prisma/schema.prisma (or ./schema.prisma) to find the schema file to load.
    • The idea is to in between 1) and 2) add a new step where we look at the location that is defined in the package.json file as defined in Add ability to configure custom schema location instead of requiring --schema arg #3144 (comment).
      • That means that even if you have a path defined in your package.json, you can manually override that by using --schema in the CLI command.
    • Additionally the output the CLI gives you where it loaded the .env file from (which is next to the schema file) should also mention the schema.prisma file to make that explicit.

    Details about documentation of this feature are still figured out, as the schema loading is currently not documented at all directly.

    Previous, slightly related documentation:

  8. timsuchanek commented on Sep 14, 2020

    @timsuchanek
    Contributor

    This is implemented by @Weakky in the latest dev version.

  9. janpio commented on Sep 14, 2020

    @janpio
    Contributor

    Follow up issue about detail that got missed: #3647

  10. sarink commented on Jan 15, 2022

    @sarink

    This is done? Where are the docs?

  11. janpio commented on Jan 16, 2022

    @janpio
    Contributor
  12. alphaelf commented on Sep 11, 2022

    @alphaelf

    can we use wildcard expression in package.json for schema location? just like:

    "prisma": {
       "schema": ["./plugins/**/*.prisma"]
    }
  13. janpio commented on Sep 12, 2022

    @janpio
    Contributor

    No, you can only specify exactly the location of the schema file you want it to read.

  14. Security2431 commented on Jun 25, 2024

    @Security2431
  15. marcospgp commented on Sep 2, 2025

    @marcospgp

    I like that package.json was used, I wish more libraries would standardize around it instead of polluting the project root with tons of independent config files

    edit: spoke too soon

    warn The configuration property `package.json#prisma` is deprecated and will be removed in Prisma 7. Please migrate to a Prisma config file (e.g., `prisma.config.ts`).
    For more information, see: https://pris.ly/prisma-config
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/featuretech/typescripttopic: clitopic: schema

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions