From f6af2d2827ab7a6eb2d68b5627a5d1c2e6a3204f Mon Sep 17 00:00:00 2001 From: dionjoshualobo <23h13.joshua@sjec.ac.in> Date: Sat, 21 Feb 2026 23:18:57 +0530 Subject: [PATCH] supabase connection --- lib/db.ts | 20 +++++++++++++------- package.json | 1 + pnpm-lock.yaml | 12 ++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/db.ts b/lib/db.ts index f9e763a..26f680a 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -1,15 +1,21 @@ -import { config } from 'dotenv'; -config({ path: '.env.local' }); - import { Pool } from 'pg'; +import { config } from 'dotenv'; -console.log('process.env:', process.env); -const connectionString = process.env.DATABASE_URL; +// Load environment variables based on the environment +if (process.env.NODE_ENV === 'production') { + config({ path: '.env.production' }); +} else { + config({ path: '.env.local' }); +} -console.log('DATABASE_URL in lib/db.ts:', connectionString); +const connectionString = process.env.NODE_ENV === 'production' + ? process.env.SUPABASE_URL + : process.env.DATABASE_URL; + +console.log('Using connection string:', connectionString); if (!connectionString) { - throw new Error('DATABASE_URL is not set in environment variables'); + throw new Error('Database connection URL is not set in environment variables'); } const pool = new Pool({ diff --git a/package.json b/package.json index 27ed17f..8c8301a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "devDependencies": { "@tailwindcss/postcss": "^4", "@types/node": "^20", + "@types/pg": "^8.16.0", "@types/react": "^19", "@types/react-dom": "^19", "biome": "^0.3.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9fb0efe..e402dbe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,6 +30,9 @@ importers: '@types/node': specifier: ^20 version: 20.19.31 + '@types/pg': + specifier: ^8.16.0 + version: 8.16.0 '@types/react': specifier: ^19 version: 19.2.11 @@ -375,6 +378,9 @@ packages: '@types/node@20.19.31': resolution: {integrity: sha512-5jsi0wpncvTD33Sh1UCgacK37FFwDn+EG7wCmEvs62fCvBL+n8/76cAYDok21NF6+jaVWIqKwCZyX7Vbu8eB3A==} + '@types/pg@8.16.0': + resolution: {integrity: sha512-RmhMd/wD+CF8Dfo+cVIy3RR5cl8CyfXQ0tGgW6XBL8L4LM/UTEbNXYRbLwU6w+CgrKBNbrQWt4FUtTfaU5jSYQ==} + '@types/react-dom@19.2.3': resolution: {integrity: sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==} peerDependencies: @@ -1303,6 +1309,12 @@ snapshots: dependencies: undici-types: 6.21.0 + '@types/pg@8.16.0': + dependencies: + '@types/node': 20.19.31 + pg-protocol: 1.11.0 + pg-types: 2.2.0 + '@types/react-dom@19.2.3(@types/react@19.2.11)': dependencies: '@types/react': 19.2.11