Skip to content

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 workflow

TypeScript schemas + migrations Python (alpha) schemas + migrations

Built byObsessionDBOpen source · MIT

Your repositorysrc/db/schema/*.ts
01SchemaTables · Views · Types
02MigrationsSQL · Snapshots · History
chkitGenerate. Review. Apply.
ClickHouseSchema tracked. Drift checked.

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 DSL

02 / Migrate

Review every change.

Generate SQL from schema changes. Commit migrations alongside the definitions, preview pending changes, and apply them explicitly.

Follow the migration workflow

03 / 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 CI

Schema management in practice

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.

Export a table from the configured schema files. Columns, engine, and ordering describe the intended ClickHouse schema.

src/db/schema/events.ts
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.

Compatible with

  • ObsessionDB

  • ClickHouse Cloud

  • Altinity

  • Self-hosted ClickHouse

  • …and any other ClickHouse

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 →.