Question about Prisma Migrations and "public" Schema

Hi! I noticed that in my recent Prisma migrations, the generated SQL now includes "public"."table_name" for table creation and foreign keys, but in my older migrations, it was just "table_name" without the schema prefix. I haven’t changed anything in my schema.prisma regarding schemas. Why does Prisma now add the "public". prefix in migration SQL? Is this a new default behavior in recent Prisma versions? Is there any impact or best practice I should be aware of? Thanks for any clarification!
No description
12 Replies
Prisma AI Help
Prisma AI Help2mo ago
You selected the bot's instantaneous insights. Let me compile your answer right away! Great questions! 1. Why does Prisma now add the "public". prefix in migration SQL?
Prisma has improved its handling of database schemas, especially for PostgreSQL. In recent versions, Prisma is more explicit about schema usage and now includes the "public". prefix in generated SQL to clearly specify the schema where tables and constraints are created. This helps avoid ambiguity, especially in databases with multiple schemas or when using features like multi-schema support. 2. Is this a new default behavior in recent Prisma versions?
Yes, this is a result of ongoing improvements in Prisma's schema and migration logic. The explicit schema prefixing (e.g., "public"."table_name") is part of Prisma's efforts to make migrations more robust and predictable, particularly as features like named constraints and multi-schema support have been introduced and refined in Prisma 3 and later. This ensures that migrations behave consistently, regardless of the database's default search path or existing schema configuration What's new in Prisma? (Q3/21). 3. Is there any impact or best practice I should be aware of?
- If you use only the public schema (the default in PostgreSQL), this change is mostly cosmetic and should not affect your application. - If you use multiple schemas or plan to, being explicit with schema prefixes helps prevent migration or query issues. - When upgrading Prisma, review the Named Constraints upgrade guide to ensure your constraint and index names are handled as expected. - Always introspect your database (prisma db pull) after upgrades to keep your Prisma schema in sync with the actual database state. Let me know if you need more details!
Sheik Mostafizur
Sheik MostafizurOP2mo ago
But in my project, I want to maintain consistency. What should I do now?
Prisma AI Help
Prisma AI Help2mo ago
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Sheik Mostafizur
Sheik MostafizurOP5w ago
@Prisma AI Help But in my project, I want to maintain consistency. What should I do now? @Nurul (Prisma) Sorry for mention please see the problem.
Nurul
Nurul4w ago
Did you upgrade your prisma version recently? Which database are you using? From what I remember we added schema name in migrations a long time back
Sheik Mostafizur
Sheik MostafizurOP4w ago
Yes i updated prisma. Postgresql Database.
Nurul
Nurul4w ago
You shouldn't run into any issues. All the migrations going forward should have the schema prefixed before the table name.
Sheik Mostafizur
Sheik MostafizurOP4w ago
First one is old schema and it's not added public and second one new schema migration here i see the public. so now should i add public in old migration?
No description
No description
Nurul
Nurul4w ago
No, I won't recommend editing the already generated old migration files. Are you facing any issues due to this change?
Sheik Mostafizur
Sheik MostafizurOP4w ago
No...
Nurul
Nurul4w ago
Cool, then you should keep old migrations as it is.
Sheik Mostafizur
Sheik MostafizurOP4w ago
Thank you so much

Did you find this page helpful?