Skip to content

Support querying across multiple schemas #1122

Closed

Description

@pantharshit00

Right now with Prisma, you can query across one schema at a time but in many cases, you need to query across multiple tables stored across multiple database schemas.

We need to make certain product decision to enable this like how we are going to add this schema metadata information to the model and other implementation details that are necessary to be handled for this.

Activity

  1. slavicdev34 commented on Jul 4, 2020

    @slavicdev34

    Hi @pantharshit00 do you have any update about this issue?

  2. pantharshit00 commented on Jul 5, 2020

    @pantharshit00
    ContributorAuthor

    Sorry, there are no updates on this right now.

  3. tylerben commented on Aug 11, 2020

    @tylerben

    @pantharshit00 are there any plans to support this going forward? I might be misunderstanding things but is my understanding correct that Prisma currently only supports connecting to a single PostgreSQL schema?

    In our database, we have tables and views split across multiple schemas that we need to be able to pull data from. We really want to use Prisma, but until there is support for connecting to multiple schemas in the same DB, it will not be possible for us to do so.

  4. alonbilu commented on Oct 21, 2020

    @alonbilu

    +1 for that. This item has been open for too long. I too use multiple schemas in a single project and in order to migrate completely to Prisma, this is a must.

  5. 199 remaining items

  6. meshackm commented on Apr 13, 2024

    @meshackm

    I am just getting into building multi-tenant apps. I plan to isolate tenants with schemas. There is a shared schema where a new tenant's data is stored, a script then runs on insert to create a schema for that tenant. A subdomain would be issued to the tenant and it would be the same as their schema name. Having a way to select which schema to query from would be nice.

  7. mkuchak commented on Aug 2, 2024

    @mkuchak

    I am just getting into building multi-tenant apps. I plan is to isolate tenants with schemas. There is a shared schema where a new tenant's data is stored, a script then runs on insert to create a schema for that tenant. A subdomain would be issued to the tenant and it would be the same as their schema name. Having a way to select which schema to query from would be nice.

    I'm facing the same situation. Were you able to solve it in any way using Prisma?

  8. meshackm commented on Aug 3, 2024

    @meshackm

    I am just getting into building multi-tenant apps. I plan is to isolate tenants with schemas. There is a shared schema where a new tenant's data is stored, a script then runs on insert to create a schema for that tenant. A subdomain would be issued to the tenant and it would be the same as their schema name. Having a way to select which schema to query from would be nice.

    I'm facing the same situation. Were you able to solve it in any way using Prisma?

    It just didn't work with Prisma, I ended up using Postgres.js and converting a bunch of Prisma queries to SQL. If you're using Postgres then Postgres.js will be your best bet.

  9. JoelWekesa commented on Sep 14, 2024

    @JoelWekesa

    When is this moving from preview? It's been in preview for quite some time

  10. jordanskole commented on Sep 23, 2024

    @jordanskole

    Will this work across databases as well?

    For example...

    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["multiSchema"]
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("APP_DATABASE_URL")
      schemas  = ["base"]
    }
    
    datasource db {
      provider = "mongodb"
      url      = env("TRANSACTIONAL_DATABASE_URL")
      schemas = ["transactional"]
    }
    
    
    model User {
      id     Int     @id
      orders Order[]
    
      @@schema("base")
    }
    
    model Order {
      id      Int  @id
      user    User @relation(fields: [id], references: [id])
      user_id Int
    
      @@schema("transactional")
    }
    
    enum Size {
      Small
      Medium
      Large
    
      @@schema("transactional")
    }
    
  11. removed their assignment
    on Nov 1, 2024
  12. ineshbose commented on Dec 20, 2024

    @ineshbose

    Could it be possible to provide a possible port for this in sqlite, using ATTACH DATABASE?

  13. kokokenada commented on Mar 31, 2025

    @kokokenada

    My use case for multiple schemas is a schema per git branch. When I a dev pushes into an feature branch, it builds and deploys at .mydomain.com . To segregate the database I use schema= in the postgres url. Works great in every hosted postgres I've tried. It works great with cockroach db. However, Prisma's hosted postgres completely ignores both the schema= connect string and the / and always uses the "postgres" database and "public" schema.

    I attempted to work around the problem with:

    schemas = [env("ACTIVE_SCHEMA")]

    No dice (error: Expected a string value, but received functional value env("ACTIVE_SCHEMA").
    --> prisma/schema.prisma:11)

  14. kokokenada commented on Apr 11, 2025

    @kokokenada

    Another use case I came across is the use of a schema for different organizations as part of an enterprise multi-tenancy strategy. This of course works perfectly fine with &schema=orgIfOfSomeSort but fails miserably with Prisma's hosted postgres.

  15. lookto commented on Apr 17, 2025

    @lookto

    Further development on this feature would be greatly appreciated. We are developing a quite huge monolith and want to seperate different scopes in different schemas, but it would be a pain without the capability to migrate.

    This not only makes the db more structured, but we could also give other services read-only access to some of the schemas without the need to specify every single table the role should have access to.

  16. FGoessler commented on Jun 18, 2025

    @FGoessler
    Contributor

    @kokokenada thank you for your feedback! We are considering this for our work to move the multiSchema preview feature to GA.

    Regarding Prisma Postgres: I am talking with our team working on this area whether we can make this work for native Prisma connections. In the meantime you can try to use direct TCP connections to Prisma Postgres. Based on my testing they support the schema=... query param as expected.

  17. FGoessler commented on Jun 19, 2025

    @FGoessler
    Contributor

    Could it be possible to provide a possible port for this in sqlite, using ATTACH DATABASE?

    Hi @ineshbose 👋
    Could you please elaborate what your use case is to use multiple schemas with SQLite? 🤔

  18. ineshbose commented on Jun 24, 2025

    @ineshbose

    Could you please elaborate what your use case is to use multiple schemas with SQLite? 🤔

    Yes, of course. I'm mostly looking at keeping separate schemas for different tables in my database, similar to a public schema in postgres and then, say, auth schema with user-account tables. I do have a setup in my project where we use postgres in prod and sqlite in dev with the help of prismaSchemaFolder as outlined in this discussion, but the only issue now is that I'm unable to make use of @@schema in local dev environment for sqlite. Again, multi-schema workaround aside, I'm looking to keep schemas separate in my database between public and auth for now.

  19. FGoessler commented on Jul 29, 2025

    @FGoessler
    Contributor

    With today's release of Prisma 6.13.0 we are moving multi schema support to general availability for Postgres and SQL Server. 🎉

    We are hence closing this issue as completed.

    Please note that multiple databases schemas for SQLite and MySQL are not supported and not on our current roadmap. Both databases work fundamentally different regarding schemas and demand for multi schema on them has been very low.

    If you encounter issues with the multi schema feature please open fresh issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featurestatus/is-preview-featuretopic: database-provider/supabasetopic: introspectiontopic: multiSchematopic: postgresqltopic: schematopic: sql server

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions