Skip to content

CLI Overview

The chkit CLI manages ClickHouse schemas, migrations, drift detection, and CI checks from the command line. It follows a workflow-oriented design: define your schema in TypeScript, generate migrations, apply them, and verify everything stays in sync.

CommandDescription
chkit initScaffold a new project with config and example schema
chkit generateDiff schema definitions against the last snapshot and produce migration SQL
chkit migrateApply pending migration files to ClickHouse
chkit statusShow migration status (total, applied, pending, checksum mismatches)
chkit driftCompare snapshot against live ClickHouse and report differences
chkit checkRun policy checks for CI gates (pending, checksums, drift, plugins)
chkit queryRun an ad-hoc SQL query against the configured target
chkit pullIntrospect live ClickHouse and generate a TypeScript schema file
chkit codegenGenerate TypeScript types from schema definitions
chkit pluginList or run plugin commands

Some commands run entirely against local files; others read or write a live ClickHouse instance. Generating a migration is offline, so it needs no connection or credentials. Applying one, or introspecting a live database, connects.

Two groups of commands. No connection: generate (diff schema vs snapshot), codegen (types from schema), and editing schema files. Connects to ClickHouse: migrate (apply SQL), pull (introspect), status (read journal), check and drift (compare live DB to code).
Needs a connectionOffline
migrate (apply SQL), pull (introspect), status (read journal), check / drift (compare live DB to code)generate (diff schema vs. snapshot), codegen (types from schema), editing schema files
chkit init # scaffold config + example schema
chkit generate # diff schema → produce migration SQL + snapshot
chkit migrate # apply pending migrations to ClickHouse
chkit status # verify migration state
chkit check # CI gate: pending, checksums, drift, plugins

These flags are available on every command that loads a config file:

FlagTypeDefaultDescription
--config <path>stringclickhouse.config.tsPath to the chkit config file
--jsonbooleanfalseEmit machine-readable JSON output
--table <selector>stringNarrow some commands to matching tables (exact name or trailing wildcard prefix, e.g. events_*). Effect varies per command — see note below
--helpbooleanShow help text
--versionbooleanPrint CLI version

--table is accepted by every command, but it is not a universal, whole-command filter — treat it as a scoping hint, not a guarantee:

  • generate, migrate, and drift use it to narrow the schema/migration operations they plan or evaluate.
  • check applies it only to its drift and plugin checks; the pending-migration and checksum checks still run across all tables, so chkit check --table app.users can still fail on an unrelated pending migration.
  • status, codegen, and pull accept the flag but ignore it, so chkit status --table app.users still reports unscoped totals.

When you need a result strictly limited to specific tables, check the individual command’s page for its exact scoping behavior.

These environment variables affect every command:

VariableDescription
CHKIT_DEBUGSet to 1 or true to emit structured debug logging to stderr. Covers config loading, command dispatch, plugin lifecycle hooks, ClickHouse queries with timing, journal operations, and per-command details.
CHKIT_JOURNAL_TABLEOverride the name of the migration journal table (default _chkit_migrations). See chkit migrate.

Debug logging is written to stderr, so it never contaminates --json output on stdout:

Terminal window
CHKIT_DEBUG=1 chkit migrate --apply