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.

feat(ml/replay): Repair sharded_session_replay_features table (#58225)

Nicholas Waltzffbd74bbd577
diff --git a/posthog/clickhouse/migrations/0254_repair_session_replay_features_unique_columns.py b/posthog/clickhouse/migrations/0254_repair_session_replay_features_unique_columns.py
new file mode 100644
index 000000000000..95820be3b7f9
--- /dev/null
+++ b/posthog/clickhouse/migrations/0254_repair_session_replay_features_unique_columns.py
@@ -0,0 +1,18 @@
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+from posthog.session_recordings.sql.session_replay_feature_sql import UNIQ_COMBINED_PRECISION
+
+REPAIR_SQL = f"""
+ALTER TABLE sharded_session_replay_features
+ ADD COLUMN IF NOT EXISTS unique_url_count AggregateFunction(uniqCombined({UNIQ_COMBINED_PRECISION}), String),
+ ADD COLUMN IF NOT EXISTS unique_click_target_count AggregateFunction(uniqCombined({UNIQ_COMBINED_PRECISION}), Int64)
+"""
+
+operations = [
+ run_sql_with_exceptions(
+ REPAIR_SQL,
+ node_roles=[NodeRole.AUX],
+ sharded=True,
+ is_alter_on_replicated_table=True,
+ ),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index 9f0f72385bb4..fdaaaf21bcb1 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0253_drop_dead_msk_kafka_tables
+0254_repair_session_replay_features_unique_columns
\ No newline at end of file