Specifying postgres schema while using a postgres database url
We use prisma migrations with an application that uses kysely, and some direct postgres queries.
The application stores its data in a named postgres schema.
Our application initializes our postgres pool with a database url, stored in an env var.
However, it seems that in order to use prisma with a postgres schema we must append
?schema={name}
to the url that is used by prisma to get prisma to understand that it ought to operate in a schema.
Additionally, it doesn't seem like there is a way to template that url in the prisma configuration. So we end up needing to use a separate database url env var for prisma, or wrap all prisma invocations in a script that derives the prisma version of the url with the ?schema
suffix, from the clean/normal postgres-compatible url.
I'm thinking there must be a better way to do this; what am I missing here?3 Replies
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!Hey 👋
You are correct that Prisma requires the schema to be specified in the connection URL.
One other solution (though not ideal for migrations) is that you can override the connection URL when instantiating the PrismaClient
Ther currently is no way to specify database schema in
schema.prisma
file yetThanks. When you say "currently", does that imply that this is coming in the future?