Skip to content

refactor(infrastructure): delegate xatu migrations to xatu-cbt#139

Merged
Savid merged 1 commit into
masterfrom
feat/delegate-xatu-migrations
Jun 17, 2026
Merged

refactor(infrastructure): delegate xatu migrations to xatu-cbt#139
Savid merged 1 commit into
masterfrom
feat/delegate-xatu-migrations

Conversation

@Savid

@Savid Savid commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

xatu restructured its ClickHouse migrations into database-agnostic per-schema sets (xatudefault, observoorobservoor, adminadmin), each applied to its target database and tracked in its own schema_migrations_<set> table (hard cutover — the old flat layout and global schema_migrations are gone).

xcli used to re-implement migration-running itself (pointing golang-migrate at the flat deploy/migrations/clickhouse dir, single default db). That breaks against the new layout. Rather than duplicate the new per-set logic here, this PR delegates the whole xatu-migration step to the xatu-cbt binary, which now owns it.

What changed

  • Start() now calls migrateXatu(ctx) instead of the in-tree runXatuMigrations. migrateXatu execs xatu-cbt infra migrate-xatu --xatu-ref <ref> (a new, CBT-free subcommand) against the local cluster.
  • Deleted the duplicated migration implementation: runXatuMigrations, createXatuDatabases, applyXatuMigrationSet, parseXatuCBTEnv, and the xatuMigrationSet type/var.
  • go mod tidy dropped the now-unused direct deps: golang-migrate/migrate, ClickHouse/clickhouse-go, joho/godotenv (and transitive ch-go).

Net: −210 / +25 lines across manager.go + go.mod/go.sum.

Why delegate instead of duplicate

The new per-set / per-database / schema_migrations_<set> logic now lives in exactly one place (xatu-cbt), which is also the component that clones the xatu repo and stands up the local xatu cluster. xcli keeps its per-network SetupNetwork loop unchanged. We use a dedicated migrate-xatu subcommand rather than xatu-cbt infra start --run-migrations, because the latter also runs CBT setup for a single network — which would conflict with xcli's multi-network orchestration.

Production safety

Unchanged and defense-in-depth:

  • The delegated call stays behind the existing xatuSource == constants.InfraModeLocal guard, so hybrid/external mode (remote/production xatu) never triggers it.
  • xatu-cbt's migrate-xatu applies the same local-only guard internally.
  • CBT migrations always target localhost; the external URL only configures the distributed-table pointer inside the local nodes.

Config generation

No changes needed. The generated cbt.yaml still points external.defaultDatabase at default (where the xatu set lands) and transformations.defaultDatabase at the per-network db — both unchanged by the restructure (only how migrations are applied changed, not where tables live).

Testing

  • go build ./..., go vet ./..., golangci-lint (new-from-rev) — clean.
  • pkg/configgen tests pass.
  • Exercised end-to-end via xcli lab up: infra start → migrate-xatu → per-network setup ran against the local 2-node clusters.

Dependency

⚠️ Requires the matching xatu-cbt PR (adds infra migrate-xatu + the database-agnostic migrations). Merge/deploy them together.

🤖 Generated with Claude Code

xatu split its ClickHouse migrations into database-agnostic per-schema sets
(xatu/observoor/admin), each applied to a target database and tracked in its
own schema_migrations_<set> table. Rather than re-implement that layout here,
delegate the entire xatu-migration step to the xatu-cbt binary, which now owns
it via a dedicated `infra migrate-xatu` subcommand.

- Replace the in-tree runXatuMigrations (flat layout, single `default` db,
  global schema_migrations) with migrateXatu, which execs
  `xatu-cbt infra migrate-xatu --xatu-ref <ref>` against the local cluster.
- Drop the now-dead helpers (parseXatuCBTEnv, createXatuDatabases,
  applyXatuMigrationSet) and the golang-migrate / clickhouse-go / godotenv
  dependencies (go mod tidy).

Production safety is unchanged: the call stays behind the existing local-only
guard (xatuSource == local), and xatu-cbt applies the same guard internally, so
hybrid/external mode never migrates the remote/production xatu cluster.

Requires the matching xatu-cbt change (the `infra migrate-xatu` subcommand).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Savid Savid requested a review from mattevans as a code owner June 17, 2026 00:58
@Savid Savid merged commit d94c85c into master Jun 17, 2026
3 checks passed
@Savid Savid deleted the feat/delegate-xatu-migrations branch June 17, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants