Open-source ClickHouse schema management
ClickHouse schemas.
Managed in code.
Define tables and views in TypeScript, with Python support in alpha. Generate migration SQL, review changes, and apply them to ClickHouse. Keep the schema and its history in your repository.
See the schema workflowTypeScript schemas + migrations Python (alpha) schemas + migrations
Built byObsessionDBOpen source · MIT
Use your ClickHouse connection from the terminal or CI.
01 / Define
Keep the schema in code.
Define ClickHouse tables, views, materialized views, and dictionaries. Import definitions from an existing database.
Explore the schema DSL02 / Migrate
Review every change.
Generate SQL from schema changes. Commit migrations alongside the definitions, preview pending changes, and apply them explicitly.
Follow the migration workflow03 / Verify
Detect schema drift.
Check pending migrations, migration checksums, and differences between the declared schema and the live database. Run the same checks in CI.
Add schema checks to CISchema management in practice
From a definition to a reviewed migration
Section titled “From a definition to a reviewed migration”A schema change starts in code and produces SQL to review. This walkthrough uses TypeScript; the Python port (alpha) provides the schema and migration workflow in Python.
Install chkit and @chkit/core, then run chkit init to create the project configuration. The first schema tutorial covers installation, the ClickHouse connection, and each step below.
Declare the table
Section titled “Declare the table”Export a table from the configured schema files. Columns, engine, and ordering describe the intended ClickHouse schema.
import { table } from '@chkit/core'
export const events = table({ database: 'default', name: 'events', columns: [ { name: 'id', type: 'UInt64' }, { name: 'event_type', type: 'String' }, { name: 'created_at', type: 'DateTime' }, ], engine: 'MergeTree()', primaryKey: ['created_at', 'id'], orderBy: ['created_at', 'id'],})The schema reference covers engines, keys, indexes, views, and dictionaries.
Generate SQL and review the plan
Section titled “Generate SQL and review the plan”Generate a migration from the definitions, inspect its SQL in chkit/migrations/, and preview the pending migrations before applying.
bunx chkit generate --name create-eventsbunx chkit migrate --json
# Apply after reviewing the generated SQL and plan.bunx chkit migrate --applyCommit the definitions, migration SQL, and metadata together. chkit records applied migrations in ClickHouse. See the migration workflow for review, destructive changes, and deployment.
Add a column through another migration
Section titled “Add a column through another migration”Replace the table definition to add user_id with a default for existing rows.
import { table } from '@chkit/core'
export const events = table({ database: 'default', name: 'events', columns: [ { name: 'id', type: 'UInt64' }, { name: 'event_type', type: 'String' }, { name: 'created_at', type: 'DateTime' }, { name: 'user_id', type: 'UInt64', default: 0 }, ], engine: 'MergeTree()', primaryKey: ['created_at', 'id'], orderBy: ['created_at', 'id'],})bunx chkit generate --name add-user-idbunx chkit migrate --jsonbunx chkit migrate --applychkit compares the updated definition with the last snapshot and generates an ADD COLUMN migration. Review the SQL before applying it.
Check migration state and drift
Section titled “Check migration state and drift”Check whether migrations are pending, checksums have changed, or the live schema differs from the declared schema.
bunx chkit statusbunx chkit driftbunx chkit checkUse chkit check as the CI gate. Its exit code reports whether the schema and migration state satisfy the checks.
Schema tools
Fit the existing project.
Import a live schema, generate application types, or backfill stored data after a schema change. Add the plugins the project needs.
Compatible with
ObsessionDB
ClickHouse Cloud
Altinity
Self-hosted ClickHouse
…and any other ClickHouse
Manage your ClickHouse schema.
Also in development: chkit Sync (beta)
We’re also building chkit Sync to sync business app data into ClickHouse. It has its own setup, integration, and operations guides in the Sync documentation →.