a year ago
I am so beyond confused right now.
I have a railway database, and a vercel project.
The vercel project is set to connect to DATABASE_URL, but i'm getting this error:
The provided database string is invalid. Error parsing connection string: empty host in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
Health check failed: PrismaClientInitializationError:
Invalid `prisma.$queryRaw()` invocation:
The provided database string is invalid. Error parsing connection string: empty host in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
at _n.handleRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:7154)
...... {
clientVersion: '5.10.2',
errorCode: undefinedWell, that doesn't make sense.
0 Replies
So i created a health check endpoint, see whats going on:
{
"status": "unhealthy",
"error": "\nInvalid `prisma.$queryRaw()` invocation:\n\n\nThe provided database string is invalid. Error parsing connection string: empty host in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.",
"environment": {
"DATABASE_URL": true
}
}Okay….
I look at the built DATABASE_URL from railway after linking, its missing the host in the constructed URL?
a year ago
can you show me what you mean please?
import { PrismaClient } from '@prisma/client'
const prismaClientSingleton = () => {
if (!process.env.DATABASE_URL) {
throw new Error('DATABASE_URL environment variable is not set');
}
return new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_URL
}
},
log: ['error', 'warn']
});
}
declare global {
var prisma: undefined | ReturnType
}
const prisma = globalThis.prisma ?? prismaClientSingleton()
if (process.env.NODE_ENV !== 'production') globalThis.prisma = prisma
export { prisma }a year ago
can you show me the missing host? of course hiding the password portion
I unlinked them, and relinked. Host is there now, but its @postgres.railway.interal, is that correct for the vercel app? I would think that internal wouldn't work with vercel, no?
Either way, after unlinking and relinking the host is there, but cleared cache on vercel, redeploy, and still getting the same error on build.
a year ago
you would indeed need to use the public url
"For example, if you have a Railway project with the Postgres plugin, the DATABASE_URL variable will be available to your Vercel deployments."
From vercel's site
Just heads up. Switched to DATABASE_PUBLIC_URL for connection, trying redeploy now.
a year ago
looks like their docs are outdated by quite a while
Can't reach database server at `postgres.railway.internal`:`5432`
Please make sure your database server is running at `postgres.railway.internal`:`5432`.
at _n.handleRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:7154)
at _n.handleAndLogRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:6188)
at _n.request (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:5896)
at async l (/vercel/path0/node_modules/@prisma/client/runtime/library.js:128:10871)
at async c (/vercel/path0/.next/server/app/api/health/route.js:1:807)
at async /vercel/path0/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:37010
at async eC.execute (/vercel/path0/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:27552)
at async eC.handle (/vercel/path0/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:38344)
at async exportAppRoute (/vercel/path0/node_modules/next/dist/export/routes/app-route.js:77:26)
at async exportPageImpl (/vercel/path0/node_modules/next/dist/export/worker.js:175:20) {
clientVersion: '5.10.2',
errorCode: undefinedI don't get it.
This is with using DATABASE_PUBLIC_URL.
a year ago
postgres.railway.internal would be from the private url
a year ago
or from PGHOST
Well it still looks like a private network url, domains that end with .railway.internal cannot be used outside of railway projects (think of it as service names in a docker compose created network)
You need to give vercel a url with a domain that looks like "…something.proxy.rlwy.net"
Also a really simple way to check if a domain is publicly accessible is to just ping it with a standard ping command
