Parallel Table Names using MuliSchema feature

I'm in the process of deploying some parallel models to new schemas so that we have a sandbox schema to work with until we're ready to do some data migration. I've learned that using the multischema feature doesn't include the schema name as part of the contraint names, so I've had to go through and use the map() function to rename all of my contraints so that they're namespaced to my new schema (e.g. {tablename}_{column_names}_fkey --> {schemaName}_{tablename}_{column_names}_fkey this has allowed me to deploy the parallel tables in a new schema, however when i reun npx prisma migrate dev i still have some outstanding changes that it's trying to apply and I can't figure out what i'm doing wrong or how to rememdy the issue. Curious if anybody has encountered issues with somethign like this
Drift detected: Your database schema is not in sync with your migration history.

The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.

It should be understood as the set of changes to get from the expected schema to the actual schema.

[*] Changed the `AccountProvider` table
[-] Removed foreign key on columns (organizationId)
[-] Removed unique index on columns (issuer)
[-] Removed unique index on columns (issuer)
[-] Dropped the primary key on columns (id)
[-] Dropped the primary key on columns (id)

[*] Changed the `EmailVerification` table
[-] Removed foreign key on columns (userId)
[-] Removed index on columns (token, email)
[-] Removed unique index on columns (token)
[-] Dropped the primary key on columns (id)

[*] Changed the `Module` table
[+] Added foreign key on columns (templateId)

[*] Changed the `ModuleExtension` table
[+] Added primary key on columns (moduleId)
)

We need to reset the following schemas: "dbo, deploy, module, user"
Drift detected: Your database schema is not in sync with your migration history.

The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.

It should be understood as the set of changes to get from the expected schema to the actual schema.

[*] Changed the `AccountProvider` table
[-] Removed foreign key on columns (organizationId)
[-] Removed unique index on columns (issuer)
[-] Removed unique index on columns (issuer)
[-] Dropped the primary key on columns (id)
[-] Dropped the primary key on columns (id)

[*] Changed the `EmailVerification` table
[-] Removed foreign key on columns (userId)
[-] Removed index on columns (token, email)
[-] Removed unique index on columns (token)
[-] Dropped the primary key on columns (id)

[*] Changed the `Module` table
[+] Added foreign key on columns (templateId)

[*] Changed the `ModuleExtension` table
[+] Added primary key on columns (moduleId)
)

We need to reset the following schemas: "dbo, deploy, module, user"
it still seems to continue to get confused with tables with the same name but in different schemas
7 Replies
Prisma AI Help
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurul7d ago
Can you try running this command and see what output you get? npx prisma migrate diff \ --from-url "$DATABASE_URL" \ --to-schema-datamodel prisma/schema.prisma \ --script > fix_migration.sql This will generate a “diff” migration script that describes how to get from your database to the schema in schema.prisma
Nurul
Nurul7d ago
Prisma CLI reference | Prisma Documentation
This page gives an overview of all available Prisma CLI commands, explains their options and shows numerous usage examples.
Spencer
SpencerOP7d ago
hey @Nurul , yes I ran that script, which is a wild output because it seems to want to drop a bunch of foreign keys and then drop a bunch of tables would it be helpful to show you the output? @Nurul i'm heavily using these 2 preview features, would you recommend against one of these? previewFeatures = ["prismaSchemaFolder", "multiSchema"] I absolutely need to use the multiSchema, so I guess i'm mainly asking about the prismaSchemaFolder, should i consolidate my entire schema into a single schema.prisma file, which I would hope I wouldn't have to do.
yaroslavb
yaroslavb7d ago
@Nurul Here is a super basic example with a single table: https://github.com/YaroBear/prisma-schema-conflict I'll create a corresponding issue on github for this as well
GitHub
GitHub - YaroBear/prisma-schema-conflict: Simple example that illus...
Simple example that illustrates prisma migration issues with tables that share the same name in different schemas - YaroBear/prisma-schema-conflict
yaroslavb
yaroslavb7d ago
GitHub
Multischema support for tables with duplicate names not working (Sq...
Bug description When working with multiple database schemas in Prisma, I encountered the following problem: Initial setup: Created a User table in the dbo schema through my first migration Second m...
Nurul
Nurul4d ago
Thank you for submitting the bug report and creating a reproduction repository 🙏 I'll go through the reproduction. ORM team should pick it up

Did you find this page helpful?