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.

chore(cdp): move invocation and message asset table definitions into products (#115427)

Harley Alexander90e49274cc4c
diff --git a/posthog/clickhouse/migrations/0254_hog_invocation_results.py b/posthog/clickhouse/migrations/0254_hog_invocation_results.py
index ef8ce3ed9c28..426e27f4dbc2 100644
--- a/posthog/clickhouse/migrations/0254_hog_invocation_results.py
+++ b/posthog/clickhouse/migrations/0254_hog_invocation_results.py
@@ -1,6 +1,7 @@
from posthog.clickhouse.client.connection import NodeRole
from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
-from posthog.models.hog_invocation_results.sql import (
+
+from products.cdp.backend.facade.clickhouse import (
DISTRIBUTED_HOG_INVOCATION_RESULTS_TABLE_SQL,
HOG_INVOCATION_RESULTS_DATA_TABLE_SQL,
HOG_INVOCATION_RESULTS_MV_SQL,
diff --git a/posthog/clickhouse/migrations/0258_hog_invocation_results_warpstream_cyclotron.py b/posthog/clickhouse/migrations/0258_hog_invocation_results_warpstream_cyclotron.py
index 7557d0d474f6..d29b6b5a19ec 100644
--- a/posthog/clickhouse/migrations/0258_hog_invocation_results_warpstream_cyclotron.py
+++ b/posthog/clickhouse/migrations/0258_hog_invocation_results_warpstream_cyclotron.py
@@ -1,6 +1,7 @@
from posthog.clickhouse.client.connection import NodeRole
from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
-from posthog.models.hog_invocation_results.sql import (
+
+from products.cdp.backend.facade.clickhouse import (
DISTRIBUTED_HOG_INVOCATION_RESULTS_TABLE_SQL,
DROP_HOG_INVOCATION_RESULTS_MV_SQL,
DROP_KAFKA_HOG_INVOCATION_RESULTS_TABLE_SQL,
diff --git a/posthog/clickhouse/migrations/0284_message_assets.py b/posthog/clickhouse/migrations/0284_message_assets.py
index 72eea9883113..8132487c1fe6 100644
--- a/posthog/clickhouse/migrations/0284_message_assets.py
+++ b/posthog/clickhouse/migrations/0284_message_assets.py
@@ -1,6 +1,7 @@
from posthog.clickhouse.client.connection import NodeRole
from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
-from posthog.models.message_assets.sql import (
+
+from products.workflows.backend.facade.clickhouse import (
DISTRIBUTED_MESSAGE_ASSETS_TABLE_SQL,
KAFKA_MESSAGE_ASSETS_TABLE_SQL,
MESSAGE_ASSETS_DATA_TABLE_SQL,
diff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.py
index 4f86684e6373..6658696da783 100644
--- a/posthog/clickhouse/schema.py
+++ b/posthog/clickhouse/schema.py
@@ -255,12 +255,6 @@ from posthog.models.group.sql import (
GROUPS_WRITABLE_TABLE_SQL,
KAFKA_GROUPS_TABLE_SQL,
)
-from posthog.models.hog_invocation_results.sql import (
- DISTRIBUTED_HOG_INVOCATION_RESULTS_TABLE_SQL,
- HOG_INVOCATION_RESULTS_DATA_TABLE_SQL,
- HOG_INVOCATION_RESULTS_MV_SQL,
- KAFKA_HOG_INVOCATION_RESULTS_TABLE_SQL,
-)
from posthog.models.ingestion_warnings.sql import (
DISTRIBUTED_INGESTION_WARNINGS_TABLE_SQL,
INGESTION_WARNINGS_DATA_TABLE_SQL,
@@ -274,12 +268,6 @@ from posthog.models.ingestion_warnings.sql_v2 import (
INGESTION_WARNINGS_V2_MV_SQL,
KAFKA_INGESTION_WARNINGS_V2_TABLE_SQL,
)
-from posthog.models.message_assets.sql import (
- DISTRIBUTED_MESSAGE_ASSETS_TABLE_SQL,
- KAFKA_MESSAGE_ASSETS_TABLE_SQL,
- MESSAGE_ASSETS_DATA_TABLE_SQL,
- MESSAGE_ASSETS_MV_SQL,
-)
from posthog.models.performance.sql import (
DISTRIBUTED_PERFORMANCE_EVENTS_TABLE_SQL,
KAFKA_PERFORMANCE_EVENTS_TABLE_SQL,
@@ -390,6 +378,12 @@ from products.alerts_platform.backend.facade.clickhouse import (
DISTRIBUTED_PLATFORM_ALERT_EVENTS_TABLE_SQL,
SHARDED_PLATFORM_ALERT_EVENTS_TABLE_SQL,
)
+from products.cdp.backend.facade.clickhouse import (
+ DISTRIBUTED_HOG_INVOCATION_RESULTS_TABLE_SQL,
+ HOG_INVOCATION_RESULTS_DATA_TABLE_SQL,
+ HOG_INVOCATION_RESULTS_MV_SQL,
+ KAFKA_HOG_INVOCATION_RESULTS_TABLE_SQL,
+)
from products.cohorts.backend.models.sql import CREATE_COHORTPEOPLE_TABLE_SQL
from products.error_tracking.backend.embedding import (
DISTRIBUTED_DOCUMENT_EMBEDDINGS_TABLE_SQL,
@@ -416,6 +410,12 @@ from products.error_tracking.backend.sql import (
WRITABLE_ERROR_TRACKING_ISSUE_FINGERPRINT_OVERRIDES_TABLE_SQL,
)
from products.event_definitions.backend.models.property_definition import PROPERTY_DEFINITIONS_TABLE_SQL
+from products.workflows.backend.facade.clickhouse import (
+ DISTRIBUTED_MESSAGE_ASSETS_TABLE_SQL,
+ KAFKA_MESSAGE_ASSETS_TABLE_SQL,
+ MESSAGE_ASSETS_DATA_TABLE_SQL,
+ MESSAGE_ASSETS_MV_SQL,
+)
# 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.
diff --git a/products/cdp/backend/facade/clickhouse.py b/products/cdp/backend/facade/clickhouse.py
new file mode 100644
index 000000000000..5d160873132b
--- /dev/null
+++ b/products/cdp/backend/facade/clickhouse.py
@@ -0,0 +1,15 @@
+"""The ClickHouse tables core creates and migrates for this product.
+
+Wiring, not data: `posthog/clickhouse/schema.py` builds these in a local or test ClickHouse, and
+the migrations that created them apply the same definitions to a cluster.
+"""
+
+from products.cdp.backend.models.hog_invocation_results_sql import (
+ DISTRIBUTED_HOG_INVOCATION_RESULTS_TABLE_SQL as DISTRIBUTED_HOG_INVOCATION_RESULTS_TABLE_SQL,
+ DROP_HOG_INVOCATION_RESULTS_MV_SQL as DROP_HOG_INVOCATION_RESULTS_MV_SQL,
+ DROP_KAFKA_HOG_INVOCATION_RESULTS_TABLE_SQL as DROP_KAFKA_HOG_INVOCATION_RESULTS_TABLE_SQL,
+ HOG_INVOCATION_RESULTS_DATA_TABLE_SQL as HOG_INVOCATION_RESULTS_DATA_TABLE_SQL,
+ HOG_INVOCATION_RESULTS_MV_SQL as HOG_INVOCATION_RESULTS_MV_SQL,
+ INSERT_HOG_INVOCATION_RESULT_SQL as INSERT_HOG_INVOCATION_RESULT_SQL,
+ KAFKA_HOG_INVOCATION_RESULTS_TABLE_SQL as KAFKA_HOG_INVOCATION_RESULTS_TABLE_SQL,
+)
diff --git a/posthog/models/hog_invocation_results/sql.py b/products/cdp/backend/models/hog_invocation_results_sql.py
similarity index 100%
rename from posthog/models/hog_invocation_results/sql.py
rename to products/cdp/backend/models/hog_invocation_results_sql.py
diff --git a/products/cdp/backend/test/test_stuck_invocations.py b/products/cdp/backend/test/test_stuck_invocations.py
index a17bea65fbdf..27cea897ec7b 100644
--- a/products/cdp/backend/test/test_stuck_invocations.py
+++ b/products/cdp/backend/test/test_stuck_invocations.py
@@ -9,8 +9,8 @@ from django.test import SimpleTestCase
from parameterized import parameterized
from posthog.clickhouse.client.execute import sync_execute
-from posthog.models.hog_invocation_results.sql import INSERT_HOG_INVOCATION_RESULT_SQL
+from products.cdp.backend.models.hog_invocation_results_sql import INSERT_HOG_INVOCATION_RESULT_SQL
from products.cdp.backend.services.stuck_invocations import (
STUCK_INVOCATION_ERROR_KIND,
StuckInvocation,
diff --git a/products/workflows/backend/facade/clickhouse.py b/products/workflows/backend/facade/clickhouse.py
new file mode 100644
index 000000000000..9cfe6bfe3314
--- /dev/null
+++ b/products/workflows/backend/facade/clickhouse.py
@@ -0,0 +1,12 @@
+"""The ClickHouse tables core creates and migrates for this product.
+
+Wiring, not data: `posthog/clickhouse/schema.py` builds these in a local or test ClickHouse, and
+the migration that created them applies the same definitions to a cluster.
+"""
+
+from products.workflows.backend.models.message_assets_sql import (
+ DISTRIBUTED_MESSAGE_ASSETS_TABLE_SQL as DISTRIBUTED_MESSAGE_ASSETS_TABLE_SQL,
+ KAFKA_MESSAGE_ASSETS_TABLE_SQL as KAFKA_MESSAGE_ASSETS_TABLE_SQL,
+ MESSAGE_ASSETS_DATA_TABLE_SQL as MESSAGE_ASSETS_DATA_TABLE_SQL,
+ MESSAGE_ASSETS_MV_SQL as MESSAGE_ASSETS_MV_SQL,
+)
diff --git a/posthog/models/message_assets/sql.py b/products/workflows/backend/models/message_assets_sql.py
similarity index 100%
rename from posthog/models/message_assets/sql.py
rename to products/workflows/backend/models/message_assets_sql.py
diff --git a/products/workflows/backend/tests/api/test_hog_flow_invocation_results.py b/products/workflows/backend/tests/api/test_hog_flow_invocation_results.py
index 07b670378d38..6e2ae2a469f6 100644
--- a/products/workflows/backend/tests/api/test_hog_flow_invocation_results.py
+++ b/products/workflows/backend/tests/api/test_hog_flow_invocation_results.py
@@ -10,10 +10,10 @@ from parameterized import parameterized
from rest_framework import status
from posthog.clickhouse.client.execute import sync_execute
-from posthog.models.hog_invocation_results.sql import INSERT_HOG_INVOCATION_RESULT_SQL
from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.utils import generate_random_token_personal, hash_key_value
+from products.cdp.backend.facade.clickhouse import INSERT_HOG_INVOCATION_RESULT_SQL
from products.workflows.backend.models.hog_flow.hog_flow import HogFlow
diff --git a/products/workflows/backend/tests/api/test_message_assets.py b/products/workflows/backend/tests/api/test_message_assets.py
index 0ff7ff822e8e..c2990cc7e5c8 100644
--- a/products/workflows/backend/tests/api/test_message_assets.py
+++ b/products/workflows/backend/tests/api/test_message_assets.py
@@ -7,12 +7,12 @@ from parameterized import parameterized
from rest_framework import status
from posthog.clickhouse.client.execute import sync_execute
-from posthog.models.message_assets.sql import INSERT_MESSAGE_ASSET_SQL
from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.utils import generate_random_token_personal, hash_key_value
from posthog.test.persons import create_person
from products.workflows.backend.models.hog_flow.hog_flow import HogFlow
+from products.workflows.backend.models.message_assets_sql import INSERT_MESSAGE_ASSET_SQL
def create_message_asset(