@fjall/clickhouse-migrations 0.99.4 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/.minified CHANGED
@@ -1 +1 @@
1
- 8 files minified at 2026-05-22T23:32:44.565Z
1
+ 9 files minified at 2026-05-23T06:07:03.980Z
package/dist/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export { type MigrationLogger, createConsoleMigrationLogger, } from "./logger.js
4
4
  export { type ConnectWithRetryOpts, connectWithRetry, } from "./connectWithRetry.js";
5
5
  export { type ProvisionUsersFromEnvOpts, type ProvisionUsersFromEnvResult, provisionUsersFromEnv, } from "./provisionUsers.js";
6
6
  export { type RunSqlMigrationsOpts, type RunSqlMigrationsResult, runSqlMigrations, } from "./runSqlMigrations.js";
7
+ export { type VerifyExpectedClickHouseSchemaVersionOpts, type VerifyExpectedClickHouseSchemaVersionResult, verifyExpectedClickHouseSchemaVersion, } from "./verifyExpectedClickHouseSchemaVersion.js";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{CLICKHOUSE_MANAGED_USERS_ENV as o,userPasswordEnvName as a}from"./constants.js";import{ManagedUserNameSchema as t,ManagedUserNamesSchema as n}from"./schemas.js";import{createConsoleMigrationLogger as i}from"./logger.js";import{connectWithRetry as f}from"./connectWithRetry.js";import{provisionUsersFromEnv as x}from"./provisionUsers.js";import{runSqlMigrations as S}from"./runSqlMigrations.js";export{o as CLICKHOUSE_MANAGED_USERS_ENV,t as ManagedUserNameSchema,n as ManagedUserNamesSchema,f as connectWithRetry,i as createConsoleMigrationLogger,x as provisionUsersFromEnv,S as runSqlMigrations,a as userPasswordEnvName};
1
+ import{CLICKHOUSE_MANAGED_USERS_ENV as o,userPasswordEnvName as a}from"./constants.js";import{ManagedUserNameSchema as t,ManagedUserNamesSchema as s}from"./schemas.js";import{createConsoleMigrationLogger as i}from"./logger.js";import{connectWithRetry as c}from"./connectWithRetry.js";import{provisionUsersFromEnv as x}from"./provisionUsers.js";import{runSqlMigrations as S}from"./runSqlMigrations.js";import{verifyExpectedClickHouseSchemaVersion as M}from"./verifyExpectedClickHouseSchemaVersion.js";export{o as CLICKHOUSE_MANAGED_USERS_ENV,t as ManagedUserNameSchema,s as ManagedUserNamesSchema,c as connectWithRetry,i as createConsoleMigrationLogger,x as provisionUsersFromEnv,S as runSqlMigrations,a as userPasswordEnvName,M as verifyExpectedClickHouseSchemaVersion};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Boot-time gate: verify the ClickHouse `_schema_migrations` audit table's
3
+ * most recently applied row matches the expected version baked into the
4
+ * deployed image. Companion to the SQL-side helper
5
+ * `verifyExpectedSchemaVersion` from `@fjall/util/migration` — together they
6
+ * close the asymmetry where a webapp's boot gate checks Postgres but blindly
7
+ * trusts ClickHouse.
8
+ *
9
+ * The audit table is owned by the migration runner: see the canonical DDL
10
+ * recorded by `ensureSchemaMigrationsTable` in the webapp's migration-runner
11
+ * (columns `version`, `applied_at`, `snapshot_arn`, `prisma_version`,
12
+ * `ch_version`). This helper reads a single configurable column (default
13
+ * `ch_version`) so callers can pin to whichever the image's expected env
14
+ * carries (overall migration hash via `version`, Prisma-side via
15
+ * `prisma_version`, or ClickHouse-side via `ch_version`).
16
+ *
17
+ * Returns `{ matches, expected, actual }` rather than throwing on mismatch:
18
+ * the consumer's boot script owns the exit-code / log shape.
19
+ */
20
+ import type { ClickHouseClient } from "@clickhouse/client";
21
+ import type { MigrationLogger } from "./logger.js";
22
+ declare const ALLOWED_FIELDS: readonly ["version", "ch_version", "prisma_version"];
23
+ type AllowedField = (typeof ALLOWED_FIELDS)[number];
24
+ export interface VerifyExpectedClickHouseSchemaVersionOpts {
25
+ client: ClickHouseClient;
26
+ /** Expected version (typically read from an env var baked into the image). */
27
+ expected: string;
28
+ /** Database holding the audit table. Defaults to `"analytics"`. */
29
+ database?: string;
30
+ /** Audit-table name. Defaults to `"_schema_migrations"`. */
31
+ table?: string;
32
+ /** Column whose latest value to compare. Defaults to `"ch_version"`. */
33
+ field?: AllowedField;
34
+ signal?: AbortSignal;
35
+ logger?: MigrationLogger;
36
+ }
37
+ export interface VerifyExpectedClickHouseSchemaVersionResult {
38
+ matches: boolean;
39
+ expected: string;
40
+ /** `null` when the audit table is empty (no migrations applied yet). */
41
+ actual: string | null;
42
+ }
43
+ export declare function verifyExpectedClickHouseSchemaVersion(opts: VerifyExpectedClickHouseSchemaVersionOpts): Promise<VerifyExpectedClickHouseSchemaVersionResult>;
44
+ export {};
@@ -0,0 +1 @@
1
+ const s=/^[A-Za-z_][A-Za-z0-9_]*$/,n=["version","ch_version","prisma_version"],l="analytics",u="_schema_migrations",E="ch_version";async function h(e){if(e.signal?.aborted)throw new Error("verifyExpectedClickHouseSchemaVersion: aborted by signal before query");const t=e.database??l,c=e.table??u,a=e.field??E;if(!s.test(t))throw new Error(`verifyExpectedClickHouseSchemaVersion: unsafe database identifier '${t}'`);if(!s.test(c))throw new Error(`verifyExpectedClickHouseSchemaVersion: unsafe table identifier '${c}'`);if(!n.includes(a))throw new Error(`verifyExpectedClickHouseSchemaVersion: field must be one of ${n.join("|")} (got '${a}')`);const i=(await(await e.client.query({query:`SELECT ${a} AS value FROM ${t}.${c} ORDER BY applied_at DESC LIMIT 1`,format:"JSONEachRow"})).json())[0]?.value,o=typeof i=="string"?i:null,r={matches:o===e.expected,expected:e.expected,actual:o};return e.logger?.info("ClickHouse schema-version check complete",{matches:r.matches,expected:r.expected,actual:r.actual,database:t,table:c,field:a}),r}export{h as verifyExpectedClickHouseSchemaVersion};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fjall/clickhouse-migrations",
3
- "version": "0.99.4",
3
+ "version": "0.100.0",
4
4
  "description": "Runtime helpers for ClickHouse migration containers — user provisioning, SQL file application, connection retry. Consumes the manifest contract published by @fjall/components-infrastructure ClickHouseDatabase.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -44,11 +44,11 @@
44
44
  "@clickhouse/client": "^1.18.0"
45
45
  },
46
46
  "dependencies": {
47
- "@fjall/util": "^0.99.4",
47
+ "@fjall/util": "^0.100.0",
48
48
  "zod": "^4.4.3"
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=22.0.0"
52
52
  },
53
- "gitHead": "4d52f0059ebb467b4a63603ed397dae36811d735"
53
+ "gitHead": "9eb16c56de49e6757cfd6352ad860dd125c6c21e"
54
54
  }