DRYCODEWORKS
← Dev guides

ClickHouse Schema Migration Tools Compared: 6 Tested on a Cluster

Daniel Young
Daniel YoungFounder, DRYCodeWorks

golang-migrate, goose, dbmate, Flyway, Liquibase and ch-migrate, tested on a ClickHouse cluster, plus Atlas from its docs: failures, mutations and ON CLUSTER.

Most migration tools were built for relational databases, where a migration runs in a transaction and a failed statement rolls everything back. ClickHouse has no such safety net. The teams I worked with were mostly Python teams on Django or SQLAlchemy with Alembic, so I built ch-migrate on Alembic, for ClickHouse only.

Seven toolboxes in a row, connected by one line to a stack of databases with one layer left half-built in orange.

I have opinions, so I tested them. I ran six tools through the same migrations on a two-replica ClickHouse 26.10 cluster. Atlas needs a paid login for ClickHouse, so it's from its docs. ch-migrate is mine; weigh that.

The quick verdict

  • A cluster with backfills: ch-migrate. Of the six I ran, it was the only one that waited for a backfill, and the only one that recovered from a failed migration without cleanup by hand.
  • One Go binary, no Python: dbmate or golang-migrate, with SETTINGS mutations_sync = 2 on backfills.
  • Already on Flyway: Flyway, with the same setting on backfills.
  • Declarative schemas: Atlas Pro. I couldn't test it.
  • Avoid: Liquibase's ClickHouse extension, last released in 2022.

Scorecard

ToolWaits for backfillsAfter a failed migrationHistory on a clusterDown migrations
golang-migrateNoBlocks until fixedSettingYes
gooseNoReruns and failsBuild it yourselfYes
dbmateNoReruns and failsSettingYes
FlywayNoBlocks until fixedSettingPaid editions
LiquibaseNoReruns and failsConfig fileYes
ch-migrateYesReruns safelySettingYes

Two failures that matter

A failed migration leaves half its changes behind. ClickHouse has no transactions for replicated tables, so when the third statement failed, the first two stayed applied in every tool. golang-migrate's ClickHouse driver warns you about this:

The queries are not executed in any sort of transaction/batch, meaning you are responsible for fixing partial migrations.

golang-migrate ClickHouse driver README

What the tool did next is what separates them:

One migration, three statementsCREATE TABLEkeptADD COLUMN emailkeptADD COLUMN c3 …failsNo transaction:What the tool recordedWhat the next run didgolang-migrate, Flywaymarked dirty / failedrefuses to run until you clean up, then force or repairgoose, dbmate, Liquibasenothing recordedreruns from statement 1, which fails: "already exists"ch-migratenothing, plus an in-progress notereruns because every statement is safe to repeat; fix statement 3, run upEvery tool left the first two statements applied. They differ in what a person has to do next.

Most tools record a backfill before it finishes. An ALTER TABLE ... UPDATE is a mutation, and by default ClickHouse doesn't wait for it:

A mutation query returns immediately after the mutation entry is added (in case of replicated tables to ZooKeeper, for non-replicated tables - to the filesystem). The mutation itself executes asynchronously using the system profile settings.

ClickHouse docs: ALTER

goose called the migration done in 0.4 seconds while the rewrite was still running, and the next migration counted 0 of the 500,000 updated rows. Here is goose's output, then system.mutations:

goose up
goose: successfully migrated database to version: 4

┌─mutation_id────┬─is_done─┬─parts_to_do─┐
│ mutation_2.txt │       0 │           1 │
└────────────────┴─────────┴─────────────┘

Five of the six tools did the same. ch-migrate polled system.mutations and waited 13 seconds; golang-migrate waited too once I added SETTINGS mutations_sync = 2 to the statement.

The tools

golang-migrate

golang-migrate is a Go binary with SQL up and down files.

  • Stops after a failure. It marks the version dirty, and nothing runs until you clean up and force.
  • Multi-statement files fail by default. Set x-multi-statement=true.

Best for: Go teams that want one binary.

goose

goose is a Go binary; migrations are SQL or Go functions.

  • Go functions as migrations, for logic SQL can't express.
  • Reruns from the top after a failure, which failed on statement 1: "already exists".
  • No cluster option. Its documented workaround also needs a version-0 row inserted by hand.

Best for: a single server and DDL that's safe to run twice.

dbmate

dbmate is a single binary, also on npm, with SQL files.

  • Cluster history from one setting, on_cluster, and status --exit-code for CI.
  • Set zoo_path per database, or a second database on the same cluster fails with REPLICA_ALREADY_EXISTS.

Best for: a small binary with real cluster support.

Flyway

Flyway is a JVM CLI with a community ClickHouse plugin and a JDBC driver you add yourself.

  • The safest defaults. It blocks after a failure until you clean up and repair, and refused to run on the second replica until I set clusterName.
  • Down migrations need a paid edition: "Upgrade required: undo is not supported by Community."

Best for: teams already running Flyway.

Liquibase

Liquibase is a JVM CLI with a third-party ClickHouse extension.

  • Hard to run on Liquibase 5. It needed a legacy JDBC driver, compress=0 and runInTransaction:false on every changeset.
  • Its lock didn't stop a second run.

Best for: teams already on it, until there's a maintained extension.

Atlas

Declarative schemas or versioned SQL, with ClickHouse on the Pro plan. Without a login it stopped at "Error: login is required to use the 'clickhouse' driver". Its docs say it resumes a failed file from the failing statement and generates ON CLUSTER for you. Review every plan it writes.

Best for: declarative schema management, if you'll pay for it.

ch-migrate

My tool: Python, ClickHouse only, SQL files on Alembic.

  • Waits for backfills, and refuses migrations that aren't safe to run twice before it sends anything.
  • Recovers on its own. After I fixed the failing statement, the next up reran the migration and finished, with no cleanup.
  • Strict and young. It waits for every mutation, even other people's, wants a written reason on every data change, and has one main author. I tested 0.7.0; 0.8 and 0.9 added drift checks and access management, and didn't change how up waits or recovers.

Best for: clusters with backfills, where a wrong rerun is expensive.

None of the six stopped two runs started at once: both applied the same migration. Serialize migration jobs in CI.

How I tested

ClickHouse 26.10.3.7 in Docker: one standalone server, and two replicas with one Keeper. Every tool ran the same migrations: one that fails on its third statement, a slow backfill, a cluster migration against each replica in turn, a rollback, and two runs at once.

Run the same tests against your own layout before you trust any of these. For more on ch-migrate, see migrations that wait for mutations, or get in touch for a second opinion on your migration workflow.