:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(tests): skip ON CLUSTER DDL on the single-node test ClickHouse (#69431)
Paul D'Ambra90bbadbbd085
diff --git a/posthog/clickhouse/cluster.py b/posthog/clickhouse/cluster.pyindex 57898c374754..422a3852b5f1 100644--- a/posthog/clickhouse/cluster.py+++ b/posthog/clickhouse/cluster.py@@ -18,7 +18,7 @@ from clickhouse_pool import ChPoolfrom posthog import settingsfrom posthog.clickhouse.client.connection import NodeRole, Workload, _make_ch_pool, default_clientfrom posthog.settings import CLICKHOUSE_PER_TEAM_SETTINGS-from posthog.settings.data_stores import CLICKHOUSE_CLUSTER+from posthog.settings.data_stores import CLICKHOUSE_CLUSTER, TESTclass _LazyDagsterLogger:@@ -44,7 +44,14 @@ logger = _LazyDagsterLogger()def ON_CLUSTER_CLAUSE(on_cluster=True):- return f"ON CLUSTER '{CLICKHOUSE_CLUSTER}'" if on_cluster else ""+ # The test ClickHouse is a single node: ON CLUSTER only adds distributed-DDL keeper+ # round-trips (tens of ms per statement) without changing the outcome, and tests issue+ # DDL in bulk (session-start CREATEs, per-test TRUNCATEs), so render no clause there.+ # If a call site ever needs to exercise real ON CLUSTER SQL under TEST, thread an+ # allow-in-test flag through here.+ if on_cluster and not TEST:+ return f"ON CLUSTER '{CLICKHOUSE_CLUSTER}'"+ return ""# Smoke-test only: when migrating against the multinode docker-compose stackdiff --git a/posthog/clickhouse/dead_letter_queue.py b/posthog/clickhouse/dead_letter_queue.pyindex 7d89d514c907..ce54ab765eb0 100644--- a/posthog/clickhouse/dead_letter_queue.py+++ b/posthog/clickhouse/dead_letter_queue.py@@ -3,7 +3,7 @@ from posthog.clickhouse.indexes import index_by_kafka_timestampfrom posthog.clickhouse.kafka_engine import KAFKA_COLUMNS, kafka_engine, ttl_periodfrom posthog.clickhouse.table_engines import Distributed, ReplacingMergeTreefrom posthog.kafka_client.topics import KAFKA_DEAD_LETTER_QUEUE-from posthog.settings import CLICKHOUSE_CLUSTER, CLICKHOUSE_DATABASE+from posthog.settings import CLICKHOUSE_DATABASEfrom posthog.settings.data_stores import CLICKHOUSE_SINGLE_SHARD_CLUSTER# We pipe our Kafka dead letter queue into CH for easier analysis and longer retention@@ -138,8 +138,6 @@ SELECTnow()"""-TRUNCATE_DEAD_LETTER_QUEUE_TABLE_SQL = (- f"TRUNCATE TABLE IF EXISTS {DEAD_LETTER_QUEUE_TABLE} ON CLUSTER '{CLICKHOUSE_CLUSTER}'"-)+TRUNCATE_DEAD_LETTER_QUEUE_TABLE_SQL = f"TRUNCATE TABLE IF EXISTS {DEAD_LETTER_QUEUE_TABLE} {ON_CLUSTER_CLAUSE()}"DROP_KAFKA_DEAD_LETTER_QUEUE_TABLE_SQL = f"DROP TABLE IF EXISTS kafka_{DEAD_LETTER_QUEUE_TABLE}"DROP_DEAD_LETTER_QUEUE_MV_TABLE_SQL = f"DROP TABLE IF EXISTS {DEAD_LETTER_QUEUE_TABLE}_mv"diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex aed0eb567d00..2d81e57b97d2 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -2,7 +2,7 @@# name: test_create_kafka_events_with_disabled_protobuf'''- CREATE TABLE IF NOT EXISTS kafka_events_json ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_events_json(uuid UUID,event VARCHAR,@@ -157,7 +157,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_error_tracking_issue_fingerprint_overrides]'''- CREATE TABLE IF NOT EXISTS kafka_error_tracking_issue_fingerprint_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_error_tracking_issue_fingerprint_overrides(team_id Int64,fingerprint VARCHAR,@@ -172,7 +172,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_events_dead_letter_queue]'''- CREATE TABLE IF NOT EXISTS kafka_events_dead_letter_queue ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_events_dead_letter_queue(id UUID,event_uuid UUID,@@ -198,7 +198,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_events_json]'''- CREATE TABLE IF NOT EXISTS kafka_events_json ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_events_json(uuid UUID,event VARCHAR,@@ -245,7 +245,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_groups]'''- CREATE TABLE IF NOT EXISTS kafka_groups ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_groups(group_type_index UInt8,group_key VARCHAR,@@ -348,7 +348,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_log_entries]'''- CREATE TABLE IF NOT EXISTS kafka_log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_log_entries(team_id UInt64,-- The name of the service or product that generated the logs.@@ -404,7 +404,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_performance_events]'''- CREATE TABLE IF NOT EXISTS kafka_performance_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_performance_events(uuid UUID,session_id String,@@ -461,7 +461,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_person]'''- CREATE TABLE IF NOT EXISTS kafka_person ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person(id UUID,created_at DateTime64,@@ -479,7 +479,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_person_distinct_id2]'''- CREATE TABLE IF NOT EXISTS kafka_person_distinct_id2 ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person_distinct_id2(team_id Int64,distinct_id VARCHAR,@@ -494,7 +494,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_person_distinct_id]'''- CREATE TABLE IF NOT EXISTS kafka_person_distinct_id ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person_distinct_id(distinct_id VARCHAR,person_id UUID,@@ -508,7 +508,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_person_distinct_id_overrides]'''- CREATE TABLE IF NOT EXISTS kafka_person_distinct_id_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person_distinct_id_overrides(team_id Int64,distinct_id VARCHAR,@@ -524,7 +524,7 @@'''CREATE TABLE IF NOT EXISTS `posthog_test`.`kafka_person_overrides`- ON CLUSTER 'posthog'+ENGINE = Kafka('kafka:9092', -- Kafka hosts@@ -555,7 +555,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_plugin_log_entries]'''- CREATE TABLE IF NOT EXISTS kafka_plugin_log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_plugin_log_entries(id UUID,team_id Int64,@@ -627,7 +627,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_session_replay_events]'''- CREATE TABLE IF NOT EXISTS kafka_session_replay_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_session_replay_events(session_id VARCHAR,team_id Int64,@@ -662,7 +662,7 @@# name: test_create_kafka_table_with_different_kafka_host[kafka_session_replay_features]'''- CREATE TABLE IF NOT EXISTS kafka_session_replay_features ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_session_replay_features(session_id VARCHAR,team_id Int64,@@ -1037,7 +1037,7 @@# name: test_create_table_query[channel_definition]'''- CREATE TABLE IF NOT EXISTS channel_definition ON CLUSTER 'posthog' (+ CREATE TABLE IF NOT EXISTS channel_definition (domain String NOT NULL,kind String NOT NULL,domain_type String NULL,@@ -1080,7 +1080,7 @@# name: test_create_table_query[cohortpeople]'''- CREATE TABLE IF NOT EXISTS cohortpeople ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS cohortpeople(person_id UUID,cohort_id Int64,@@ -1266,7 +1266,7 @@# name: test_create_table_query[distributed_system_processes]'''- CREATE TABLE IF NOT EXISTS distributed_system_processes ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS distributed_system_processesENGINE = Distributed(posthog, system, processes)SETTINGS skip_unavailable_shards=1@@ -1337,7 +1337,7 @@# name: test_create_table_query[error_tracking_issue_fingerprint_overrides]'''- CREATE TABLE IF NOT EXISTS error_tracking_issue_fingerprint_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS error_tracking_issue_fingerprint_overrides(team_id Int64,fingerprint VARCHAR,@@ -1362,7 +1362,7 @@# name: test_create_table_query[error_tracking_issue_fingerprint_overrides_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS error_tracking_issue_fingerprint_overrides_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS error_tracking_issue_fingerprint_overrides_mvTO writable_error_tracking_issue_fingerprint_overridesAS SELECTteam_id,@@ -1381,7 +1381,7 @@# name: test_create_table_query[events]'''- CREATE TABLE IF NOT EXISTS events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS events(uuid UUID,event VARCHAR,@@ -1443,7 +1443,7 @@# name: test_create_table_query[events_dead_letter_queue]'''- CREATE TABLE IF NOT EXISTS events_dead_letter_queue ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS events_dead_letter_queue(id UUID,event_uuid UUID,@@ -1478,7 +1478,7 @@# name: test_create_table_query[events_dead_letter_queue_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS events_dead_letter_queue_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS events_dead_letter_queue_mvTO posthog_test.writable_events_dead_letter_queueAS SELECTid,@@ -1631,7 +1631,7 @@# name: test_create_table_query[exchange_rate]'''- CREATE TABLE IF NOT EXISTS `posthog_test`.`exchange_rate` ON CLUSTER 'posthog' (+ CREATE TABLE IF NOT EXISTS `posthog_test`.`exchange_rate` (currency String,date Date,rate Decimal64(10),@@ -1702,7 +1702,7 @@# name: test_create_table_query[groups]'''- CREATE TABLE IF NOT EXISTS groups ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS groups(group_type_index UInt8,group_key VARCHAR,@@ -1722,7 +1722,7 @@# name: test_create_table_query[groups_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS groups_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS groups_mvTO writable_groupsAS SELECTgroup_type_index,@@ -2133,7 +2133,7 @@# name: test_create_table_query[kafka_error_tracking_issue_fingerprint_overrides]'''- CREATE TABLE IF NOT EXISTS kafka_error_tracking_issue_fingerprint_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_error_tracking_issue_fingerprint_overrides(team_id Int64,fingerprint VARCHAR,@@ -2148,7 +2148,7 @@# name: test_create_table_query[kafka_events_dead_letter_queue]'''- CREATE TABLE IF NOT EXISTS kafka_events_dead_letter_queue ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_events_dead_letter_queue(id UUID,event_uuid UUID,@@ -2174,7 +2174,7 @@# name: test_create_table_query[kafka_events_json]'''- CREATE TABLE IF NOT EXISTS kafka_events_json ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_events_json(uuid UUID,event VARCHAR,@@ -2221,7 +2221,7 @@# name: test_create_table_query[kafka_groups]'''- CREATE TABLE IF NOT EXISTS kafka_groups ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_groups(group_type_index UInt8,group_key VARCHAR,@@ -2324,7 +2324,7 @@# name: test_create_table_query[kafka_log_entries]'''- CREATE TABLE IF NOT EXISTS kafka_log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_log_entries(team_id UInt64,-- The name of the service or product that generated the logs.@@ -2380,7 +2380,7 @@# name: test_create_table_query[kafka_performance_events]'''- CREATE TABLE IF NOT EXISTS kafka_performance_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_performance_events(uuid UUID,session_id String,@@ -2437,7 +2437,7 @@# name: test_create_table_query[kafka_person]'''- CREATE TABLE IF NOT EXISTS kafka_person ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person(id UUID,created_at DateTime64,@@ -2455,7 +2455,7 @@# name: test_create_table_query[kafka_person_distinct_id2]'''- CREATE TABLE IF NOT EXISTS kafka_person_distinct_id2 ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person_distinct_id2(team_id Int64,distinct_id VARCHAR,@@ -2470,7 +2470,7 @@# name: test_create_table_query[kafka_person_distinct_id]'''- CREATE TABLE IF NOT EXISTS kafka_person_distinct_id ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person_distinct_id(distinct_id VARCHAR,person_id UUID,@@ -2484,7 +2484,7 @@# name: test_create_table_query[kafka_person_distinct_id_overrides]'''- CREATE TABLE IF NOT EXISTS kafka_person_distinct_id_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_person_distinct_id_overrides(team_id Int64,distinct_id VARCHAR,@@ -2500,7 +2500,7 @@'''CREATE TABLE IF NOT EXISTS `posthog_test`.`kafka_person_overrides`- ON CLUSTER 'posthog'+ENGINE = Kafka('kafka:9092', -- Kafka hosts@@ -2531,7 +2531,7 @@# name: test_create_table_query[kafka_plugin_log_entries]'''- CREATE TABLE IF NOT EXISTS kafka_plugin_log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_plugin_log_entries(id UUID,team_id Int64,@@ -2603,7 +2603,7 @@# name: test_create_table_query[kafka_session_replay_events]'''- CREATE TABLE IF NOT EXISTS kafka_session_replay_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_session_replay_events(session_id VARCHAR,team_id Int64,@@ -2638,7 +2638,7 @@# name: test_create_table_query[kafka_session_replay_features]'''- CREATE TABLE IF NOT EXISTS kafka_session_replay_features ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS kafka_session_replay_features(session_id VARCHAR,team_id Int64,@@ -2830,7 +2830,7 @@# name: test_create_table_query[log_entries]'''- CREATE TABLE IF NOT EXISTS log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS log_entries(team_id UInt64,-- The name of the service or product that generated the logs.@@ -3952,7 +3952,7 @@# name: test_create_table_query[performance_events]'''- CREATE TABLE IF NOT EXISTS performance_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS performance_events(uuid UUID,session_id String,@@ -4025,7 +4025,7 @@# name: test_create_table_query[person]'''- CREATE TABLE IF NOT EXISTS person ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person(id UUID,created_at DateTime64,@@ -4051,7 +4051,7 @@# name: test_create_table_query[person_distinct_id2]'''- CREATE TABLE IF NOT EXISTS person_distinct_id2 ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_distinct_id2(team_id Int64,distinct_id VARCHAR,@@ -4076,7 +4076,7 @@# name: test_create_table_query[person_distinct_id2_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS person_distinct_id2_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS person_distinct_id2_mvTO writable_person_distinct_id2AS SELECTteam_id,@@ -4094,7 +4094,7 @@# name: test_create_table_query[person_distinct_id]'''- CREATE TABLE IF NOT EXISTS person_distinct_id ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_distinct_id(distinct_id VARCHAR,person_id UUID,@@ -4130,7 +4130,7 @@# name: test_create_table_query[person_distinct_id_overrides]'''- CREATE TABLE IF NOT EXISTS person_distinct_id_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_distinct_id_overrides(team_id Int64,distinct_id VARCHAR,@@ -4174,7 +4174,7 @@# name: test_create_table_query[person_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS person_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS person_mvTO writable_personAS SELECTid,@@ -4195,7 +4195,7 @@'''CREATE TABLE IF NOT EXISTS `posthog_test`.`person_overrides`- ON CLUSTER 'posthog' (+ (team_id INT NOT NULL,-- When we merge two people `old_person_id` and `override_person_id`, we@@ -4259,7 +4259,7 @@'''CREATE MATERIALIZED VIEW IF NOT EXISTS `posthog_test`.`person_overrides_mv`- ON CLUSTER 'posthog'+TO `posthog_test`.`person_overrides`AS SELECTteam_id,@@ -4278,7 +4278,7 @@# name: test_create_table_query[person_static_cohort]'''- CREATE TABLE IF NOT EXISTS person_static_cohort ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_static_cohort(id UUID,person_id UUID,@@ -4297,7 +4297,7 @@# name: test_create_table_query[pg_embeddings]'''- CREATE TABLE IF NOT EXISTS pg_embeddings ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS pg_embeddings(domain String,team_id Int64,@@ -4318,7 +4318,7 @@# name: test_create_table_query[plugin_log_entries]'''- CREATE TABLE IF NOT EXISTS plugin_log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS plugin_log_entries(id UUID,team_id Int64,@@ -4343,7 +4343,7 @@# name: test_create_table_query[plugin_log_entries_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS plugin_log_entries_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS plugin_log_entries_mvTO writable_plugin_log_entriesAS SELECTid,@@ -4879,7 +4879,7 @@# name: test_create_table_query[raw_sessions]'''- CREATE TABLE IF NOT EXISTS raw_sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS raw_sessions(team_id Int64,session_id_v7 UInt128, -- integer representation of a uuidv7@@ -5541,7 +5541,7 @@# name: test_create_table_query[session_replay_events_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS session_replay_events_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS session_replay_events_mvTO posthog_test.writable_session_replay_events (`session_id` String, `team_id` Int64, `distinct_id` String,`min_first_timestamp` DateTime64(6, 'UTC'),@@ -5691,7 +5691,7 @@# name: test_create_table_query[session_replay_features_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS session_replay_features_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS session_replay_features_mvTO posthog_test.writable_session_replay_featuresAS SELECTsession_id,@@ -5770,7 +5770,7 @@# name: test_create_table_query[sessions]'''- CREATE TABLE IF NOT EXISTS sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sessions(-- part of order by so will aggregate correctlysession_id VARCHAR,@@ -5826,7 +5826,7 @@# name: test_create_table_query[sessions_mv]'''- CREATE MATERIALIZED VIEW IF NOT EXISTS sessions_mv ON CLUSTER 'posthog'+ CREATE MATERIALIZED VIEW IF NOT EXISTS sessions_mvTO posthog_test.writable_sessionsAS@@ -6022,7 +6022,7 @@# name: test_create_table_query[sharded_app_metrics]'''- CREATE TABLE IF NOT EXISTS sharded_app_metrics ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_app_metrics(team_id Int64,timestamp DateTime64(6, 'UTC'),@@ -6104,7 +6104,7 @@# name: test_create_table_query[sharded_events]'''- CREATE TABLE IF NOT EXISTS sharded_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_events(uuid UUID,event VARCHAR,@@ -6490,7 +6490,7 @@# name: test_create_table_query[sharded_performance_events]'''- CREATE TABLE IF NOT EXISTS sharded_performance_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_performance_events(uuid UUID,session_id String,@@ -6860,7 +6860,7 @@# name: test_create_table_query[sharded_raw_sessions]'''- CREATE TABLE IF NOT EXISTS sharded_raw_sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_raw_sessions(team_id Int64,session_id_v7 UInt128, -- integer representation of a uuidv7@@ -7079,7 +7079,7 @@# name: test_create_table_query[sharded_session_replay_events]'''- CREATE TABLE IF NOT EXISTS sharded_session_replay_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_session_replay_events(-- part of order by so will aggregate correctlysession_id VARCHAR,@@ -7154,7 +7154,7 @@# name: test_create_table_query[sharded_session_replay_features]'''- CREATE TABLE IF NOT EXISTS sharded_session_replay_features ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_session_replay_features(session_id VARCHAR,team_id Int64,@@ -7235,7 +7235,7 @@# name: test_create_table_query[sharded_sessions]'''- CREATE TABLE IF NOT EXISTS sharded_sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_sessions(-- part of order by so will aggregate correctlysession_id VARCHAR,@@ -8203,7 +8203,7 @@# name: test_create_table_query[writable_events]'''- CREATE TABLE IF NOT EXISTS writable_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS writable_events(uuid UUID,event VARCHAR,@@ -8251,7 +8251,7 @@# name: test_create_table_query[writable_events_dead_letter_queue]'''- CREATE TABLE IF NOT EXISTS writable_events_dead_letter_queue ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS writable_events_dead_letter_queue(id UUID,event_uuid UUID,@@ -8683,7 +8683,7 @@# name: test_create_table_query[writable_raw_sessions]'''- CREATE TABLE IF NOT EXISTS writable_raw_sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS writable_raw_sessions(team_id Int64,session_id_v7 UInt128, -- integer representation of a uuidv7@@ -9016,7 +9016,7 @@# name: test_create_table_query[writable_sessions]'''- CREATE TABLE IF NOT EXISTS writable_sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS writable_sessions(-- part of order by so will aggregate correctlysession_id VARCHAR,@@ -9090,7 +9090,7 @@# name: test_create_table_query[writeable_performance_events]'''- CREATE TABLE IF NOT EXISTS writeable_performance_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS writeable_performance_events(uuid UUID,session_id String,@@ -9151,7 +9151,7 @@# name: test_create_table_query_replicated_and_storage[channel_definition]'''- CREATE TABLE IF NOT EXISTS channel_definition ON CLUSTER 'posthog' (+ CREATE TABLE IF NOT EXISTS channel_definition (domain String NOT NULL,kind String NOT NULL,domain_type String NULL,@@ -9180,7 +9180,7 @@# name: test_create_table_query_replicated_and_storage[cohortpeople]'''- CREATE TABLE IF NOT EXISTS cohortpeople ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS cohortpeople(person_id UUID,cohort_id Int64,@@ -9209,7 +9209,7 @@# name: test_create_table_query_replicated_and_storage[error_tracking_issue_fingerprint_overrides]'''- CREATE TABLE IF NOT EXISTS error_tracking_issue_fingerprint_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS error_tracking_issue_fingerprint_overrides(team_id Int64,fingerprint VARCHAR,@@ -9234,7 +9234,7 @@# name: test_create_table_query_replicated_and_storage[events_dead_letter_queue]'''- CREATE TABLE IF NOT EXISTS events_dead_letter_queue ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS events_dead_letter_queue(id UUID,event_uuid UUID,@@ -9269,7 +9269,7 @@# name: test_create_table_query_replicated_and_storage[exchange_rate]'''- CREATE TABLE IF NOT EXISTS `posthog_test`.`exchange_rate` ON CLUSTER 'posthog' (+ CREATE TABLE IF NOT EXISTS `posthog_test`.`exchange_rate` (currency String,date Date,rate Decimal64(10),@@ -9282,7 +9282,7 @@# name: test_create_table_query_replicated_and_storage[groups]'''- CREATE TABLE IF NOT EXISTS groups ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS groups(group_type_index UInt8,group_key VARCHAR,@@ -9463,7 +9463,7 @@# name: test_create_table_query_replicated_and_storage[log_entries]'''- CREATE TABLE IF NOT EXISTS log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS log_entries(team_id UInt64,-- The name of the service or product that generated the logs.@@ -9925,7 +9925,7 @@# name: test_create_table_query_replicated_and_storage[person]'''- CREATE TABLE IF NOT EXISTS person ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person(id UUID,created_at DateTime64,@@ -9951,7 +9951,7 @@# name: test_create_table_query_replicated_and_storage[person_distinct_id2]'''- CREATE TABLE IF NOT EXISTS person_distinct_id2 ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_distinct_id2(team_id Int64,distinct_id VARCHAR,@@ -9976,7 +9976,7 @@# name: test_create_table_query_replicated_and_storage[person_distinct_id]'''- CREATE TABLE IF NOT EXISTS person_distinct_id ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_distinct_id(distinct_id VARCHAR,person_id UUID,@@ -9996,7 +9996,7 @@# name: test_create_table_query_replicated_and_storage[person_distinct_id_overrides]'''- CREATE TABLE IF NOT EXISTS person_distinct_id_overrides ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_distinct_id_overrides(team_id Int64,distinct_id VARCHAR,@@ -10022,7 +10022,7 @@'''CREATE TABLE IF NOT EXISTS `posthog_test`.`person_overrides`- ON CLUSTER 'posthog' (+ (team_id INT NOT NULL,-- When we merge two people `old_person_id` and `override_person_id`, we@@ -10085,7 +10085,7 @@# name: test_create_table_query_replicated_and_storage[person_static_cohort]'''- CREATE TABLE IF NOT EXISTS person_static_cohort ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS person_static_cohort(id UUID,person_id UUID,@@ -10104,7 +10104,7 @@# name: test_create_table_query_replicated_and_storage[pg_embeddings]'''- CREATE TABLE IF NOT EXISTS pg_embeddings ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS pg_embeddings(domain String,team_id Int64,@@ -10125,7 +10125,7 @@# name: test_create_table_query_replicated_and_storage[plugin_log_entries]'''- CREATE TABLE IF NOT EXISTS plugin_log_entries ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS plugin_log_entries(id UUID,team_id Int64,@@ -10469,7 +10469,7 @@# name: test_create_table_query_replicated_and_storage[sharded_app_metrics]'''- CREATE TABLE IF NOT EXISTS sharded_app_metrics ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_app_metrics(team_id Int64,timestamp DateTime64(6, 'UTC'),@@ -10551,7 +10551,7 @@# name: test_create_table_query_replicated_and_storage[sharded_events]'''- CREATE TABLE IF NOT EXISTS sharded_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_events(uuid UUID,event VARCHAR,@@ -10937,7 +10937,7 @@# name: test_create_table_query_replicated_and_storage[sharded_performance_events]'''- CREATE TABLE IF NOT EXISTS sharded_performance_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_performance_events(uuid UUID,session_id String,@@ -11307,7 +11307,7 @@# name: test_create_table_query_replicated_and_storage[sharded_raw_sessions]'''- CREATE TABLE IF NOT EXISTS sharded_raw_sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_raw_sessions(team_id Int64,session_id_v7 UInt128, -- integer representation of a uuidv7@@ -11526,7 +11526,7 @@# name: test_create_table_query_replicated_and_storage[sharded_session_replay_events]'''- CREATE TABLE IF NOT EXISTS sharded_session_replay_events ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_session_replay_events(-- part of order by so will aggregate correctlysession_id VARCHAR,@@ -11601,7 +11601,7 @@# name: test_create_table_query_replicated_and_storage[sharded_session_replay_features]'''- CREATE TABLE IF NOT EXISTS sharded_session_replay_features ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_session_replay_features(session_id VARCHAR,team_id Int64,@@ -11682,7 +11682,7 @@# name: test_create_table_query_replicated_and_storage[sharded_sessions]'''- CREATE TABLE IF NOT EXISTS sharded_sessions ON CLUSTER 'posthog'+ CREATE TABLE IF NOT EXISTS sharded_sessions(-- part of order by so will aggregate correctlysession_id VARCHAR,diff --git a/posthog/models/channel_type/sql.py b/posthog/models/channel_type/sql.pyindex 1891da175e2e..7e2a67b6b454 100644--- a/posthog/models/channel_type/sql.py+++ b/posthog/models/channel_type/sql.py@@ -32,7 +32,7 @@ DROP_CHANNEL_DEFINITION_TABLE_SQL = (TRUNCATE_CHANNEL_DEFINITION_TABLE_SQL = (- f"TRUNCATE TABLE IF EXISTS {CHANNEL_DEFINITION_TABLE_NAME} ON CLUSTER '{CLICKHOUSE_CLUSTER}'"+ f"TRUNCATE TABLE IF EXISTS {CHANNEL_DEFINITION_TABLE_NAME} {ON_CLUSTER_CLAUSE()}")with open(os.path.join(os.path.dirname(__file__), "channel_definitions.json")) as f:diff --git a/posthog/models/duplicate_events/sql.py b/posthog/models/duplicate_events/sql.pyindex a76dde863e85..a70dd07ae3ad 100644--- a/posthog/models/duplicate_events/sql.py+++ b/posthog/models/duplicate_events/sql.py@@ -1,5 +1,6 @@from django.conf import settings+from posthog.clickhouse.cluster import ON_CLUSTER_CLAUSEfrom posthog.clickhouse.indexes import index_by_kafka_timestampfrom posthog.clickhouse.kafka_engine import KAFKA_COLUMNS_WITH_PARTITION, kafka_enginefrom posthog.clickhouse.table_engines import Distributed, MergeTreeEngine@@ -148,4 +149,4 @@ def DROP_DUPLICATE_EVENTS_MV_SQL():def TRUNCATE_DUPLICATE_EVENTS_TABLE_SQL():- return f"TRUNCATE TABLE IF EXISTS {DUPLICATE_EVENTS_TABLE} ON CLUSTER '{settings.CLICKHOUSE_CLUSTER}'"+ return f"TRUNCATE TABLE IF EXISTS {DUPLICATE_EVENTS_TABLE} {ON_CLUSTER_CLAUSE()}"diff --git a/posthog/models/group/sql.py b/posthog/models/group/sql.pyindex 7874edede2d6..53a04425ebac 100644--- a/posthog/models/group/sql.py+++ b/posthog/models/group/sql.py@@ -15,7 +15,7 @@ DROP_GROUPS_TABLE_SQL = f"DROP TABLE {GROUPS_TABLE} ON CLUSTER '{CLICKHOUSE_CLUSDROP_GROUPS_TABLE_MV_SQL = f"DROP TABLE IF EXISTS {GROUPS_TABLE_MV}"DROP_KAFKA_GROUPS_TABLE_SQL = f"DROP TABLE IF EXISTS {KAFKA_GROUPS_TABLE}"-TRUNCATE_GROUPS_TABLE_SQL = f"TRUNCATE TABLE IF EXISTS {GROUPS_TABLE} ON CLUSTER '{CLICKHOUSE_CLUSTER}'"+TRUNCATE_GROUPS_TABLE_SQL = f"TRUNCATE TABLE IF EXISTS {GROUPS_TABLE} {ON_CLUSTER_CLAUSE()}"GROUPS_TABLE_BASE_SQL = """CREATE TABLE IF NOT EXISTS {table_name} {on_cluster_clause}diff --git a/posthog/models/person/sql.py b/posthog/models/person/sql.pyindex e3da80ced03d..d67ae5c758bd 100644--- a/posthog/models/person/sql.py+++ b/posthog/models/person/sql.py@@ -467,7 +467,7 @@ def PERSON_DISTINCT_ID_OVERRIDES_WRITABLE_TABLE_SQL():def TRUNCATE_PERSON_DISTINCT_ID_OVERRIDES_TABLE_SQL():- return f"TRUNCATE TABLE IF EXISTS {PERSON_DISTINCT_ID_OVERRIDES_TABLE} ON CLUSTER '{settings.CLICKHOUSE_CLUSTER}'"+ return f"TRUNCATE TABLE IF EXISTS {PERSON_DISTINCT_ID_OVERRIDES_TABLE} {ON_CLUSTER_CLAUSE()}"# WarpStream Kafka engine tables for person_distinct_id_overrides (coexist alongside MSK tables, same target)@@ -535,7 +535,7 @@ def PERSON_STATIC_COHORT_TABLE_SQL(on_cluster=True):def TRUNCATE_PERSON_STATIC_COHORT_TABLE_SQL():- return f"TRUNCATE TABLE IF EXISTS {PERSON_STATIC_COHORT_TABLE} ON CLUSTER '{settings.CLICKHOUSE_CLUSTER}'"+ return f"TRUNCATE TABLE IF EXISTS {PERSON_STATIC_COHORT_TABLE} {ON_CLUSTER_CLAUSE()}"INSERT_PERSON_STATIC_COHORT = (diff --git a/products/cohorts/backend/models/sql.py b/products/cohorts/backend/models/sql.pyindex ed055a51c658..fb9c0cf67812 100644--- a/products/cohorts/backend/models/sql.py+++ b/products/cohorts/backend/models/sql.py@@ -1,7 +1,6 @@from posthog.clickhouse.cluster import ON_CLUSTER_CLAUSEfrom posthog.clickhouse.table_engines import CollapsingMergeTreefrom posthog.models.person.sql import PERSON_STATIC_COHORT_TABLE-from posthog.settings import CLICKHOUSE_CLUSTERCALCULATE_COHORT_PEOPLE_SQL = """SELECT {id_column} FROM ({GET_TEAM_PERSON_DISTINCT_IDS}) WHERE {query}@@ -29,7 +28,7 @@ Order By (team_id, cohort_id, person_id, version)storage_policy="",)-TRUNCATE_COHORTPEOPLE_TABLE_SQL = f"TRUNCATE TABLE IF EXISTS cohortpeople ON CLUSTER '{CLICKHOUSE_CLUSTER}'"+TRUNCATE_COHORTPEOPLE_TABLE_SQL = f"TRUNCATE TABLE IF EXISTS cohortpeople {ON_CLUSTER_CLAUSE()}"GET_COHORT_SIZE_SQL = """SELECT count(DISTINCT person_id)diff --git a/products/error_tracking/backend/embedding.py b/products/error_tracking/backend/embedding.pyindex 4b6af962ca91..e43355081389 100644--- a/products/error_tracking/backend/embedding.py+++ b/products/error_tracking/backend/embedding.py@@ -1,5 +1,6 @@from django.conf import settings+from posthog.clickhouse.cluster import ON_CLUSTER_CLAUSEfrom posthog.clickhouse.indexes import index_by_kafka_timestampfrom posthog.clickhouse.kafka_engine import (CONSUMER_GROUP_DOCUMENT_EMBEDDINGS,@@ -142,9 +143,7 @@ FROM {database}.{kafka_table}def TRUNCATE_DOCUMENT_EMBEDDINGS_TABLE_SQL():- return (- f"TRUNCATE TABLE IF EXISTS {PARTITIONED_SHARDED_DOCUMENT_EMBEDDINGS} ON CLUSTER '{settings.CLICKHOUSE_CLUSTER}'"- )+ return f"TRUNCATE TABLE IF EXISTS {PARTITIONED_SHARDED_DOCUMENT_EMBEDDINGS} {ON_CLUSTER_CLAUSE()}"# Migration helpers for transitioning to partitioned tablesdiff --git a/products/error_tracking/backend/sql.py b/products/error_tracking/backend/sql.pyindex e227c6e055c7..f2cba532db8a 100644--- a/products/error_tracking/backend/sql.py+++ b/products/error_tracking/backend/sql.py@@ -119,7 +119,7 @@ WRITABLE_ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE_SQL = lambda: (def TRUNCATE_ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE_SQL():- return f"TRUNCATE TABLE IF EXISTS {ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE} ON CLUSTER '{settings.CLICKHOUSE_CLUSTER}'"+ return f"TRUNCATE TABLE IF EXISTS {ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE} {ON_CLUSTER_CLAUSE()}"def TRUNCATE_ERROR_TRACKING_FINGERPRINT_ISSUE_STATE_TABLE_SQL():