Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

clickhouse-migrations

БесплатноБез исполняемых скриптовНе проверен

ClickHouse migration patterns and rules. Use when creating or modifying ClickHouse migrations.

PostHogот PostHog★ 41 278 звёзд на GitHub

Об этом скилле

ClickHouse Migrations

Read posthog/clickhouse/migrations/AGENTS.md for comprehensive patterns, cluster setup, examples, and ingestion layer details.

Quick reference

Migration structure

operations = [
    run_sql_with_exceptions(
        SQL_FUNCTION(),
        node_roles=[...],
        sharded=False,  # True for sharded tables
        is_alter_on_replicated_table=False  # True for ALTER on replicated tables
    ),
]

Node roles (choose by the cluster that owns the object)

Only the members of NodeRole in posthog/clickhouse/client/connection.py are valid: ALL, DATA, INGESTION_EVENTS, INGESTION_SMALL, INGESTION_MEDIUM, INGESTION_METRICS, ENDPOINTS, LOGS, METRICS, INGESTION_APM, AI_EVENTS, AUX, BATCH_EXPORTS, OPS, SESSIONS. A name that is not in that enum fails at import, which aborts migration discovery and takes every job that runs migrations down with it.

Pick the role by which cluster owns the object, not by its type alone:

  • [NodeRole.DATA]: objects that belong on the main cluster — sharded tables, the Distributed read tables in front of sharded or satellite tables, views, dictionaries. A non-sharded replicated table on DATA keeps a full copy on every main-cluster node, so it is the wrong home for a product rollup or pre-aggregate (see below).
  • [NodeRole.INGESTION_SMALL], [NodeRole.INGESTION_MEDIUM], [NodeRole.INGESTION_EVENTS]: writable tables, Kafka tables, materialized views on the ingestion layer. INGESTION_EVENTS is for consumers of all of clickhouse_events_json. For other topics, check where comparable consumers run in each environment, and use INGESTION_SMALL or INGESTION_MEDIUM to match. Use INGESTION_SMALL when you can't tell.
  • [NodeRole.INGESTION_APM]: the ingestion-apm nodes, the metrics ingestion layer. Kafka tables, Null input tables, materialized views and writable Distributed tables that write into storage on LOGS. Stateless like the other ingestion nodes, so storage tables never go here.
  • [NodeRole.METRICS], [NodeRole.INGESTION_METRICS]: the metrics cluster and the ingestion-metrics nodes that write to it. In cloud the metrics4 tables run only on these (0376 and 0379 removed them from INGESTION_APM and LOGS). The local stacks still run them on INGESTION_APM and LOGS, so a metrics4 change targets both pairs.
  • [NodeRole.OPS], [NodeRole.LOGS], [NodeRole.AUX], [NodeRole.AI_EVENTS], [NodeRole.SESSIONS], [NodeRole.BATCH_EXPORTS]: objects that live on a satellite cluster. A table for one of those on DATA lands on the wrong nodes and leaves the intended cluster without it, so check where the object is read and written before defaulting to DATA. Dev runs the same satellite clusters as US/EU prod — never branch on CLOUD_DEPLOYMENT to give dev a different layout.
  • [NodeRole.ALL]: rarely used

Pre-aggregates and rollups are stored on a satellite and read through a Distributed table on DATA (and on the storage satellite, for ad-hoc reads there), unless the app already connects to that satellite directly. A rollup of a satellite's own data stays on that satellite; general product pre-aggregates go to AUX. Confirm the satellite with the live check below, and find a current example's HCL layers with hclexp locate.

Check the live clusters before choosing a role

Older migrations, the HCL local layers and shared helpers can trail what runs in dev and production. Confirm placement against the live clusters before writing the migration:

  1. Use the ClickHouse MCP to check each of dev, prod-us and prod-eu: where comparable tables live, which satellite tables the main cluster reads through Distributed tables, and that the new table names are unused. See the Housekeeper MCP runbook for setup and usage.
  2. When precedents disagree, follow the newest migration for that table family and confirm it matches what runs in all three environments. A layout that only some environments still run is mid-migration, not a pattern to copy.
  3. State in the PR description which cluster each new object lands on, and name the reference migration or live check behind the choice.

Table engines quick reference

MergeTree engines:

  • AggregatingMergeTree(table, replication_scheme=ReplicationScheme.SHARDED) for sharded tables
  • ReplacingMergeTree(table, replication_scheme=ReplicationScheme.REPLICATED) for non-sharded
  • Other variants: CollapsingMergeTree, ReplacingMergeTreeDeleted

Distributed engine:

  • Sharded: Distributed(data_table="sharded_events", sharding_key="sipHash64(person_id)")
  • Non-sharded: Distributed(data_table="my_table", cluster=settings.CLICKHOUSE_SINGLE_SHARD_CLUSTER)

Kafka engine — kafka_engine() returns the ENGINE clause only, so every table appends its own SETTINGS. Start from this baseline:

SETTINGS k
Полный SKILL.md на GitHub

Установить clickhouse-migrations в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл clickhouse-migrations?

ClickHouse migration patterns and rules. Use when creating or modifying ClickHouse migrations.

Как установить скилл clickhouse-migrations?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл clickhouse-migrations запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить clickhouse-migrations с