P
Prisma•2w ago
davidmfoley

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
Prisma AI Help
Prisma AI Help•2w ago
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
Nurul•2w ago
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
const prisma = new PrismaClient({
datasources: {
db: {
url: `${process.env.DATABASE_URL}?schema=your_schema_name`
}
}
})
const prisma = new PrismaClient({
datasources: {
db: {
url: `${process.env.DATABASE_URL}?schema=your_schema_name`
}
}
})
Ther currently is no way to specify database schema in schema.prisma file yet
davidmfoley
davidmfoleyOP•3d ago
Thanks. When you say "currently", does that imply that this is coming in the future?

Did you find this page helpful?