integratedhub/test-db.ts
2026-02-14 06:10:15 +00:00

53 lines
1.4 KiB
TypeScript

import { Pool } from "pg";
import { load } from "$std/dotenv/mod.ts";
await load({ export: true, allowEmptyValues: true });
const postgresOptions = Deno.env.get("POSTGRES_OPTIONS");
if (!postgresOptions) {
console.error("POSTGRES_OPTIONS is not set");
Deno.exit(1);
}
const pool = new Pool({
connectionString: postgresOptions.replace("postgresql://", "postgres://"),
});
try {
console.log("Attempting to connect to PostgreSQL...");
const client = await pool.connect();
console.log("✅ Connected to PostgreSQL!");
const result = await client.query("SELECT version()");
console.log("PostgreSQL version:", result.rows[0]);
const tables = await client.query(`
SELECT table_name, table_schema
FROM information_schema.tables
WHERE table_schema = 'memory'
OR table_schema = 'checkpoints'
OR table_schema = 'public'
ORDER BY table_schema, table_name
`);
console.log("Tables found:", tables.rows.length);
console.log(
"Tables:",
tables.rows.map((r: { table_schema: string; table_name: string }) =>
`${r.table_schema}.${r.table_name}`
),
);
client.release();
await pool.end();
} catch (error: unknown) {
console.error(
"❌ Database connection failed:",
error instanceof Error ? error.message : String(error),
);
if (error instanceof Error && error.cause) {
console.error("Cause:", error.cause);
}
await pool.end();
Deno.exit(1);
}