/** * Boot-time gate: verify the ClickHouse `_schema_migrations` audit table's * most recently applied row matches the expected version baked into the * deployed image. Companion to the SQL-side helper * `verifyExpectedSchemaVersion` from `@fjall/util/migration` — together they * close the asymmetry where a webapp's boot gate checks Postgres but blindly * trusts ClickHouse. * * The audit table is owned by the migration runner: see the canonical DDL * recorded by `ensureSchemaMigrationsTable` in the webapp's migration-runner * (columns `version`, `applied_at`, `snapshot_arn`, `prisma_version`, * `ch_version`). This helper reads a single configurable column (default * `ch_version`) so callers can pin to whichever the image's expected env * carries (overall migration hash via `version`, Prisma-side via * `prisma_version`, or ClickHouse-side via `ch_version`). * * Returns `{ matches, expected, actual }` rather than throwing on mismatch: * the consumer's boot script owns the exit-code / log shape. * * `matches` tolerates expand-only rollback via the shared * `isSchemaVersionSatisfied` (same comparator the Postgres gate uses, so the * two can't drift): the default `ch_version` field is an orderable `.sql` * filename, so `actual >= expected` passes; the non-orderable audit fields * (`version` sha256 hash, `prisma_version` constant) fall back to strict * identity. */ import type { MigrationLogger } from "./logger.js"; declare const ALLOWED_FIELDS: readonly ["version", "ch_version", "prisma_version"]; type AllowedField = (typeof ALLOWED_FIELDS)[number]; /** * The slice of `ClickHouseClient` this check needs. Structural so a caller * holding a narrower handle (the schema-gate container's injectable * `SchemaGateChHandle`) passes it without a cast; `@clickhouse/client` * satisfies it directly. */ export interface SchemaVersionQueryClient { query(params: { query: string; format: "JSONEachRow"; abort_signal?: AbortSignal; }): Promise<{ json(): Promise; }>; } export interface VerifyExpectedClickHouseSchemaVersionOpts { client: SchemaVersionQueryClient; /** Expected version (typically read from an env var baked into the image). */ expected: string; /** Database holding the audit table. Defaults to `"analytics"`. */ database?: string; /** Audit-table name. Defaults to `"_schema_migrations"`. */ table?: string; /** Column whose latest value to compare. Defaults to `"ch_version"`. */ field?: AllowedField; signal?: AbortSignal; logger?: MigrationLogger; } export interface VerifyExpectedClickHouseSchemaVersionResult { matches: boolean; expected: string; /** `null` when the audit table is empty (no migrations applied yet). */ actual: string | null; } export declare function verifyExpectedClickHouseSchemaVersion(opts: VerifyExpectedClickHouseSchemaVersionOpts): Promise; export {};