Files
descrybe/scripts/wait-postgres.mjs
T
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

44 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
/**
* Wait until docker-compose Postgres is accepting connections.
* Usage: node scripts/wait-postgres.mjs
*/
import { spawnSync } from "node:child_process";
import { setTimeout as delay } from "node:timers/promises";
import { repoRoot } from "./root-env.mjs";
const maxAttempts = Number(process.env.DESCRYBE_DB_WAIT_ATTEMPTS || 60);
const sleepMs = Number(process.env.DESCRYBE_DB_WAIT_MS || 1000);
for (let i = 1; i <= maxAttempts; i++) {
const r = spawnSync(
"docker",
[
"compose",
"exec",
"-T",
"postgres",
"pg_isready",
"-U",
"descrybe",
"-d",
"descrybe",
],
{
cwd: repoRoot,
encoding: "utf8",
shell: process.platform === "win32",
},
);
if (r.status === 0) {
console.log(`[db] postgres ready (attempt ${i})`);
process.exit(0);
}
process.stdout.write(`[db] waiting for postgres… (${i}/${maxAttempts})\r`);
await delay(sleepMs);
}
console.error("\n[db] postgres did not become ready in time");
console.error("Check: docker compose ps && docker compose logs postgres");
process.exit(1);