// src/config/check-db.js
require('dotenv').config();
console.log('[check-db] Iniciando...');

const pool = require('./db');

(async () => {
  try {
    console.log('[check-db] Variables cargadas:',
      { DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_NAME: process.env.DB_NAME, DB_PORT: process.env.DB_PORT });

    // Opción 1: ping de conexión
    const conn = await pool.getConnection();
    console.log('[check-db] Conexión obtenida del pool');
    await conn.ping();
    conn.release();
    console.log('[check-db] Ping OK');

    // Opción 2: consulta simple
    const [rows] = await pool.query('SELECT 1 AS ok');
    console.log('[check-db] Query OK =>', rows);

    console.log('[check-db] TODO OK ✅');
    process.exit(0);
  } catch (err) {
    console.error('[check-db] ERROR ❌', err && err.code, err && err.message);
    process.exit(1);
  }
})();

