Connection timeout when connecting supabase to astro project while using Drizzle kit

this is the issue I ran into
PS C:\Users\User\Desktop\folder> pnpm run db:push

> [email protected] db:push C:\Users\User\Desktop\folder
> drizzle-kit push:pg

drizzle-kit: v0.20.14
drizzle-orm: v0.30.0

No config path provided, using default path
Reading config file 'C:\Users\User\Desktop\folder\drizzle.config.ts'
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

Error: connect ETIMEDOUT XXX.XXX.XXX.XXX:5432
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:671:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: 'XXX.XXX.XXX.XXX',
port: 5432
}

Node.js v18.18.0
 ELIFECYCLE  Command failed with exit code 1.
PS C:\Users\User\Desktop\folder> pnpm run db:push

> [email protected] db:push C:\Users\User\Desktop\folder
> drizzle-kit push:pg

drizzle-kit: v0.20.14
drizzle-orm: v0.30.0

No config path provided, using default path
Reading config file 'C:\Users\User\Desktop\folder\drizzle.config.ts'
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

Error: connect ETIMEDOUT XXX.XXX.XXX.XXX:5432
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:671:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: 'XXX.XXX.XXX.XXX',
port: 5432
}

Node.js v18.18.0
 ELIFECYCLE  Command failed with exit code 1.
1 Reply
Chi Hao
Chi HaoOP9mo ago
This is my drizzle.config.ts
import type { Config } from "drizzle-kit";
import 'dotenv/config';

const URL = process.env.SECRET_SUPABASE_URL;

if (!URL) {
throw new Error("DATABASE_URL is missing");
}

export default {
schema: "./src/lib/schema.ts",
out: "./drizzle",
dbCredentials: {
connectionString: URL,
},
driver: "pg",
verbose: true,
strict: true,
} satisfies Config;
import type { Config } from "drizzle-kit";
import 'dotenv/config';

const URL = process.env.SECRET_SUPABASE_URL;

if (!URL) {
throw new Error("DATABASE_URL is missing");
}

export default {
schema: "./src/lib/schema.ts",
out: "./drizzle",
dbCredentials: {
connectionString: URL,
},
driver: "pg",
verbose: true,
strict: true,
} satisfies Config;
this is my src/lib/db.ts
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import type { MyDatabase } from "@/lib/schema";

export const connectionString = import.meta.env.SECRET_SUPABASE_URL;

declare global {
var db: MyDatabase | undefined;
}

let db: MyDatabase;

if (!global.db) {
const client = postgres(connectionString, { prepare: false })

global.db = drizzle(client, { logger: true });
}

db = global.db;

export default db;
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import type { MyDatabase } from "@/lib/schema";

export const connectionString = import.meta.env.SECRET_SUPABASE_URL;

declare global {
var db: MyDatabase | undefined;
}

let db: MyDatabase;

if (!global.db) {
const client = postgres(connectionString, { prepare: false })

global.db = drizzle(client, { logger: true });
}

db = global.db;

export default db;
this is the script at package.json
"db:push": "drizzle-kit push:pg",
"db:push": "drizzle-kit push:pg",
my .env variables' names looks like this
SECRET_SUPABASE_URL=
SECRET_SUPABASE_ANON_KEY=
SECRET_SUPABASE_URL=
SECRET_SUPABASE_ANON_KEY=
i also encountered an issue whereby im not allowed to use
import.meta.env.SECRET_SUPABASE_URL
import.meta.env.SECRET_SUPABASE_URL
in the drizzle.config.ts file. The error was :
"import.meta" is not available in the configured target environment ("es2015") and will be empty
"import.meta" is not available in the configured target environment ("es2015") and will be empty
I have also tried hard coding the URL and connectionString in the drizzle.config.ts and src/lib/db.ts respectively and I'm still facing the connection timed out issue. solved: I was supposed to use the Connection string URI not the Project URL
Want results from more Discord servers?
Add your server