From 699277be07dfc2649f288e6f61da98e8f4d4beea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=9B=D0=B5=D0=B1=D0=B5=D0=B4=D0=B8=D0=BD=D1=81=D0=BA?= =?UTF-8?q?=D0=B8=D0=B9?= Date: Fri, 24 Apr 2026 20:31:43 +0500 Subject: [PATCH] =?UTF-8?q?fix(migrate):=20=D0=BE=D1=81=D0=B2=D0=BE=D0=B1?= =?UTF-8?q?=D0=BE=D0=B6=D0=B4=D0=B0=D1=82=D1=8C=20=D0=BA=D0=BB=D0=B8=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=20=D0=BF=D1=83=D0=BB=D0=B0,=20=D0=B4=D0=B8=D0=B0?= =?UTF-8?q?=D0=B3=D0=BD=D0=BE=D1=81=D1=82=D0=B8=D0=BA=D0=B0=20ECONNREFUSED?= =?UTF-8?q?=20=D0=B8=20AggregateError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- backend/src/db/migrate.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/backend/src/db/migrate.js b/backend/src/db/migrate.js index e564d32..f155a8c 100644 --- a/backend/src/db/migrate.js +++ b/backend/src/db/migrate.js @@ -72,12 +72,41 @@ async function executeMigration(pool, filename) { /** * Main migration function */ +function logMigrationError(error) { + const msg = error?.message || String(error); + console.error('\n✗ Migration failed:', msg || '(no message)'); + if (error?.code) { + console.error(' PG code:', error.code); + } + if (error?.address && error?.port) { + console.error(' connect:', `${error.address}:${error.port}`); + } + if (error?.name === 'AggregateError' && Array.isArray(error.errors)) { + for (const e of error.errors) { + console.error(' —', e?.message || e); + } + } + if (error?.code === 'ECONNREFUSED') { + console.error( + ' hint: проверьте, что Postgres запущен и DATABASE_URL / DB_* в backend/.env совпадают с портом (часто 5432 для Postgres_TG_Bots или 5433 для локального compose).' + ); + } + if (process.env.DEBUG_MIGRATE === '1' || !msg) { + console.error(error); + } +} + async function migrate() { const pool = new Pool(getPoolConfig()); try { console.log('Connecting to database...'); - await pool.connect(); + const client = await pool.connect(); + try { + await client.query('SELECT 1'); + } finally { + client.release(); + } console.log('Connected to database\n'); // Ensure migrations table exists @@ -107,7 +136,7 @@ async function migrate() { console.log(`\n✓ Successfully executed ${pendingMigrations.length} migration(s)`); } } catch (error) { - console.error('\n✗ Migration failed:', error.message); + logMigrationError(error); process.exit(1); } finally { await pool.end();