VercelPostgresError - 'missing_connection_string'

Hello everyone! So I'm getting the following error while trying to use the @vercel/postgres package with drizzle ORM
VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.
at createPool (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VGUHM5WG.js:150:34)
at Object.get (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VG
VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.
at createPool (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VGUHM5WG.js:150:34)
at Object.get (webpack-internal:///(rsc)/./node_modules/@vercel/postgres/dist/chunk-VG
Here is my db index.ts
import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';

export const db = drizzle(sql)
import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';

export const db = drizzle(sql)
As well as my drizzle.config.ts
import { loadEnvConfig } from "@next/env";
import type { Config } from "drizzle-kit";
import { cwd } from "process";

loadEnvConfig(cwd());

console.log("url", process.env.DEV_POSTGRES_URL);

let connectionString;

if (process.env.VERCEL_ENV === "production") {
connectionString = process.env.PROD_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "preview") {
connectionString = process.env.STAGING_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "development") {
connectionString = process.env.DEV_POSTGRES_URL;
}

export default {
schema: "./src/lib/db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: connectionString
? connectionString + "?sslmode=require"
: "",
},
} as Config;
import { loadEnvConfig } from "@next/env";
import type { Config } from "drizzle-kit";
import { cwd } from "process";

loadEnvConfig(cwd());

console.log("url", process.env.DEV_POSTGRES_URL);

let connectionString;

if (process.env.VERCEL_ENV === "production") {
connectionString = process.env.PROD_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "preview") {
connectionString = process.env.STAGING_POSTGRES_URL;
} else if (process.env.VERCEL_ENV === "development") {
connectionString = process.env.DEV_POSTGRES_URL;
}

export default {
schema: "./src/lib/db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: connectionString
? connectionString + "?sslmode=require"
: "",
},
} as Config;
Few notes: 1. The URL is provided in connectionString. I'm sure it's defined. I have even hardcoded it. I'm 99% sure that the case is that Vercel postgres doesn't really read it and is trying to look for POSTGRES_URL in the env (which is not present because I want to use prefixes for each DB depending on the environment). 2. As you can probably already guess I'm trying to make it so depending on the environment I'm using a different DB. You got any advice on that?
0 Replies
No replies yetBe the first to reply to this messageJoin