P
Prisma2mo ago
Spocko

Prisma runtime error using direct db access in parallel with Accelerate on Vercel

I want to use two paths to Postgres: Prisma Accelerate and direct for a very limited use case (mentioned below) with my Next deployment. I get this runtime error on Vercel, not locally:
Error validating datasource `db`: the URL must start with the protocol `prisma://`
Error validating datasource `db`: the URL must start with the protocol `prisma://`
I export const prisma (for Accelerate) and prismaDirect (for direct access) as follows:
import {PrismaClient} from "@prisma/client"
import {withAccelerate} from "@prisma/extension-accelerate"

export const prisma = new PrismaClient({log: ['error']}).$extends(withAccelerate())

export const prismaDirect = new PrismaClient({datasourceUrl: process.env.DIRECT_DATABASE_URL})
import {PrismaClient} from "@prisma/client"
import {withAccelerate} from "@prisma/extension-accelerate"

export const prisma = new PrismaClient({log: ['error']}).$extends(withAccelerate())

export const prismaDirect = new PrismaClient({datasourceUrl: process.env.DIRECT_DATABASE_URL})
Relevant build output:
$ dotenv -e ../../.env -- npx prisma generate --no-engine
Prisma schema loaded from schema.prisma
✔ Generated Prisma Client (v5.14.0, engine=none) to ./../../node_modules/.prisma/client in 227ms
Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
See other ways of importing Prisma Client: http://pris.ly/d/importing-client
Done in 1.69s.
yarn run v1.22.19
$ dotenv -e ../../.env -- npx prisma migrate deploy
Prisma schema loaded from schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "XX.XX.XX.XX:5432"
32 migrations found in prisma/migrations
No pending migrations to apply.
$ dotenv -e ../../.env -- npx prisma generate --no-engine
Prisma schema loaded from schema.prisma
✔ Generated Prisma Client (v5.14.0, engine=none) to ./../../node_modules/.prisma/client in 227ms
Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
See other ways of importing Prisma Client: http://pris.ly/d/importing-client
Done in 1.69s.
yarn run v1.22.19
$ dotenv -e ../../.env -- npx prisma migrate deploy
Prisma schema loaded from schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "XX.XX.XX.XX:5432"
32 migrations found in prisma/migrations
No pending migrations to apply.
more in thread...
4 Replies
Spocko
Spocko2mo ago
Continued ... My env vars:
DATABASE_URL=prisma://accelerate.prisma-data.net/?api_key=eyJhb...
DIRECT_DATABASE_URL=postgresql://postgres:XXXXXX@YY.YY.YY.YY:5432/postgres?connection_limit=5&sslmode=require
DATABASE_URL=prisma://accelerate.prisma-data.net/?api_key=eyJhb...
DIRECT_DATABASE_URL=postgresql://postgres:XXXXXX@YY.YY.YY.YY:5432/postgres?connection_limit=5&sslmode=require
This all works locally, but not on Vercel. So this could be related to postinstall. My postinstall script:
"postinstall": "cd ../../packages/prisma && yarn generate:noengine && yarn deploy"
"postinstall": "cd ../../packages/prisma && yarn generate:noengine && yarn deploy"
My prisma package.json scripts:
"generate": "dotenv -e ../../.env -- npx prisma generate",
"generate:noengine": "dotenv -e ../../.env -- npx prisma generate --no-engine",
"generate": "dotenv -e ../../.env -- npx prisma generate",
"generate:noengine": "dotenv -e ../../.env -- npx prisma generate --no-engine",
Questions: 1) Should we be able to use direct access with Accelerate? 2) Is there anything wrong with the above? Is there more I can provide to help? My use case is to load up to 30MB into a MUI DataGrid. I could this progressively (via Accelerate without cache), but I don't want to incur excessive data costs associated with the transfer. Thank you! @Nurul (Prisma) @moosthuizen
sachiechan.
sachiechan.5w ago
When using with accelerate you need to import {PrismaClient} from '@prisma/client/edge'
Nurul
Nurul4w ago
Hey, apologies for the delay in getting to this thread. You should be able to have two PrismaClient instance, one with direct database access and the other with Accelerate. Are you still getting this error?
jonfanz
jonfanz4w ago
Pretty sure the issue you’re running into is that you have the no-engine flag when running npx prisma generate. If you remove that flag, is there still an issue?
Want results from more Discord servers?
Add your server
More Posts