spb/datacenterindex
Public
HTML 53.9%
TypeScript 44.5%
JavaScript 0.6%
SQL 0.5%
1// One-shot: create the ClickHouse database + tables (idempotent). Run by `dci-entrypoint migrate`.2// Relative import on purpose: this file lives outside the workspace packages inside the image.3import { ensureClickHouse } from "../../packages/db/src/clickhouse.ts";45const url = process.env.CLICKHOUSE_URL ?? "http://127.0.0.1:8123";6const attempts = Number(process.env.DCI_CLICKHOUSE_ATTEMPTS ?? 20);7for (let i = 1; i <= attempts; i++) {8 try {9 await ensureClickHouse();10 console.log(`clickhouse: database ${process.env.CLICKHOUSE_DB ?? "dci"} ready at ${url}`);11 process.exit(0);12 } catch (e) {13 const msg = (e as Error).message;14 if (i === attempts) {15 console.error(`clickhouse: giving up after ${attempts} attempts: ${msg}`);16 process.exit(1);17 }18 console.warn(`clickhouse: attempt ${i}/${attempts} failed (${msg}); retrying in 3 s`);19 await new Promise((r) => setTimeout(r, 3000));20 }21}22