Skip to content

: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.

fix(ml/replay): run session replay features migration on aux cluster (#58144)

posthog[bot]ea29fd8014dd
diff --git a/posthog/clickhouse/migrations/0252_extend_session_replay_features.py b/posthog/clickhouse/migrations/0252_extend_session_replay_features.py
index 0d5bc7103f4a..ca2d9cbf78ef 100644
--- a/posthog/clickhouse/migrations/0252_extend_session_replay_features.py
+++ b/posthog/clickhouse/migrations/0252_extend_session_replay_features.py
@@ -73,20 +73,20 @@ operations = [
# 2. ALTER the sharded source-of-truth table in place (it holds the actual data).
run_sql_with_exceptions(
_alter_sharded(),
- node_roles=[NodeRole.DATA],
+ node_roles=[NodeRole.AUX],
sharded=True,
is_alter_on_replicated_table=True,
),
# 3. Drop and recreate the Distributed read/write tables. They have no data
run_sql_with_exceptions(
"DROP TABLE IF EXISTS session_replay_features",
- node_roles=[NodeRole.DATA],
+ node_roles=[NodeRole.AUX],
sharded=False,
is_alter_on_replicated_table=False,
),
run_sql_with_exceptions(
DISTRIBUTED_SESSION_REPLAY_FEATURES_TABLE_SQL(on_cluster=False),
- node_roles=[NodeRole.DATA],
+ node_roles=[NodeRole.AUX],
),
run_sql_with_exceptions(
"DROP TABLE IF EXISTS writable_session_replay_features",
diff --git a/posthog/clickhouse/test/test_migrations.py b/posthog/clickhouse/test/test_migrations.py
index 934df2bec00e..468f4c5f79de 100644
--- a/posthog/clickhouse/test/test_migrations.py
+++ b/posthog/clickhouse/test/test_migrations.py
@@ -18,6 +18,17 @@ MIGRATIONS_PACKAGE_NAME = "posthog.clickhouse.migrations"
# `operations` lists can be cloud-gated; re-evaluate them under each prod-shaped value plus
# the unset default so gated branches don't silently bypass the guard.
CLOUD_DEPLOYMENTS_TO_CHECK = ("", "US", "EU", "DEV")
+# Cluster roles that host actual replicated MergeTree data — i.e. where sharded data tables
+# and non-sharded replicated tables live. ALTER TABLE on those tables must target exactly
+# one of these roles, never an ingestion / coordinator / shuffler role. The main cluster's
+# data role is `DATA`; satellite clusters expose their own data role.
+DATA_BEARING_NODE_ROLES: set[NodeRole] = {
+ NodeRole.DATA,
+ NodeRole.AI_EVENTS,
+ NodeRole.AUX,
+ NodeRole.OPS,
+ NodeRole.SESSIONS,
+}
class TestUniqueMigrationPrefixes(TestCase):
@@ -121,11 +132,19 @@ class TestUniqueMigrationPrefixes(TestCase):
if is_alter_on_replicated_table is None:
errors.append("is_alter_on_replicated_table parameter must be explicitly specified for ALTER TABLE queries")
- if sharded and node_roles != [NodeRole.DATA]:
- errors.append("ALTER TABLE on sharded tables must have node_role=NodeRole.DATA")
+ allowed_roles_label = "one of " + ", ".join(
+ f"NodeRole.{r.name}" for r in sorted(DATA_BEARING_NODE_ROLES, key=lambda r: r.name)
+ )
+
+ if sharded and (len(node_roles) != 1 or node_roles[0] not in DATA_BEARING_NODE_ROLES):
+ errors.append(f"ALTER TABLE on sharded tables must have node_role={allowed_roles_label}")
- if not sharded and is_alter_on_replicated_table and set(node_roles) != {NodeRole.DATA}:
- errors.append("ALTER TABLE on non-sharded tables must have node_role=NodeRole.DATA")
+ if (
+ not sharded
+ and is_alter_on_replicated_table
+ and (len(node_roles) != 1 or node_roles[0] not in DATA_BEARING_NODE_ROLES)
+ ):
+ errors.append(f"ALTER TABLE on non-sharded tables must have node_role={allowed_roles_label}")
return errors