fix: migrate.js retry DB connection + align CORS_ORIGINS pattern on dev
migrate.js now retries up to 12 times with linear backoff (max 30s per attempt)
instead of crashing immediately — prevents container restart loops when the
standalone Coolify DB is temporarily unreachable at startup.
CORS_ORIGINS in docker-compose.dev.yml now uses ${CORS_ORIGINS:-https://dev.metalfrom.eu}
to match the prod pattern and allow Coolify UI override.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bf03647de6
commit
c55366fb25
2 changed files with 16 additions and 2 deletions
|
|
@ -6,10 +6,24 @@ import { fileURLToPath } from 'url';
|
|||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const MIGRATIONS_DIR = path.join(__dirname, '../migrations');
|
||||
|
||||
async function connectWithRetry(client, maxAttempts = 12) {
|
||||
for (let i = 1; i <= maxAttempts; i++) {
|
||||
try {
|
||||
await client.connect();
|
||||
return;
|
||||
} catch (err) {
|
||||
if (i === maxAttempts) throw err;
|
||||
const delay = Math.min(2000 * i, 30000);
|
||||
console.log(`[migrate] DB not ready (attempt ${i}/${maxAttempts}), retry in ${delay}ms — ${err.message}`);
|
||||
await new Promise(r => setTimeout(r, delay));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const client = new pg.Client({ connectionString: process.env.DATABASE_URL });
|
||||
|
||||
async function run() {
|
||||
await client.connect();
|
||||
await connectWithRetry(client);
|
||||
|
||||
await client.query(`
|
||||
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ services:
|
|||
PORT: "3000"
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
BM_IMPORT_TOKEN: ${BM_IMPORT_TOKEN}
|
||||
CORS_ORIGINS: https://dev.metalfrom.eu
|
||||
CORS_ORIGINS: ${CORS_ORIGINS:-https://dev.metalfrom.eu}
|
||||
networks:
|
||||
- bm_internal
|
||||
- coolify
|
||||
|
|
|
|||
Loading…
Reference in a new issue