chkit
v0.2.0-beta.19
Published
ClickHouse schema and migration CLI for TypeScript projects
Maintainers
Readme
chkit
ClickHouse schema management in TypeScript, with Python support in beta.
chkit is an open-source CLI for defining ClickHouse schemas in code, generating SQL migrations, and checking schema drift. Keep definitions and migration files in your repository, review the SQL before applying it, and verify the live database from the terminal or CI.
Get started · First-schema tutorial · Documentation
TL;DR
Define → generate → preview → migrate → check. TypeScript schemas use @chkit/core. Python support is in beta and uses chkit-py, with the same migration SQL, snapshots, and ClickHouse journal.
Features
- Schema as code — Define tables, views, materialized views, and dictionaries with ClickHouse-native types and options.
- Migration generation — Diff definitions against the previous snapshot and generate timestamped SQL migrations with rename metadata.
- Migration risk checks — Review risk levels and approve destructive operations before applying them.
- Drift detection — Compare the schema snapshot against a live ClickHouse instance to catch out-of-band changes.
- CI gate — Run
chkit checkto fail builds on pending migrations, checksum mismatches, or schema drift. - TypeScript codegen — Generate row types and optional Zod schemas with
@chkit/plugin-codegen. - Schema pulling — Import a live ClickHouse schema into local files with
@chkit/plugin-pull. - Data backfill (beta) — Run checkpointed SQL backfills for data migrations with
@chkit/plugin-backfill. - JSON output — Use
--jsonfor scripting and automation.
Install
bun add -d chkit @chkit/coreInstall both packages: the CLI runs commands, and @chkit/core provides the schema DSL and config helpers imported by TypeScript projects.
First migration
Initialize the config and starter schema:
bunx chkit initChoose a database connection in the prompt, or set CLICKHOUSE_URL, CLICKHOUSE_USER, and CLICKHOUSE_PASSWORD for an existing ClickHouse instance. Edit the starter definition in src/db/schema/example.ts to match the intended table, then run the schema workflow:
# Generate SQL from the schema definitions
bunx chkit generate --name create-events
# Review chkit/migrations/*.sql, then preview pending migrations
bunx chkit migrate --json
# Apply the reviewed migrations
bunx chkit migrate --apply
# Verify migration state and the live schema
bunx chkit status
bunx chkit checkWithout --apply, JSON mode only prints the pending migration plan. Commit the schema definitions, migration files, and chkit/meta/ together. Repeat the workflow after changing a definition, and use chkit drift for a detailed schema comparison.
All commands support --json for machine-readable output and --config <path> for a custom config file. The first-schema tutorial includes a complete definition, database setup, queries, and a schema change.
Python (beta)
Python support is in beta. Install the Python implementation and initialize a project:
pip install chkit-py
chkit initUse Python schema modules and clickhouse.config.py, then run the same generate, migrate, status, drift, and check commands. See the Python overview.
Requirements
- Node.js 22+ or Bun 1.3.5+ for TypeScript config and schemas. Python projects require Python 3.11+ and
chkit-py. - ClickHouse 24.x or newer, self-hosted or managed. Some schema features are version-gated; see ClickHouse compatibility.
Plugins
| Plugin | Description |
| --- | --- |
| @chkit/plugin-codegen | Generate TypeScript row types and Zod schemas |
| @chkit/plugin-pull | Pull a live schema into local definitions |
| @chkit/plugin-tinybird | Import a Tinybird project as a chkit schema and typed queries |
| @chkit/plugin-backfill | Run checkpointed SQL backfills for data migrations (beta) |
| @chkit/plugin-sync | Sync API data into ClickHouse with journaled checkpoints (beta) |
| @chkit/plugin-obsessiondb | Connect to ObsessionDB and run schema commands remotely |
Register plugins in clickhouse.config.ts. See the plugin documentation for setup.
AI agent skill
Install the schema skill for AI coding assistants:
npx skills add obsessiondb/chkit --skill chkitSee Agent skills for supported tools and setup.
Versioning and releases
chkit is pre-1.0: the public API is still evolving, and releases may contain breaking changes. Pin versions for reproducible installs.
- All publishable packages release in lockstep. Install matching versions of
chkit,@chkit/core, and plugins. - The supported public API is the CLI,
@chkit/core, and@chkit/plugin-*.@chkit/clickhouseand@chkit/codegenare internal packages. - At 1.0, chkit will follow SemVer with breaking changes in major releases.
chkit Sync (beta)
We're also building chkit Sync, a beta toolkit for syncing data from business applications into ClickHouse. It builds on chkit's schema management and has its own Sync documentation.
License
The ObsessionDB team builds and maintains chkit. Connect to its managed ClickHouse service with @chkit/plugin-obsessiondb.
