Skip to content

chkit drift

Compares your local snapshot against the live ClickHouse schema and reports any differences. Requires both a snapshot file and a clickhouse configuration block.

chkit drift [flags]
FlagTypeDefaultDescription
--table <selector>stringScope drift detection to matching tables

Global flags documented on CLI Overview.

  1. Reads snapshot.json from metaDir. If no snapshot exists, the command fails with an error: “Snapshot not found. Run ‘chkit generate’ before drift checks.”
  2. Requires clickhouse config. If missing, fails with: “clickhouse config is required for drift checks.”
  3. Connects to ClickHouse and introspects the live schema
  4. Compares expected (snapshot) vs actual (live) objects and table shapes
  5. Reports drift at both the object level and the table level

When comparing engines, SharedMergeTree is normalized to MergeTree. This prevents false positives on ClickHouse Cloud, where the server transparently substitutes SharedMergeTree for MergeTree.

Object-level drift:

CodeMeaning
missing_objectExpected object not found in ClickHouse
extra_objectObject in ClickHouse not in snapshot
kind_mismatchObject exists but is a different kind (e.g. table vs view)

Table-level drift:

CodeMeaning
missing_columnColumn in snapshot not found in live table
extra_columnColumn in live table not in snapshot
changed_columnColumn exists but type or default differs
setting_mismatchTable setting value differs
index_mismatchIndex definition differs
ttl_mismatchTTL expression differs
engine_mismatchTable engine differs (after normalization)
primary_key_mismatchPrimary key expression differs
order_by_mismatchORDER BY expression differs
partition_by_mismatchPARTITION BY expression differs
unique_key_mismatchUnique key expression differs
projection_mismatchProjection definition differs

Check for drift:

Terminal window
chkit drift

Check drift for a specific table:

Terminal window
chkit drift --table analytics.events

JSON output for CI:

Terminal window
chkit drift --json
CodeMeaning
0Always succeeds (drift is reported, not enforced)

Use chkit check with failOnDrift to enforce drift-free state in CI.

{
"command": "drift",
"schemaVersion": 1,
"scope": { "enabled": false },
"snapshotFile": "./chkit/meta/snapshot.json",
"expectedCount": 5,
"actualCount": 6,
"drifted": true,
"missing": ["table:analytics.sessions"],
"extra": ["table:analytics.temp_import"],
"kindMismatches": [],
"objectDrift": [
{ "code": "missing_object", "object": "analytics.sessions", "expectedKind": "table", "actualKind": null }
],
"tableDrift": [
{
"table": "analytics.events",
"reasonCodes": ["extra_column", "setting_mismatch"],
"missingColumns": [],
"extraColumns": ["debug_flag"],
"changedColumns": [],
"settingDiffs": [{ "name": "index_granularity", "expected": "8192", "actual": "4096" }],
"indexDiffs": [],
"ttlMismatch": false,
"engineMismatch": false,
"primaryKeyMismatch": false,
"orderByMismatch": false,
"uniqueKeyMismatch": false,
"partitionByMismatch": false,
"projectionDiffs": []
}
]
}