
const { Sequelize } = require('sequelize');
require('dotenv').config();

const sequelize = new Sequelize(
  'postgres', // Connect to default DB to list others
  process.env.DB_USER,
  process.env.DB_PASS,
  {
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
    dialect: 'postgres',
    logging: false,
  }
);

async function check() {
  try {
    const [results, metadata] = await sequelize.query("SELECT datname FROM pg_database WHERE datistemplate = false");
    console.log('Databases:', results.map(r => r.datname));
  } catch (err) {
    console.error('Error:', err);
  } finally {
    await sequelize.close();
  }
}

check();
