7

Does prisma support the ability to fetch data from multiple schemas from within a single database?

Muhammad Rehan Qadri
  • 6,824
  • 1
  • 17
  • 18

2 Answers2

6

That is not yet possible. Here's a GitHub issue that had been created you can use to monitor the feature's status and give your feedback too.

Could you also share your use case too? Your feedback will be highly appreciated as we relay it back to the team.

Alex Ruheni
  • 989
  • 5
  • 6
0

Prisma multiSchema is now supported as a preview feature.

See here https://www.prisma.io/docs/guides/database/multi-schema

It was introduced in version 4.3.0 https://github.com/prisma/prisma/issues/1122#issuecomment-1231773471

As the docs say you would add the preview feature...

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["multiSchema"]
}

Then in your datasource you note the schemas...

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  schemas  = ["schema1", "schema2"]
}

And finally in each model you add the @@schema attribute...

model User {
  id      Int      @id
  orders  Order[]
  profile Profile?

  @@schema("schema1")
}

model Order {
  id      Int  @id
  user    User @relation(fields: [id], references: [id])
  user_id Int

  @@schema("schema2")
}
shmuels
  • 1,039
  • 1
  • 9
  • 22