Files
SBC/server/src/db.js
T
Claude 59256ad9ff Log de diagnostic : hôte PostgreSQL ciblé au démarrage
Affiche host/port/db/user à la connexion et un message explicite en cas
d'échec d'authentification persistant, pour identifier immédiatement une
stack déployée avec une ancienne version du compose.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fkg15RCxNgUys4ru73He2o
2026-07-11 04:45:08 +00:00

37 lines
1.0 KiB
JavaScript

import pg from 'pg';
import { config } from './config.js';
export const pool = new pg.Pool({
...config.db,
max: 10,
idleTimeoutMillis: 30_000,
connectionTimeoutMillis: 5_000,
});
export const query = (text, params) => pool.query(text, params);
export async function waitForDb(retries = 30, delayMs = 1000) {
console.log(
`Connecting to PostgreSQL: host=${config.db.host} port=${config.db.port} ` +
`db=${config.db.database} user=${config.db.user}`
);
for (let i = 1; i <= retries; i++) {
try {
await pool.query('SELECT 1');
return;
} catch (err) {
if (i === retries) {
if (err.code === '28P01') {
console.error(
'Authentication failed: the sbc_app password in PostgreSQL does not match ' +
'PGPASSWORD/APP_DB_PASSWORD. The db-sync service realigns it at every stack ' +
'start — make sure it ran against this same database.'
);
}
throw err;
}
await new Promise((r) => setTimeout(r, delayMs));
}
}
}