Skip to content

multiSchema support for MySQL #16943

Closed as not planned
Closed as not planned

Description

@Jolg42

multiSchema is done for PostgreSQL, CockroachDB and SQLServer but we miss support for MySQL.

Activity

  1. added
    kind/feature
    tech/engines
    tech/engines/introspection engine
    topic: prisma db pull
    topic: multiSchema
    on Dec 21, 2022
  2. floelhoeffel commented on Jan 17, 2023

    @floelhoeffel

    I'll convert this to the main issue tracking support for MySQL for multiSchema

  3. changed the title [-]Multi-schema support for `db pull` for MySQL[/-] [+]Multi-schema support for MySQL[/+] on Jan 17, 2023
  4. changed the title [-]Multi-schema support for MySQL[/-] [+]`multiSchema` support for MySQL[/+] on Jan 17, 2023
  5. ludufre commented on Jul 11, 2023

    @ludufre

    Version 5 was released and this feature here is still open. Please don't forget this, Prisma is very good and I would really like to implement it in our main project.

  6. bentleysayer23 commented on Oct 16, 2023

    @bentleysayer23

    Any updates on this? We are wanting to switch asap but have been blocked by this for a long time

  7. William-McGonagle commented on Aug 19, 2024

    @William-McGonagle

    @Jolg42

    Any update on this issue? I know it's still open but we have a MySQL database and we're looking to functionally shard it soon so it can better scale with us.

  8. Ustice commented on Dec 6, 2024

    @Ustice

    I'm looking forward to seeing what can be done in this space given the restructuring of how Prisma is handling preview features, given that MySQL is listed as a first-class database in terms of support.

  9. thelinuxlich commented on Feb 6, 2025

    @thelinuxlich

    Hoping to see this come to life in 2025 :)

  10. scavlev commented on Mar 13, 2025

    @scavlev

    While undocumented - it used to work before version 5.15.0 even with mysql. We are still using 5.14.0 version with multiSchema + mysql and are pretty much stuck with it as it looks like this commit prisma/prisma-engines@ae0473d has broken it.

  11. thelinuxlich commented on May 2, 2025

    @thelinuxlich

    Is it supported now that multi schemas are out of preview?

  12. NanNanCHN commented on May 29, 2025

    @NanNanCHN

    While undocumented - it used to work before version 5.15.0 even with mysql. We are still using 5.14.0 version with multiSchema + mysql and are pretty much stuck with it as it looks like this commit prisma/prisma-engines@ae0473d has broken it.

    what about this https://www.prisma.io/blog/organize-your-prisma-schema-with-multi-file-support, did you try it?

  13. thelinuxlich commented on May 29, 2025

    @thelinuxlich

    Not the same thing

  14. NanNanCHN commented on May 30, 2025

    @NanNanCHN

    Not the same thing

    i understand

  15. FGoessler commented on Jul 9, 2025

    @FGoessler
    Contributor

    Important Update On This Feature Request

    As we are working towards bringing the multiSchema feature from preview to general availability, we also had another deeper look into supporting multiple schemas for MySQL.

    What we want to achieve with this feature is that users can spread out their models across schemas in their database via a simple @@schema("<schema-name>") attribute on the model in the Prisma schema file and query models across schemas through a single PrismaClient instance (docu).

    Note

    Please do not confuse this with having multiple Prisma schema files!
    You can read more about using multiple Prisma schema files here.

    Unfortunately, MySQL does not natively support this layer of abstraction as it treats databases and schemas as synonyms - contrary to the SQL standard and e.g. Postgres and SQL Server.

    Important

    Hence we have concluded that it is not technically feasible with justifiable efforts and we will not pursue this feature for MySQL for the foreseeable future.

    We understand this may be disappointing to some users. However, demand for this feature has been comparatively low. If you have strong demand for this feature please open a new issue describing your specific use-case and motivation.

    Alternatives To Use

    If you have the need to connect to multiple databases on your MySQL server you can create separate PrismaClient specifications with separate schema files and output directories. These clients can be then used alongside each other to query the databases independently.


    Why This Is Not Technically Feasible For Us:

    Context:

    • The SQL standard specifies a “three tiered hierarchy” of: database → schema → table
    • MySQL, unlike PostgreSQL, does not follow this hierarchy. In MySQL DATABASE and SCHEMA are effectively synonyms. In fact CREATE DATABASE foo and CREATE SCHEMA foo result in the same operation.
    • Prisma’s migration engine internally uses a so called “shadow database” to perform introspections and schema diffing (read more about it here). The shadow database needs an isolated namespace to create ephemeral tables that can be created and destroyed adhoc by commands such as prisma migrate dev.
    • Currently that level of isolation of the shadow database is ensured by creating a fresh database via a CREATE DATABASE <generated-tmp-shaddow-db-name> statement.

    Problem:

    • Because CREATE SCHEMA and CREATE DATABASE are equivalent in MySQL, attempting to isolate schemas within a shadow database does not work.
    • Any CREATE SCHEMA call during a shadow DB operation escapes the intended isolation boundary and creates a new top-level database on the server.
    • This can interfere with the user’s actual databases and potentially cause destructive side effects.
    • ⇒ In short, we cannot guarantee the isolation required for safe shadow database operations when using multiple schemas in MySQL.

    Why We Can’t Work Around It

    While theoretical workarounds exist, they all come with serious limitations:

    1. Dynamic SQL rewriting

      Attempt to detect and rewrite schema-scoped SQL to use globally unique schema names during shadow database operations.

      • Highly fragile: migrations may contain arbitrary SQL that’s hard to rewrite safely.
      • Increases the risk of subtle or destructive errors.
      • Weakens isolation guarantees.
    2. Require a dedicated MySQL instance

      Ask users to provide a fully isolated MySQL server exclusively for the shadow database.

      • Poor user experience.
      • High potential for misconfiguration and footguns (e.g., using the same instance unintentionally).

    This limitation also impacts our internal testing setup. Without schema-level isolation, we cannot safely run parallel tests on shared MySQL instances, making test setup more complex and brittle.

    Additional Considerations:

    We also encountered issues when testing with Vitess and PlanetScale-based MySQL setups. These systems use schemas internally for sharding and branching, and may rename schemas in metadata tables needed for introspection. This adds another layer of fragility and complexity, making robust support even more challenging.

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/featuretech/enginestech/engines/introspection enginetopic: introspectiontopic: migratetopic: multiSchematopic: mysqltopic: prisma db pulltopic: re-introspection

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions