Skip to content

Multiple Prisma connections and schemas #24247

Answered by ludralph
rdrigos asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @rdrigos 👋

To work with multiple databases, you can create separate schema files for each database. In each schema file, you define the datasource with the respective database connection string. Here's an example of how you can set up your schema files:
For Database 1, create a schema file prisma/db-1/schema.prisma:

datasource db {
  provider = "sqlserver"
  url      = env("DATABASE_URL_DB_1")
}

generator client {
  provider        = "prisma-client-js"
  output          = "../../node_modules/@prisma-db-1/client"
}

For Database 2, create a schema file prisma/db-2/schema.prisma:

datasource db {
  provider = "sqlserver"
  url      = env("DATABASE_URL_DB_2")
}

generator client {
  provider

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rdrigos
Comment options

@ludralph
Comment options

@rdrigos
Comment options

Answer selected by rdrigos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
discussion/needs-confirmation Needs a user to confirm the solution before the Discussion can be marked as answered
2 participants