#Best Pratices on prisma.schema location

4 messages · Page 1 of 1 (latest)

polar tartanBOT
#

Skipping coffee for instant knowledge! Let's brew that AI answer now.

polar tartanBOT
# polar tartan Skipping coffee for instant knowledge! Let's brew that AI answer now.

Placing your Prisma schema in a custom location like infra/database/prisma is fully supported and should not cause problems if you configure your project correctly. Prisma CLI allows you to specify the schema location in several ways:

  • Use the --schema flag in CLI commands (e.g., prisma migrate dev --schema=./infra/database/prisma/schema.prisma).
  • Set the schema path in your package.json under the prisma property:
    {
      "prisma": {
        "schema": "./infra/database/prisma/schema.prisma"
      }
    }
    
  • Use a prisma.config.ts file to define the schema location (for advanced setups) Schema location.

This approach is common in Domain-Driven Design (DDD) and monorepo setups, where organizing by domain or infrastructure is preferred. The Prisma CLI will use the schema from your specified location, and there are no known issues with this pattern as long as you consistently reference the correct path in your scripts and configuration.

One thing to note: if you use a multi-file schema (splitting models into separate files), you must always specify the directory containing the main schema file (with datasource and generator blocks), and the migrations directory must be at the same level as that main schema file Multi-file Prisma schema.

In summary, your setup aligns with best practices for custom project structures. Just ensure your configuration points to the correct schema location, and you should not encounter future issues related to this choice.

desert sedge
#

Okay, but in my case i don't have a monorepo, so i will have a prisma.client different in each microservice repository but the database will be the same to them
How handle with this?

leaden mesa
#

The original message is deleted, what was your question?