// One-shot: create the ClickHouse database + tables (idempotent). Run by `dci-entrypoint migrate`. // Relative import on purpose: this file lives outside the workspace packages inside the image. import { ensureClickHouse } from "../../packages/db/src/clickhouse.ts"; const url = process.env.CLICKHOUSE_URL ?? "http://127.0.0.1:8123"; const attempts = Number(process.env.DCI_CLICKHOUSE_ATTEMPTS ?? 20); for (let i = 1; i <= attempts; i++) { try { await ensureClickHouse(); console.log(`clickhouse: database ${process.env.CLICKHOUSE_DB ?? "dci"} ready at ${url}`); process.exit(0); } catch (e) { const msg = (e as Error).message; if (i === attempts) { console.error(`clickhouse: giving up after ${attempts} attempts: ${msg}`); process.exit(1); } console.warn(`clickhouse: attempt ${i}/${attempts} failed (${msg}); retrying in 3 s`); await new Promise((r) => setTimeout(r, 3000)); } }