PyClickHouseMigrator¶
PyClickHouseMigrator is a SQL-first ClickHouse migration runner for teams that keep schema changes in Git and run them through a small, predictable CLI.
It stores migration state inside ClickHouse, validates checksums, supports rollback SQL, handles advisory locking, and works with single-node or cluster deployments.
Install¶
With uv:
The CLI command is:
Quick start¶
Set the ClickHouse connection URL. The database in the URL must already exist.
Create a migrations directory and a first migration:
Edit the generated file in ./db/migrations:
-- migrator:up
-- @stmt
CREATE TABLE IF NOT EXISTS users
(
id UInt64,
name String,
created_at DateTime DEFAULT now()
)
ENGINE = MergeTree
ORDER BY id
-- migrator:down
-- @stmt
DROP TABLE IF EXISTS users
Preview what will run:
Apply pending migrations:
Check status:
Rollback the last applied migration:
Guides¶
- Migration format
- Baseline existing databases
- Cluster mode
- CI/CD usage
- Docker usage
- Python API
- Troubleshooting
- Known limitations
- 2.0 release notes