: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
feat(clickhouse): retain event person mutation payloads on aux (#97215)
Rory Shanksc290f2fbdcb2
diff --git a/docs/internal/clickhouse-deletion-coverage.md b/docs/internal/clickhouse-deletion-coverage.mdindex 465480d4010e..6e3dccc59fd9 100644--- a/docs/internal/clickhouse-deletion-coverage.md+++ b/docs/internal/clickhouse-deletion-coverage.md@@ -96,6 +96,8 @@ Each is a decision that erasure may lag by the retention window.- `sharded_events_recent` — a transient mirror of the last few days of events, 7-day TTL keyed on `inserted_at`. It partitions by day with `ttl_only_drop_parts = 1`, so a part drops only once its newest row expires: the real worst case is about 8 days plus TTL-merge lag, not a flat 7. Short enough to accept as the erasure bound, and a sweep would race the TTL for little benefit.+- `person_property_mutation_log_data` retains submitted person updates for 30 days from the Kafka message timestamp. It stores only `team_id`, `event_uuid`, `properties`, and `ingested_at`, so person-based sweeps cannot target it directly. Daily partitions drop after their newest row expires, plus TTL-merge lag.+Session recordings, the dead letter queue, and logs are likewise TTL-reclaimed.That decision predates this document; the older `posthog/models/async_deletion/delete_events.py` records it in a comment, but that module is legacy and is not the source of truth here.diff --git a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl b/posthog/clickhouse/hcl/golden/dev/auxiliary.hclindex ab32f650c604..1d74983b5749 100644--- a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl@@ -1004,6 +1004,53 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }++ table "person_property_mutation_log_data" {+ order_by = ["team_id", "event_uuid"]+ partition_by = "toDate(ingested_at)"+ ttl = "ingested_at + toIntervalDay(30)"+ settings = {+ index_granularity = "1024"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.person_property_mutation_log_data"+ replica_name = "{replica}-{shard}"+ version_column = "ingested_at"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hclindex 74292d7233f8..bd46e1e9a6fa 100644--- a/posthog/clickhouse/hcl/golden/dev/data.hcl+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl@@ -2946,6 +2946,26 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }+table "person_static_cohort" {order_by = ["team_id", "cohort_id", "person_id", "id"]settings = {diff --git a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hclindex 3bd51d83ea2d..81a7c5302cfa 100644--- a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl@@ -1048,6 +1048,53 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }++ table "person_property_mutation_log_data" {+ order_by = ["team_id", "event_uuid"]+ partition_by = "toDate(ingested_at)"+ ttl = "ingested_at + toIntervalDay(30)"+ settings = {+ index_granularity = "1024"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.person_property_mutation_log_data"+ replica_name = "{replica}-{shard}"+ version_column = "ingested_at"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hclindex 27ada547203d..3f26bd3fd997 100644--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl@@ -3265,6 +3265,26 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }+table "person_static_cohort" {order_by = ["team_id", "cohort_id", "person_id", "id"]settings = {diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hclindex 4cbeb7b6afc5..475fd7537a95 100644--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl@@ -192,6 +192,45 @@ database "posthog" {}}+ table "kafka_person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ engine "kafka" {+ collection = "warpstream_ingestion"+ topic_list = "clickhouse_events_json"+ group_name = "clickhouse_person_property_mutation_log"+ format = "JSONEachRow"+ skip_broken_messages = 100+ }+ }++ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }+table "query_log_archive" {column "hostname" {type = "LowCardinality(String)"@@ -1002,6 +1041,50 @@ SQLtype = "UInt8"}}++ materialized_view "person_property_mutation_log_mv" {+ to_table = "posthog.person_property_mutation_log"+ query = <<SQL+SELECT+ team_id,+ uuid AS event_uuid,+ concat(+ '{',+ arrayStringConcat(+ arrayMap(+ property -> concat(toJSONString(property.1), ':', property.2),+ arrayFilter(+ property -> property.1 IN ('$set', '$set_once', '$unset'),+ JSONExtractKeysAndValuesRaw(source.properties)+ )+ ),+ ','+ ),+ '}'+ ) AS properties,+ toDateTime(_timestamp, 'UTC') AS ingested_at+FROM kafka_person_property_mutation_log AS source+WHERE+ JSONHas(source.properties, '$set')+OR+ JSONHas(source.properties, '$set_once')+OR+ JSONHas(source.properties, '$unset')+SQL++ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ }}named_collection "msk_cluster" {diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex b5a6d303f538..e8ce34b15585 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -4002,6 +4002,25 @@ database "posthog" {}}+ table "kafka_person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ engine "kafka" {+ collection = "warpstream_ingestion"+ topic_list = "clickhouse_events_json"+ group_name = "clickhouse_person_property_mutation_log"+ format = "JSONEachRow"+ skip_broken_messages = 100+ }+ }+table "kafka_plugin_log_entries" {column "id" {type = "UUID"@@ -7745,6 +7764,53 @@ SQL}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }++ table "person_property_mutation_log_data" {+ order_by = ["team_id", "event_uuid"]+ partition_by = "toDate(ingested_at)"+ ttl = "ingested_at + toIntervalDay(30)"+ settings = {+ index_granularity = "1024"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.person_property_mutation_log_data"+ replica_name = "{replica}-{shard}"+ version_column = "ingested_at"+ }+ }+table "person_static_cohort" {order_by = ["team_id", "cohort_id", "person_id", "id"]settings = {@@ -22294,6 +22360,50 @@ SQL}}+ materialized_view "person_property_mutation_log_mv" {+ to_table = "posthog.person_property_mutation_log"+ query = <<SQL+SELECT+ team_id,+ uuid AS event_uuid,+ concat(+ '{',+ arrayStringConcat(+ arrayMap(+ property -> concat(toJSONString(property.1), ':', property.2),+ arrayFilter(+ property -> property.1 IN ('$set', '$set_once', '$unset'),+ JSONExtractKeysAndValuesRaw(source.properties)+ )+ ),+ ','+ ),+ '}'+ ) AS properties,+ toDateTime(_timestamp, 'UTC') AS ingested_at+FROM kafka_person_property_mutation_log AS source+WHERE+ JSONHas(source.properties, '$set')+OR+ JSONHas(source.properties, '$set_once')+OR+ JSONHas(source.properties, '$unset')+SQL++ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ }+materialized_view "plugin_log_entries_mv" {to_table = "posthog.writable_plugin_log_entries"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hclindex d8bc9a9564e9..b8376144f63d 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl@@ -1004,6 +1004,53 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }++ table "person_property_mutation_log_data" {+ order_by = ["team_id", "event_uuid"]+ partition_by = "toDate(ingested_at)"+ ttl = "ingested_at + toIntervalDay(30)"+ settings = {+ index_granularity = "1024"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.person_property_mutation_log_data"+ replica_name = "{replica}-{shard}"+ version_column = "ingested_at"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hclindex 4063530ea5f5..abef8c2c5af3 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl@@ -3617,6 +3617,26 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }+table "person_static_cohort" {order_by = ["team_id", "cohort_id", "person_id", "id"]settings = {diff --git a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hclindex b196938c48d1..9bf9bf33778d 100644--- a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl@@ -1042,6 +1042,53 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }++ table "person_property_mutation_log_data" {+ order_by = ["team_id", "event_uuid"]+ partition_by = "toDate(ingested_at)"+ ttl = "ingested_at + toIntervalDay(30)"+ settings = {+ index_granularity = "1024"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.person_property_mutation_log_data"+ replica_name = "{replica}-{shard}"+ version_column = "ingested_at"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hclindex 985bb570175e..2186f2572cf6 100644--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl@@ -3406,6 +3406,26 @@ database "posthog" {}}+ table "person_property_mutation_log" {+ column "team_id" {+ type = "Int64"+ }+ column "event_uuid" {+ type = "UUID"+ }+ column "properties" {+ type = "String"+ }+ column "ingested_at" {+ type = "DateTime('UTC')"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }+table "person_static_cohort" {order_by = ["team_id", "cohort_id", "person_id", "id"]settings = {diff --git a/posthog/clickhouse/hcl/manifest.hcl b/posthog/clickhouse/hcl/manifest.hclindex a2e16ab19706..6c88a67e2fe6 100644--- a/posthog/clickhouse/hcl/manifest.hcl+++ b/posthog/clickhouse/hcl/manifest.hcl@@ -75,10 +75,10 @@ role "ai_events" {# hosts the ingestion_warnings store; prod-us adds the Distributed proxy onto the data# cluster. prod goldens are dump-baselined (not live-verifiable here).role "aux" {- env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local"] }- env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/dev"] }- env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-us"] }- env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-eu"] }+ env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local"] }+ env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/dev"] }+ env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-us"] }+ env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-eu"] }}# SESSIONS satellite: the local node runs only the shared query_log_archive path@@ -119,10 +119,10 @@ role "batch_exports" {# columns per env that are added out-of-band and churn constantly, so their goldens# live in PostHog/posthog-cloud-infra (clickhouse/hcl/), not the OSS gate.role "data" {- env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/dev"] }- env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/data/prod", "roles/data/prod-us"] }- env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/prod", "roles/data/prod-eu"] }- env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/sessions_data", "roles/coshared/ai_events_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local"] }+ env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/dev"] }+ env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/data/prod", "roles/data/prod-us"] }+ env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/prod", "roles/data/prod-eu"] }+ env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/ai_events_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local"] }}# INGESTION satellites: the Kafka consumer layer. Each node carries the kafka_* engine@@ -131,7 +131,7 @@ role "data" {# Beyond that they carry only the shared query_log_archive path. Role names are the# hostClusterRole macros migrations target: events, small, medium.role "events" {- env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/coshared/logs_avro_ingest", "roles/coshared/events_json_write", "roles/ingestion_events/local"] }+ env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/coshared/logs_avro_ingest", "roles/coshared/events_json_write", "roles/coshared/person_property_mutations", "roles/ingestion_events/shared", "roles/ingestion_events/local"] }}role "small" {@@ -147,7 +147,7 @@ role "medium" {# and not MULTINODE_CLICKHOUSE. Composed as the deduped union of the local-multi stacks it# hosts, so any name two of those roles declare fails this load instead of drifting.role "all" {- env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/coshared/logs_avro_ingest", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }+ env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/coshared/logs_avro_ingest", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local", "roles/ingestion_events/shared", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }}# role "endpoints" {diff --git a/posthog/clickhouse/hcl/roles/auxiliary/shared/person_property_mutations.hcl b/posthog/clickhouse/hcl/roles/auxiliary/shared/person_property_mutations.hclnew file mode 100644index 000000000000..7864a9eed46d--- /dev/null+++ b/posthog/clickhouse/hcl/roles/auxiliary/shared/person_property_mutations.hcl@@ -0,0 +1,14 @@+database "posthog" {+ table "person_property_mutation_log_data" {+ extend = "_person_property_mutation_log_columns"+ order_by = ["team_id", "event_uuid"]+ partition_by = "toDate(ingested_at)"+ ttl = "ingested_at + toIntervalDay(30)"+ settings = { index_granularity = "1024", ttl_only_drop_parts = "1" }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.person_property_mutation_log_data"+ replica_name = "{replica}-{shard}"+ version_column = "ingested_at"+ }+ }+}diff --git a/posthog/clickhouse/hcl/roles/coshared/person_property_mutations/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/person_property_mutations/tables.hclnew file mode 100644index 000000000000..3d59e8cb80d7--- /dev/null+++ b/posthog/clickhouse/hcl/roles/coshared/person_property_mutations/tables.hcl@@ -0,0 +1,17 @@+database "posthog" {+ table "_person_property_mutation_log_columns" {+ abstract = true+ column "team_id" { type = "Int64" }+ column "event_uuid" { type = "UUID" }+ column "properties" { type = "String" }+ column "ingested_at" { type = "DateTime('UTC')" }+ }+ table "person_property_mutation_log" {+ extend = "_person_property_mutation_log_columns"+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "person_property_mutation_log_data"+ }+ }+}diff --git a/posthog/clickhouse/hcl/roles/ingestion_events/shared/person_property_mutations.hcl b/posthog/clickhouse/hcl/roles/ingestion_events/shared/person_property_mutations.hclnew file mode 100644index 000000000000..5138ccedd118--- /dev/null+++ b/posthog/clickhouse/hcl/roles/ingestion_events/shared/person_property_mutations.hcl@@ -0,0 +1,22 @@+database "posthog" {+ table "kafka_person_property_mutation_log" {+ column "team_id" { type = "Int64" }+ column "uuid" { type = "UUID" }+ column "properties" { type = "String" }+ engine "kafka" {+ collection = "warpstream_ingestion"+ topic_list = "clickhouse_events_json"+ group_name = "clickhouse_person_property_mutation_log"+ format = "JSONEachRow"+ skip_broken_messages = 100+ }+ }+ materialized_view "person_property_mutation_log_mv" {+ to_table = "posthog.person_property_mutation_log"+ query = file("sql/person_property_mutation_log_mv.sql")+ column "team_id" { type = "Int64" }+ column "event_uuid" { type = "UUID" }+ column "properties" { type = "String" }+ column "ingested_at" { type = "DateTime('UTC')" }+ }+}diff --git a/posthog/clickhouse/hcl/roles/ingestion_events/shared/sql/person_property_mutation_log_mv.sql b/posthog/clickhouse/hcl/roles/ingestion_events/shared/sql/person_property_mutation_log_mv.sqlnew file mode 100644index 000000000000..bb0e6400dde9--- /dev/null+++ b/posthog/clickhouse/hcl/roles/ingestion_events/shared/sql/person_property_mutation_log_mv.sql@@ -0,0 +1,11 @@+SELECT+ team_id,+ uuid AS event_uuid,+ concat('{', arrayStringConcat(arrayMap(+ property -> concat(toJSONString(property.1), ':', property.2),+ arrayFilter(property -> property.1 IN ('$set', '$set_once', '$unset'),+ JSONExtractKeysAndValuesRaw(source.properties))+ ), ','), '}') AS properties,+ toDateTime(_timestamp, 'UTC') AS ingested_at+FROM kafka_person_property_mutation_log AS source+WHERE JSONHas(source.properties, '$set') OR JSONHas(source.properties, '$set_once') OR JSONHas(source.properties, '$unset')diff --git a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql b/posthog/clickhouse/hcl/sql/dev/auxiliary.sqlindex 3f39538c830d..8cdd64858ede 100644--- a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql@@ -145,6 +145,12 @@ CREATE TABLE posthog.message_assets_data (INDEX person_id_idx person_id TYPE bloom_filter(0.01) GRANULARITY 1,INDEX recipient_idx recipient TYPE bloom_filter(0.01) GRANULARITY 1) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.message_assets_data', '{replica}-{shard}', version) ORDER BY (team_id, function_kind, function_id, invocation_id, action_id) PARTITION BY toYYYYMMDD(sent_at) TTL toDate(sent_at) + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;+CREATE TABLE posthog.person_property_mutation_log_data (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_property_mutation_log_data', '{replica}-{shard}', ingested_at) ORDER BY (team_id, event_uuid) PARTITION BY toDate(ingested_at) TTL ingested_at + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;CREATE TABLE posthog.property_values (team_id Int64 CODEC(DoubleDelta, ZSTD(1)),property_type LowCardinality(String),@@ -1155,6 +1161,12 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sqlindex 6835cafc5dcc..30c19e921b08 100644--- a/posthog/clickhouse/hcl/sql/dev/data.sql+++ b/posthog/clickhouse/hcl/sql/dev/data.sql@@ -614,6 +614,12 @@ CREATE TABLE posthog.person_overrides (created_at DateTime64(6, 'UTC') DEFAULT now(),version Int32) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_overrides', '{replica}-{shard}', version) ORDER BY (team_id, old_person_id) PARTITION BY toYYYYMM(oldest_event) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.person_static_cohort (id UUID,person_id UUID,diff --git a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sqlindex 875b258e5a3b..9e2f9f949292 100644--- a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql@@ -159,6 +159,12 @@ CREATE TABLE posthog.message_assets_data (INDEX person_id_idx person_id TYPE bloom_filter(0.01) GRANULARITY 1,INDEX recipient_idx recipient TYPE bloom_filter(0.01) GRANULARITY 1) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.message_assets_data', '{replica}-{shard}', version) ORDER BY (team_id, function_kind, function_id, invocation_id, action_id) PARTITION BY toYYYYMMDD(sent_at) TTL toDate(sent_at) + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;+CREATE TABLE posthog.person_property_mutation_log_data (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_property_mutation_log_data', '{replica}-{shard}', ingested_at) ORDER BY (team_id, event_uuid) PARTITION BY toDate(ingested_at) TTL ingested_at + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;CREATE TABLE posthog.property_values (team_id Int64 CODEC(DoubleDelta, ZSTD(1)),property_type LowCardinality(String),@@ -1176,6 +1182,12 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sqlindex 258cee59455c..0157afdaf127 100644--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql@@ -601,6 +601,12 @@ CREATE TABLE posthog.person_overrides (created_at DateTime64(6, 'UTC') DEFAULT now(),version Int32) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_overrides', '{replica}-{shard}', version) ORDER BY (team_id, old_person_id) PARTITION BY toYYYYMM(oldest_event) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.person_static_cohort (id UUID,person_id UUID,diff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sqlindex 6830c1c75747..ac8a28dede56 100644--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql@@ -55,6 +55,17 @@ CREATE TABLE posthog.kafka_logs_avro (pattern Nullable(String),pattern_version Nullable(Int32)) ENGINE = Kafka(warpstream_logs) SETTINGS input_format_avro_allow_missing_fields = 1, kafka_format = 'Avro', kafka_group_name = 'clickhouse-logs-avro-new', kafka_num_consumers = 1, kafka_poll_max_batch_size = 1000, kafka_poll_timeout_ms = 3000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_logs';+CREATE TABLE posthog.kafka_person_property_mutation_log (+ team_id Int64,+ uuid UUID,+ properties String+) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_person_property_mutation_log', kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_events_json';+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.query_log_archive (hostname LowCardinality(String),user LowCardinality(String),@@ -289,3 +300,28 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34ifNull(pattern, '') AS pattern,toUInt8(ifNull(pattern_version, 0)) AS pattern_versionFROM posthog.kafka_logs_avro;+CREATE MATERIALIZED VIEW posthog.person_property_mutation_log_mv TO posthog.person_property_mutation_log (team_id Int64, event_uuid UUID, properties String, ingested_at DateTime('UTC')) AS SELECT+ team_id,+ uuid AS event_uuid,+ concat(+ '{',+ arrayStringConcat(+ arrayMap(+ property -> concat(toJSONString(property.1), ':', property.2),+ arrayFilter(+ property -> property.1 IN ('$set', '$set_once', '$unset'),+ JSONExtractKeysAndValuesRaw(source.properties)+ )+ ),+ ','+ ),+ '}'+ ) AS properties,+ toDateTime(_timestamp, 'UTC') AS ingested_at+FROM kafka_person_property_mutation_log AS source+WHERE+ JSONHas(source.properties, '$set')+OR+ JSONHas(source.properties, '$set_once')+OR+ JSONHas(source.properties, '$unset');diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex 29732036a703..671d14da1dd6 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -722,6 +722,11 @@ CREATE TABLE posthog.kafka_person_overrides (oldest_event DateTime64(6, 'UTC'),version Int32) ENGINE = Kafka() SETTINGS kafka_broker_list = 'kafka:9092', kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse-person-overrides', kafka_topic_list = 'clickhouse_person_override';+CREATE TABLE posthog.kafka_person_property_mutation_log (+ team_id Int64,+ uuid UUID,+ properties String+) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_person_property_mutation_log', kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_events_json';CREATE TABLE posthog.kafka_plugin_log_entries (id UUID,team_id Int64,@@ -1560,6 +1565,12 @@ CREATE TABLE posthog.person_overrides (created_at DateTime64(6, 'UTC') DEFAULT now(),version Int32) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_overrides', '{replica}-{shard}', version) ORDER BY (team_id, old_person_id) PARTITION BY toYYYYMM(oldest_event) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.person_property_mutation_log_data (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_property_mutation_log_data', '{replica}-{shard}', ingested_at) ORDER BY (team_id, event_uuid) PARTITION BY toDate(ingested_at) TTL ingested_at + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;CREATE TABLE posthog.person_static_cohort (id UUID,person_id UUID,@@ -6637,6 +6648,12 @@ CREATE TABLE posthog.performance_events (_offset UInt64,_partition UInt64) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.preaggregation_results (team_id Int64,job_id UUID,@@ -7188,6 +7205,31 @@ CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_mv TO posthog.writable_quProfileEventsFROM system.query_logWHERE type != 'QueryStart';+CREATE MATERIALIZED VIEW posthog.person_property_mutation_log_mv TO posthog.person_property_mutation_log (team_id Int64, event_uuid UUID, properties String, ingested_at DateTime('UTC')) AS SELECT+ team_id,+ uuid AS event_uuid,+ concat(+ '{',+ arrayStringConcat(+ arrayMap(+ property -> concat(toJSONString(property.1), ':', property.2),+ arrayFilter(+ property -> property.1 IN ('$set', '$set_once', '$unset'),+ JSONExtractKeysAndValuesRaw(source.properties)+ )+ ),+ ','+ ),+ '}'+ ) AS properties,+ toDateTime(_timestamp, 'UTC') AS ingested_at+FROM kafka_person_property_mutation_log AS source+WHERE+ JSONHas(source.properties, '$set')+OR+ JSONHas(source.properties, '$set_once')+OR+ JSONHas(source.properties, '$unset');CREATE VIEW posthog.custom_metrics AS SELECT * REPLACE(toFloat64(value) AS value)FROM posthog.custom_metrics_testUNION ALLdiff --git a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sqlindex 0517a4cc7823..5f2877ad2cf2 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql@@ -145,6 +145,12 @@ CREATE TABLE posthog.message_assets_data (INDEX person_id_idx person_id TYPE bloom_filter(0.01) GRANULARITY 1,INDEX recipient_idx recipient TYPE bloom_filter(0.01) GRANULARITY 1) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.message_assets_data', '{replica}-{shard}', version) ORDER BY (team_id, function_kind, function_id, invocation_id, action_id) PARTITION BY toYYYYMMDD(sent_at) TTL toDate(sent_at) + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;+CREATE TABLE posthog.person_property_mutation_log_data (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_property_mutation_log_data', '{replica}-{shard}', ingested_at) ORDER BY (team_id, event_uuid) PARTITION BY toDate(ingested_at) TTL ingested_at + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;CREATE TABLE posthog.property_values (team_id Int64 CODEC(DoubleDelta, ZSTD(1)),property_type LowCardinality(String),@@ -1155,6 +1161,12 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sqlindex 86bc493725fc..60c7537bbf12 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql@@ -861,6 +861,12 @@ CREATE TABLE posthog.person_overrides_to_delete (distinct_id String,partitions Array(String)) ENGINE = Join(ANY, LEFT, team_id, distinct_id);+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.person_static_cohort (id UUID,person_id UUID,diff --git a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sqlindex bfca76533082..f05de4cb5767 100644--- a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql@@ -145,6 +145,12 @@ CREATE TABLE posthog.message_assets_data (INDEX person_id_idx person_id TYPE bloom_filter(0.01) GRANULARITY 1,INDEX recipient_idx recipient TYPE bloom_filter(0.01) GRANULARITY 1) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.message_assets_data', '{replica}-{shard}', version) ORDER BY (team_id, function_kind, function_id, invocation_id, action_id) PARTITION BY toYYYYMMDD(sent_at) TTL toDate(sent_at) + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;+CREATE TABLE posthog.person_property_mutation_log_data (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.person_property_mutation_log_data', '{replica}-{shard}', ingested_at) ORDER BY (team_id, event_uuid) PARTITION BY toDate(ingested_at) TTL ingested_at + toIntervalDay(30) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;CREATE TABLE posthog.property_values (team_id Int64 CODEC(DoubleDelta, ZSTD(1)),property_type LowCardinality(String),@@ -1165,6 +1171,12 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sqlindex aeb8f175b5dc..fcac2a02dd20 100644--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql@@ -730,6 +730,12 @@ CREATE TABLE posthog.person_overrides_to_delete (distinct_id String,partitions Array(String)) ENGINE = Join(ANY, LEFT, team_id, distinct_id);+CREATE TABLE posthog.person_property_mutation_log (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+) ENGINE = Distributed('aux', 'posthog', 'person_property_mutation_log_data');CREATE TABLE posthog.person_static_cohort (id UUID,person_id UUID,diff --git a/posthog/clickhouse/migrations/0318_person_property_mutation_log.py b/posthog/clickhouse/migrations/0318_person_property_mutation_log.pynew file mode 100644index 000000000000..7d4b0db87caa--- /dev/null+++ b/posthog/clickhouse/migrations/0318_person_property_mutation_log.py@@ -0,0 +1,17 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions+from posthog.models.event.person_property_mutation_sql import (+ PERSON_PROPERTY_MUTATION_LOG_DATA_TABLE_SQL,+ PERSON_PROPERTY_MUTATION_LOG_KAFKA_TABLE_SQL,+ PERSON_PROPERTY_MUTATION_LOG_MV_SQL,+ PERSON_PROPERTY_MUTATION_LOG_TABLE_SQL,+)++operations = [+ run_sql_with_exceptions(PERSON_PROPERTY_MUTATION_LOG_DATA_TABLE_SQL(), node_roles=[NodeRole.AUX]),+ run_sql_with_exceptions(+ PERSON_PROPERTY_MUTATION_LOG_TABLE_SQL(), node_roles=[NodeRole.AUX, NodeRole.DATA, NodeRole.INGESTION_EVENTS]+ ),+ run_sql_with_exceptions(PERSON_PROPERTY_MUTATION_LOG_KAFKA_TABLE_SQL(), node_roles=[NodeRole.INGESTION_EVENTS]),+ run_sql_with_exceptions(PERSON_PROPERTY_MUTATION_LOG_MV_SQL(), node_roles=[NodeRole.INGESTION_EVENTS]),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 404e381e3091..9aa3cf5ed60f 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0317_extract_ipv4_substrings_function+0318_person_property_mutation_logdiff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.pyindex 2e4655b992b7..6bbee3b3b796 100644--- a/posthog/clickhouse/schema.py+++ b/posthog/clickhouse/schema.py@@ -187,6 +187,12 @@ from posthog.models.dmat_slot_assignments.sql import (DMAT_SLOT_ASSIGNMENTS_DICTIONARY_SQL,DMAT_SLOT_ASSIGNMENTS_TABLE_SQL,)+from posthog.models.event.person_property_mutation_sql import (+ PERSON_PROPERTY_MUTATION_LOG_DATA_TABLE_SQL,+ PERSON_PROPERTY_MUTATION_LOG_KAFKA_TABLE_SQL,+ PERSON_PROPERTY_MUTATION_LOG_MV_SQL,+ PERSON_PROPERTY_MUTATION_LOG_TABLE_SQL,+)from posthog.models.event.sql import (DISTRIBUTED_EVENTS_JSON_TABLE_SQL,DISTRIBUTED_EVENTS_RECENT_TABLE_SQL,@@ -375,6 +381,7 @@ from products.event_definitions.backend.models.property_definition import PROPER# Queries to create tables, you must pass function, otherwise the table is created before# objects are mocked and the ambr will go into infinite loop update.CREATE_MERGETREE_TABLE_QUERIES = (+ PERSON_PROPERTY_MUTATION_LOG_DATA_TABLE_SQL,LOG_ENTRIES_TABLE_SQL,CREATE_COHORTPEOPLE_TABLE_SQL,PERSON_STATIC_COHORT_TABLE_SQL,@@ -462,6 +469,7 @@ CREATE_MERGETREE_TABLE_QUERIES = (DMAT_SLOT_ASSIGNMENTS_TABLE_SQL,)CREATE_DISTRIBUTED_TABLE_QUERIES = (+ PERSON_PROPERTY_MUTATION_LOG_TABLE_SQL,WRITABLE_EVENTS_TABLE_SQL,DISTRIBUTED_EVENTS_TABLE_SQL,WRITABLE_EVENTS_JSON_TABLE_SQL,@@ -553,6 +561,7 @@ CREATE_DISTRIBUTED_TABLE_QUERIES = (DISTRIBUTED_PROPERTY_VALUES_TABLE_SQL,)CREATE_KAFKA_TABLE_QUERIES = (+ PERSON_PROPERTY_MUTATION_LOG_KAFKA_TABLE_SQL,KAFKA_LOG_ENTRIES_TABLE_SQL,KAFKA_DEAD_LETTER_QUEUE_TABLE_SQL,KAFKA_EVENTS_TABLE_JSON_SQL,@@ -588,6 +597,7 @@ CREATE_KAFKA_TABLE_QUERIES = (KAFKA_PROPERTY_VALUES_TABLE_SQL_FN,)CREATE_MV_TABLE_QUERIES = (+ PERSON_PROPERTY_MUTATION_LOG_MV_SQL,LOG_ENTRIES_TABLE_MV_SQL,DEAD_LETTER_QUEUE_TABLE_MV_SQL,EVENTS_TABLE_JSON_MV_SQL,diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex bd5bf478cff2..73c4aad812d4 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -641,6 +641,20 @@'''# ---+# name: test_create_kafka_table_with_different_kafka_host[kafka_person_property_mutation_log]+ '''++ CREATE TABLE IF NOT EXISTS kafka_person_property_mutation_log+ (+ team_id Int64,+ uuid UUID,+ properties String+ )+ ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'clickhouse_events_json_test', kafka_group_name = 'clickhouse_person_property_mutation_log', kafka_format = 'JSONEachRow')+ SETTINGS kafka_skip_broken_messages = 100++ '''+# ---# name: test_create_kafka_table_with_different_kafka_host[kafka_plugin_log_entries]'''@@ -2928,6 +2942,20 @@'''# ---+# name: test_create_table_query[kafka_person_property_mutation_log]+ '''++ CREATE TABLE IF NOT EXISTS kafka_person_property_mutation_log+ (+ team_id Int64,+ uuid UUID,+ properties String+ )+ ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'clickhouse_events_json_test', kafka_group_name = 'clickhouse_person_property_mutation_log', kafka_format = 'JSONEachRow')+ SETTINGS kafka_skip_broken_messages = 100++ '''+# ---# name: test_create_table_query[kafka_plugin_log_entries]'''@@ -5039,6 +5067,57 @@'''# ---+# name: test_create_table_query[person_property_mutation_log]+ '''++ CREATE TABLE IF NOT EXISTS person_property_mutation_log+ (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+ )+ ENGINE = Distributed('aux', 'posthog_test', 'person_property_mutation_log_data')++ '''+# ---+# name: test_create_table_query[person_property_mutation_log_data]+ '''++ CREATE TABLE IF NOT EXISTS person_property_mutation_log_data+ (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+ )+ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.person_property_mutation_log_data', '{replica}-{shard}', ingested_at)+ PARTITION BY toDate(ingested_at)+ ORDER BY (team_id, event_uuid)+ TTL ingested_at + INTERVAL 30 DAY+ SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1++ '''+# ---+# name: test_create_table_query[person_property_mutation_log_mv]+ '''++ CREATE MATERIALIZED VIEW IF NOT EXISTS person_property_mutation_log_mv+ TO person_property_mutation_log+ AS SELECT+ team_id,+ uuid AS event_uuid,+ concat('{', arrayStringConcat(arrayMap(+ property -> concat(toJSONString(property.1), ':', property.2),+ arrayFilter(property -> property.1 IN ('$set', '$set_once', '$unset'),+ JSONExtractKeysAndValuesRaw(source.properties))+ ), ','), '}') AS properties,+ toDateTime(_timestamp, 'UTC') AS ingested_at+ FROM kafka_person_property_mutation_log AS source+ WHERE JSONHas(source.properties, '$set') OR JSONHas(source.properties, '$set_once') OR JSONHas(source.properties, '$unset')++ '''+# ---# name: test_create_table_query[person_static_cohort]'''@@ -11668,6 +11747,24 @@'''# ---+# name: test_create_table_query_replicated_and_storage[person_property_mutation_log_data]+ '''++ CREATE TABLE IF NOT EXISTS person_property_mutation_log_data+ (+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+ )+ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.person_property_mutation_log_data', '{replica}-{shard}', ingested_at)+ PARTITION BY toDate(ingested_at)+ ORDER BY (team_id, event_uuid)+ TTL ingested_at + INTERVAL 30 DAY+ SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1++ '''+# ---# name: test_create_table_query_replicated_and_storage[person_static_cohort]'''diff --git a/posthog/clickhouse/test/test_schema.py b/posthog/clickhouse/test/test_schema.pyindex afcfaf43e033..7f8d94980f68 100644--- a/posthog/clickhouse/test/test_schema.py+++ b/posthog/clickhouse/test/test_schema.py@@ -1,10 +1,12 @@import re+import jsonimport uuidfrom collections.abc import Iteratorfrom pathlib import Pathimport pytest+from posthog.clickhouse.client import sync_executefrom posthog.clickhouse.kafka_engine import CONSUMER_GROUP_EVENTS_JSON_NATIVE_JSON, KAFKA_COLUMNS_WITH_PARTITIONfrom posthog.clickhouse.schema import (CREATE_KAFKA_TABLE_QUERIES,@@ -14,6 +16,7 @@ from posthog.clickhouse.schema import (build_query,get_table_name,)+from posthog.models.event.person_property_mutation_sql import PERSON_PROPERTY_MUTATION_LOG_MV_SQLfrom posthog.models.event.sql import (EVENTS_JSON_TABLE_MV_SQL,KAFKA_EVENTS_NATIVE_JSON_TABLE,@@ -64,6 +67,43 @@ def test_events_json_table_uses_dedicated_kafka_consumer_group(settings):assert f"FROM {settings.CLICKHOUSE_DATABASE}.{KAFKA_EVENTS_NATIVE_JSON_TABLE}" in mv_query+ "properties,expected",+ [+ (+ {+ "$set": {"nested": {"values": [True, None, 42, "雪"]}},+ "$set_once": {"first": False},+ "$unset": ["old"],+ "ordinary": "discard",+ },+ {"$set": {"nested": {"values": [True, None, 42, "雪"]}}, "$set_once": {"first": False}, "$unset": ["old"]},+ ),+ ({"$unset": ["old"]}, {"$unset": ["old"]}),+ ({"$unset": {"old": True}}, {"$unset": {"old": True}}),+ ({"$set_once": {"first": 0}}, {"$set_once": {"first": 0}}),+ ({"ordinary": "discard"}, None),+ ],+)+def test_person_property_mutation_projection(properties: dict[str, object], expected: dict[str, object] | None) -> None:+ select = PERSON_PROPERTY_MUTATION_LOG_MV_SQL().split("AS SELECT", 1)[1]+ rows = sync_execute(+ """+ WITH kafka_person_property_mutation_log AS (+ SELECT 42 AS team_id,+ toUUID('0192a5c8-0000-0000-0000-000000000000') AS uuid,+ %(properties)s AS properties,+ now() AS _timestamp+ )+ SELECT """+ + select,+ {"properties": json.dumps(properties)},+ team_id=42,+ flush=False,+ )+ assert [json.loads(row[2]) for row in rows] == ([] if expected is None else [expected])++def _column_definition_lines(block: str) -> Iterator[str]:for raw_line in block.splitlines():line = raw_line.strip().lstrip(",").strip()diff --git a/posthog/models/deletion_targets.py b/posthog/models/deletion_targets.pyindex 6c34c65ce4a4..656a99e42fae 100644--- a/posthog/models/deletion_targets.py+++ b/posthog/models/deletion_targets.py@@ -206,7 +206,7 @@ PERSONAL_DATA_TARGETS: tuple[DeletionTarget, ...] = (*EVENTS_TARGETS, FLAG_EVALU# sharded_events_recent is a transient mirror of the last few days of events, on a 7-day TTL keyed# on inserted_at. Seven days is a short enough window to accept as the erasure bound, and a sweep# would race the TTL for little benefit.-TTL_ONLY_TABLES: frozenset[str] = frozenset({SHARDED_EVENTS_RECENT_DATA_TABLE()})+TTL_ONLY_TABLES: frozenset[str] = frozenset({SHARDED_EVENTS_RECENT_DATA_TABLE(), "person_property_mutation_log_data"})_TABLE_EXISTS_SQL = "SELECT count() FROM system.tables WHERE database = %(database)s AND name = %(name)s"diff --git a/posthog/models/event/person_property_mutation_sql.py b/posthog/models/event/person_property_mutation_sql.pynew file mode 100644index 000000000000..d77ddc979dcf--- /dev/null+++ b/posthog/models/event/person_property_mutation_sql.py@@ -0,0 +1,63 @@+from django.conf import settings++from posthog.clickhouse.kafka_engine import kafka_engine+from posthog.clickhouse.table_engines import Distributed, ReplacingMergeTree+from posthog.kafka_client.topics import KAFKA_EVENTS_JSON++PERSON_PROPERTY_MUTATION_COLUMNS = """+ team_id Int64,+ event_uuid UUID,+ properties String,+ ingested_at DateTime('UTC')+"""+++def PERSON_PROPERTY_MUTATION_LOG_DATA_TABLE_SQL() -> str:+ return f"""+CREATE TABLE IF NOT EXISTS person_property_mutation_log_data+({PERSON_PROPERTY_MUTATION_COLUMNS})+ENGINE = {ReplacingMergeTree("person_property_mutation_log_data", ver="ingested_at")}+PARTITION BY toDate(ingested_at)+ORDER BY (team_id, event_uuid)+TTL ingested_at + INTERVAL 30 DAY+SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1+"""+++def PERSON_PROPERTY_MUTATION_LOG_TABLE_SQL() -> str:+ return f"""+CREATE TABLE IF NOT EXISTS person_property_mutation_log+({PERSON_PROPERTY_MUTATION_COLUMNS})+ENGINE = {Distributed(data_table="person_property_mutation_log_data", cluster=settings.CLICKHOUSE_AUX_CLUSTER)}+"""+++def PERSON_PROPERTY_MUTATION_LOG_KAFKA_TABLE_SQL() -> str:+ return f"""+CREATE TABLE IF NOT EXISTS kafka_person_property_mutation_log+(+ team_id Int64,+ uuid UUID,+ properties String+)+ENGINE = {kafka_engine(topic=KAFKA_EVENTS_JSON, group="clickhouse_person_property_mutation_log", named_collection=settings.CLICKHOUSE_KAFKA_WARPSTREAM_INGESTION_NAMED_COLLECTION)}+SETTINGS kafka_skip_broken_messages = 100+"""+++def PERSON_PROPERTY_MUTATION_LOG_MV_SQL() -> str:+ return """+CREATE MATERIALIZED VIEW IF NOT EXISTS person_property_mutation_log_mv+TO person_property_mutation_log+AS SELECT+ team_id,+ uuid AS event_uuid,+ concat('{', arrayStringConcat(arrayMap(+ property -> concat(toJSONString(property.1), ':', property.2),+ arrayFilter(property -> property.1 IN ('$set', '$set_once', '$unset'),+ JSONExtractKeysAndValuesRaw(source.properties))+ ), ','), '}') AS properties,+ toDateTime(_timestamp, 'UTC') AS ingested_at+FROM kafka_person_property_mutation_log AS source+WHERE JSONHas(source.properties, '$set') OR JSONHas(source.properties, '$set_once') OR JSONHas(source.properties, '$unset')+"""