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(data-deletion): add request provenance to deletion queue (#98213)

Paweł Szczure9d9a1912dde
diff --git a/posthog/clickhouse/adhoc_events_deletion.py b/posthog/clickhouse/adhoc_events_deletion.py
index 0aee3a6d85db..e3cfc9989e41 100644
--- a/posthog/clickhouse/adhoc_events_deletion.py
+++ b/posthog/clickhouse/adhoc_events_deletion.py
@@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS {table_name} {on_cluster_clause}
(
team_id Int64,
uuid UUID,
+ data_deletion_request_id Nullable(UUID),
created_at DateTime64(6, 'UTC') DEFAULT now64(),
deleted_at DateTime,
is_deleted UInt8 DEFAULT 0
diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hcl
index 6d65e191933c..ad3555053ea4 100644
--- a/posthog/clickhouse/hcl/golden/dev/data.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl
@@ -11,6 +11,9 @@ database "posthog" {
column "uuid" {
type = "UUID"
}
+ column "data_deletion_request_id" {
+ type = "Nullable(UUID)"
+ }
column "created_at" {
type = "DateTime64(6, 'UTC')"
default = "now64()"
diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
index 5ccd7ef04d29..8466420faec6 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
@@ -11,6 +11,9 @@ database "posthog" {
column "uuid" {
type = "UUID"
}
+ column "data_deletion_request_id" {
+ type = "Nullable(UUID)"
+ }
column "created_at" {
type = "DateTime64(6, 'UTC')"
default = "now64()"
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 8b09318c7d28..66397a09fad2 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -38,6 +38,9 @@ database "posthog" {
column "uuid" {
type = "UUID"
}
+ column "data_deletion_request_id" {
+ type = "Nullable(UUID)"
+ }
column "created_at" {
type = "DateTime64(6, 'UTC')"
default = "now64()"
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
index 28fb1402a540..afed040dcbe1 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
@@ -11,6 +11,9 @@ database "posthog" {
column "uuid" {
type = "UUID"
}
+ column "data_deletion_request_id" {
+ type = "Nullable(UUID)"
+ }
column "created_at" {
type = "DateTime64(6, 'UTC')"
default = "now64()"
diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
index 21fae7729254..6ae879438942 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
@@ -12,6 +12,9 @@ database "posthog" {
column "uuid" {
type = "UUID"
}
+ column "data_deletion_request_id" {
+ type = "Nullable(UUID)"
+ }
column "created_at" {
type = "DateTime64(6, 'UTC')"
default = "now64()"
diff --git a/posthog/clickhouse/hcl/roles/data/common/cloud_and_local.hcl b/posthog/clickhouse/hcl/roles/data/common/cloud_and_local.hcl
index 3d4d21933a72..dc641e2aee83 100644
--- a/posthog/clickhouse/hcl/roles/data/common/cloud_and_local.hcl
+++ b/posthog/clickhouse/hcl/roles/data/common/cloud_and_local.hcl
@@ -14,6 +14,9 @@ database "posthog" {
column "uuid" {
type = "UUID"
}
+ column "data_deletion_request_id" {
+ type = "Nullable(UUID)"
+ }
column "created_at" {
type = "DateTime64(6, 'UTC')"
default = "now64()"
diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sql
index 476b2ba89d35..4c8aa8c5de57 100644
--- a/posthog/clickhouse/hcl/sql/dev/data.sql
+++ b/posthog/clickhouse/hcl/sql/dev/data.sql
@@ -4,6 +4,7 @@
CREATE TABLE posthog.adhoc_events_deletion (
team_id Int64,
uuid UUID,
+ data_deletion_request_id Nullable(UUID),
created_at DateTime64(6, 'UTC') DEFAULT now64(),
deleted_at DateTime,
is_deleted UInt8 DEFAULT 0
diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sql
index 6c036b4593b7..5b5a69c361a3 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql
@@ -4,6 +4,7 @@
CREATE TABLE posthog.adhoc_events_deletion (
team_id Int64,
uuid UUID,
+ data_deletion_request_id Nullable(UUID),
created_at DateTime64(6, 'UTC') DEFAULT now64(),
deleted_at DateTime,
is_deleted UInt8 DEFAULT 0
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index b820e98bd186..06475cf58b60 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -4,6 +4,7 @@
CREATE TABLE posthog.adhoc_events_deletion (
team_id Int64,
uuid UUID,
+ data_deletion_request_id Nullable(UUID),
created_at DateTime64(6, 'UTC') DEFAULT now64(),
deleted_at DateTime,
is_deleted UInt8 DEFAULT 0
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
index 7944a16c7867..1751eac8d626 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
@@ -4,6 +4,7 @@
CREATE TABLE posthog.adhoc_events_deletion (
team_id Int64,
uuid UUID,
+ data_deletion_request_id Nullable(UUID),
created_at DateTime64(6, 'UTC') DEFAULT now64(),
deleted_at DateTime,
is_deleted UInt8 DEFAULT 0
diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sql
index 0c97ac61aaa7..47bad17ee17b 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql
@@ -4,6 +4,7 @@
CREATE TABLE posthog.adhoc_events_deletion (
team_id Int64,
uuid UUID,
+ data_deletion_request_id Nullable(UUID),
created_at DateTime64(6, 'UTC') DEFAULT now64(),
deleted_at DateTime,
is_deleted UInt8 DEFAULT 0
diff --git a/posthog/clickhouse/migrations/0319_add_data_deletion_request_id_to_adhoc_events_deletion.py b/posthog/clickhouse/migrations/0319_add_data_deletion_request_id_to_adhoc_events_deletion.py
new file mode 100644
index 000000000000..9a3eec51d744
--- /dev/null
+++ b/posthog/clickhouse/migrations/0319_add_data_deletion_request_id_to_adhoc_events_deletion.py
@@ -0,0 +1,15 @@
+"""AUTO-GENERATED from the declarative HCL by posthog/clickhouse/hcl/codegen/gen_migration.py.
+Placement (node_roles) is derived from the node composition manifest; review before committing.
+"""
+
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+
+operations = [
+ run_sql_with_exceptions(
+ "ALTER TABLE adhoc_events_deletion ADD COLUMN IF NOT EXISTS data_deletion_request_id Nullable(UUID) AFTER uuid",
+ node_roles=[NodeRole.DATA],
+ sharded=False,
+ is_alter_on_replicated_table=True,
+ ),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index 9aa3cf5ed60f..db775bba6390 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0318_person_property_mutation_log
+0319_add_data_deletion_request_id_to_adhoc_events_deletion