clickhouse-migration-deep-dive
БесплатноБез исполняемых скриптовНе проверенExecute ClickHouse schema migrations — ALTER TABLE operations, data migration between engines, versioned migration runners, and zero-downtime schema changes…
от jeremylongshore★ 2 961 звезда на GitHubОб этом скилле
ClickHouse Migration Deep Dive
Overview
Plan and execute ClickHouse schema migrations: column changes, engine migrations, ORDER BY modifications, and versioned migration runners. ClickHouse ALTER operations behave unlike PostgreSQL/MySQL — most are asynchronous mutations that rewrite data parts in the background, and some changes (ORDER BY, engine) require full table recreation. This skill walks the safe path for each.
Prerequisites
- ClickHouse admin access
- Backup of production data (see
clickhouse-prod-checklist) - Test environment for validation
Instructions
Follow these steps in order. SQL and runner code for each step live in the linked reference files — keep them open while you work.
Step 1: Classify the operation
Decide whether your change is lightweight (instant, metadata only) or a heavyweight mutation (rewrites parts in the background):
-- Lightweight (instant): ADD COLUMN, RENAME COLUMN, COMMENT COLUMN
ALTER TABLE events ADD COLUMN country LowCardinality(String) DEFAULT '';
-- Heavyweight (mutation): MODIFY COLUMN, DROP COLUMN, DELETE, UPDATE
ALTER TABLE events MODIFY COLUMN properties String CODEC(ZSTD(3));
-- Always monitor mutation progress
SELECT database, table, mutation_id, is_done, parts_to_do
FROM system.mutations WHERE NOT is_done ORDER BY create_time;
Step 2: Run column operations
Use Edit/Write to author the ALTER TABLE statements, then apply them.
Add/modify/drop columns, set materialized defaults, and attach codecs. Full DDL
semantics and every column-operation variant:
DDL & column operations.
Step 3: Recreate the table for ORDER BY / engine changes
ClickHouse has no MODIFY ORDER BY and no in-place engine change. Create a new
table, INSERT ... SELECT the data, then atomically RENAME TABLE to swap.
Full create → copy → swap → verify → drop recipe for both cases:
table recreation.
Step 4: Wire a versioned migration runner
For repeatable, tracked migrations, drive numbered .sql files through a runner
that records applied versions in a _migrations table and stops on first
failure. Use Write to scaffold runner.ts and the sql/NNN-*.sql files, then
run it with npm/node. Full runner, example migration files, and the
operation downtime matrix: migration runner.
Output
Applying this skill produces:
- Executed ALTER statements or recreated-and-swapped tables, with mutations
confirmed complete via
system.mutations WHERE NOT is_done(empty result). - Migration
.sqlfiles undermigrations/sql/(e.g.001-create-events.sql) and arunner.tsthat records each applied version in the_migrationstable. - Verification counts — row counts on the new/old tables matching before the old table is dropped.
Pre-Migration Checklist
- Backup production data (
BACKUP TABLE ... TO S3(...)) - Test migration on staging with production-like data
- Check disk space (mutations create temporary extra parts)
- Schedule during low-traffic window (for heavy mutations)
- Prepare rollback procedure
- Verify mutation completes (
system.mutations WHERE NOT is_done)
Examples
Add a column (instant, no data rewrite):
ALTER TABLE analytics.events
ADD COLUMN IF NOT EXISTS country LowCardinality(String) DEFAULT ''
AFTER user_id;
Change ORDER BY via table recreation and atomic swap:
CREATE TABLE analytics.events_v2 AS analytics.events
ENGINE = MergeTree()
ORDER BY (tenant_id, event_type, toDate(created_at))
PARTITION BY toYYYYMM(created_at);
INSERT INTO analytics.events_v2 SELECT * FROM analytics.events;
RENAME TABLE
analytics.events TO analytics.events_old,
analytics.events_v2 TO analytics.events;
More worked examples: column codecs and materialized defaults in column operations, the MergeTree → ReplacingMergeTree engine swap in table recreation, and end-to-end versioned files in migration runner.
Error Handling
| Error | Cause | Solution |
|---|---|---|
Cannot ALTER: table has mutations |
Mutation queue full | Wait or cancel: KILL MUTATION WHERE ... |
Column already exists |
Re-running migration | Use IF NOT EXISTS |
Cannot convert type |
Incompatible type change | Create new column, backfill, drop old |
Not enough disk space |
Mutation doubles data temporarily | Free space, then retry |
Resources
- ALTER TABLE Reference
- Column Manipulations
- Schema Migration Tools
- Mutations
- For architecture patterns, see `clickhouse-
Установить clickhouse-migration-deep-dive в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBash(npm:*)Bash(node:*)Bash(kubectl:*)Вложенные файлы
FAQ
Что делает скилл clickhouse-migration-deep-dive?
Execute ClickHouse schema migrations — ALTER TABLE operations, data migration between engines, versioned migration runners, and zero-downtime schema changes. Use when modifying ClickHouse schemas, migrating data between tables, or implementing versioned migration workflows. Trigger with "clickhouse migration", "clickhouse ALTER TABLE", "clickhouse schema change", "migrate clickhouse", "clickhouse add column", or "clickhouse schema migration".
Как установить скилл clickhouse-migration-deep-dive?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл clickhouse-migration-deep-dive запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic