require("dotenv").config();
const { Pool } = require("pg");

// Ensure DATABASE_URL is loaded
if (!process.env.DATABASE_URL) {
  console.error("❌ DATABASE_URL is not set!");
  process.exit(1);
}

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: { rejectUnauthorized: false },
});

// Test Database Connection
(async () => {
  try {
    const result = await pool.query("SELECT NOW()");
    console.log("✅ Connected to the database:", result.rows[0]);
  } catch (error) {
    console.error("❌ Database connection error:", error);
  } finally {
    pool.end();
  }
})();
