clickhouse-migrations
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 based on table type)
[NodeRole.DATA]: Sharded tables (data nodes only)[NodeRole.DATA, NodeRole.COORDINATOR]: Non-sharded data tables, distributed read tables, replicated tables, views, dictionaries[NodeRole.INGESTION_SMALL]: Writable tables, Kafka tables, materialized views on ingestion layer
Table engines quick reference
MergeTree engines:
AggregatingMergeTree(table, replication_scheme=ReplicationScheme.SHARDED)for sharded tablesReplacingMergeTree(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)
Critical rules
- NEVER use
ON CLUSTERclause in SQL statements - Always use
IF EXISTS/IF NOT EXISTSclauses - When dropping and recreating replicated table in same migration, use
DROP TABLE IF EXISTS ... SYNC - If a function generating SQL has on_cluster param, always set
on_cluster=False - Use
sharded=Truewhen altering sharded tables - Use
is_alter_on_replicated_table=Truewhen altering non-sharded replicated tables
Testing
Delete entry from infi_clickhouse_orm_migrations table to re-run a migration.
More from posthog/posthog
implementing-agent-modes
Guidelines to create/update a new mode for PostHog AI agent. Modes are a way to limit what tools, prompts, and prompt injections are applied and under what conditions. Achieve better results using your plan mode.
711hogli
>
106react-doctor
Diagnose and fix React codebase health issues. Use when reviewing React code, fixing performance problems, auditing security, or improving code quality.
105survey-sdk-audit
Audit PostHog survey SDK features and version requirements
95setup-web-tests
Set up Python test environment in Claude Code for web where flox is unavailable. Use when you need to run backend tests and `uv sync` fails due to Python version mismatch.
93ingestion-pipeline-doctor-nodejs
>
69