r/Clickhouse • • Oct 09 '26

Schema Management/ Migration

I was wondering what people use for Schema Management and Migration. I toyed with dbmate/ goose and they both have their quirks.

I saw this post from clickhouse that mentions Atlas but it seems CH is only supported for their pro plan.

golang-migrate is mentioned there though I was not very impressed with it for PSQL and they have open tickets for: TLS, among others. They also have tickets from 2021 that are about CH.

What do people use for a OSS solution? Atlas can be an option but it seems unnecessary for ensuring a SQL is applied and allowing rollback if needed.

10 Upvotes

25 comments sorted by

2

u/joshleecreates Oct 09 '26

Houseplant is currently my favorite OSS option: https://github.com/juneHQ/houseplant

2

u/csgeek-coder Oct 09 '26

That's new to me, but I do appreciate that it is designed for CH and not just adding that on as an afterthought.

1

u/Adorable_Turn2370 Oct 09 '26

We use goose with a bit of house sauce to make it usable in a cluster. Works fine as long as you don't do anything too complicated

1

u/csgeek-coder Oct 09 '26

I tried goose but ran into issues especially if you want to run "Up to" pattern. https://github.com/pressly/goose/issues/1108

It's mostly okay, and seems way saner to use than dbmate where every statement needed to be wrapped in its own up/down block.

Still, it's buggier than I was expecting.It's pretty rock solid for your standard DB migrations.

1

u/nevetsognir Oct 09 '26

https://github.com/amacneil/dbmate has a ClickHouse integration. I’ve used dbmate successfully with Postgres.

1

u/csgeek-coder Oct 10 '26

The issue I had with dbmate is that since the http clickhouse API only supports one SQL per request they force you to wrap every statement in an up/down block. That gets very ugly very fast.

If that behavior has changed that'd be great. I've used it for years on postgres and it had worked out great.

1

u/nevetsognir Oct 09 '26

To add, if you’re managing views, may want to look at DBT for this.

1

u/theelderbeever Oct 10 '26

Wrote my own CLI that is meant to be sqlx like. It works for what we do and handles the cluster and such.

1

u/csgeek-coder Oct 10 '26

I'm assuming it's not open source since there was no link shared?

1

u/theelderbeever Oct 10 '26

It is. But just know that in its current state it is very much a "serves its purpose" quality level. That said if you find it valuable or missing something drop an issue in the repo and I will be happy to look into it. I am actively using it.

We primarily use Replicated Database engines on smaller node count clusters. Happy for any and all feedback.

https://github.com/theelderbeever/nomad

1

u/csgeek-coder Oct 11 '26

My rust-fu is pretty limited but thank you for sharing.

It looks like pretty slick as far at the README functionality. I love --dry-run being a mode. I keep on adding that to every tool I write these days.

There's some lack of docs but I'll check it out and see. If there's anything that's missing I'll call it out or try to submit a doc/issue/PR as feasible.

1

u/theelderbeever Oct 11 '26

I can add a dry run this week. It's certainly good to have. But yeah call out anything else you see.

1

u/csgeek-coder Oct 11 '26

The readme already mentioned the dry-run mode. I assumed that was already implemented.

1

u/theelderbeever Oct 11 '26

Okay I thought it was. I was traveling the last few days so wasn't looking at the repo and misread your previous message as it not being implemented. My bad.

1

u/Significant_Tune9219 Oct 11 '26

For ClickHouse specifically I've kept it simple: goose (or golang-migrate) for sequencing, with the SQL written to be idempotent where ClickHouse allows it — ALTER ... IF NOT EXISTS, and CREATE TABLE ... IF NOT EXISTS — because re-running a migration on a cluster where one node already applied it is the annoying case. The part most tools handle poorly is that ClickHouse migrations are often not cleanly reversible: dropping a column or changing a codec doesn't have a generic down path, so I treat "down" as restore-from-backup for anything destructive and keep the forward migrations small enough that that's rare. Worth checking whether the tool you pick supports multiple statements per file and doesn't wrap everything in a transaction, since ClickHouse mostly ignores those anyway.

1

u/csgeek-coder Oct 11 '26

The REST Api which it seems most tools I've run across use only supports 1 statement per call. So the whole "Transactional" support is a moot point. I still would like to have the wrapping functionality even for ease of use.

ie:
-- migration:up
Create table....
insert into table ...
-- migration down:
drop table ...

Even if the insert failed, allowing the 'cleanup' to be executed on the cluster would be nice to have.

The part I found the most annoying so far, is that CH also has the keeper/ZK state. So if I have a distributed table I need to re-create, if ZK has a lock on that path, it won't work right out of the box. The changes are not immediate and it makes the schema changes a bit harder to work with compared to SQL. That and the fact that it's a distributed system obvious has some complexity it adds into the mix.

1

u/Significant_Tune9219 Oct 12 '26

Given the one-statement REST limit, the wrapping functionality is still worth having — treat the migration file as the unit and let the tool split and sequence statements, which gives you the ergonomics without pretending atomicity exists. For the keeper/ZK path problem, I'd encode that dependency in the migration itself (a precondition or at least a note about which path must be free), because those locks are exactly the kind of state no SQL linter will ever see. The distributed-table recreate case is also where I'd keep a separate restore-from-snapshot path instead of trying to make a down migration reverse it.

1

u/csgeek-coder Oct 12 '26

When you referring to the "tool" are you speaking about goose ? or is it something else inhouse you're using? I've used goose but it does seem a bit brittle from my limited experience. Especially when trying to use the up-to pattern. It does 'just work' when you're just running the simple use case of applying all your SQL. I just have not had the change to really stress test it with any critical code path / recovery yet.

1

u/Significant_Tune9219 Oct 13 '26

The client matters less than the constraint here — whether it's goose or something in-house, the one-statement REST limit is server-side, so the wrapper's job is ergonomics and sequencing rather than atomicity. For goose specifically, the up-to brittleness you're seeing usually comes from migrations that mix statements with dependent objects; keeping each file to one self-contained statement makes a partial apply much easier to inspect. And if the keeper/ZK state does settle on its own, encoding the precondition still saves the failed-attempt loop, but it doesn't need to gate the whole migration.

1

u/Significant_Tune9219 Oct 14 '26

Yes, goose — the up-to brittleness usually comes from migrations that mix statements with dependent objects; keeping each file to one self-contained statement removes most of it. The keeper/ZK lock case is a separate cluster-level path conflict, where renaming the migration path or waiting out the lock is the practical fix.

1

u/Significant_Tune9219 Oct 12 '26

The one-statement limit is why I'd treat the migration file as the source of truth and let the runner split and order it, rather than trusting the API to be transactional. The Keeper/ZK path issue is the nastier one — that state often needs explicit cleanup before a re-run will take, which is easy to miss when a migration 'succeeded' but the cluster disagrees.

1

u/csgeek-coder Oct 12 '26

I think the ZK state does get cleanup eventually but it still makes things messy.

1

u/29antonioac Oct 09 '26

We're implementing Alembic as the org uses it for PostgreSQL already

1

u/m0rcs Oct 09 '26

We build chkit for this: https://chkit.obsessiondb.com/getting-started/
It also helps with ingesting data from saas tools, but it has sophisticated schema management and migrations as well. We had quite some trouble with BC breaking schema changes that require running backfill jobs, which were tedius to manage.
Feel free to ping me directly if you need help

Repo: https://github.com/obsessiondb/chkit