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(customer-analytics): Add CustomPropertySource model (#67176)

Arthur Moreira de Deus710770a63dc1
diff --git a/.semgrep/rules/idor-team-scoped-models.yaml b/.semgrep/rules/idor-team-scoped-models.yaml
index b82121303024..cc34ea1471f2 100644
--- a/.semgrep/rules/idor-team-scoped-models.yaml
+++ b/.semgrep/rules/idor-team-scoped-models.yaml
@@ -92,6 +92,7 @@ rules:
|CustomerProfileConfig
|CustomOAuth2Integration
|CustomPropertyDefinition
+ |CustomPropertySource
|CustomPropertyValue
|DAG
|Dashboard
@@ -364,6 +365,7 @@ rules:
|CustomerProfileConfig
|CustomOAuth2Integration
|CustomPropertyDefinition
+ |CustomPropertySource
|CustomPropertyValue
|DAG
|Dashboard
diff --git a/products/customer_analytics/backend/migrations/0010_custompropertysource.py b/products/customer_analytics/backend/migrations/0010_custompropertysource.py
new file mode 100644
index 000000000000..29c9778c2308
--- /dev/null
+++ b/products/customer_analytics/backend/migrations/0010_custompropertysource.py
@@ -0,0 +1,94 @@
+# Generated by Django 5.2.14 on 2026-06-26 17:27
+
+import django.db.models.deletion
+from django.conf import settings
+from django.db import migrations, models
+
+import posthog.models.utils
+from posthog.migration_helpers import AddForeignKeyNotValid
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("customer_analytics", "0009_custompropertyvalue_validate_fks"),
+ ("data_modeling", "0024_datamodelingjob_team_status_idx"),
+ ("posthog", "1238_ducklakebackfill_earliest_event_date"),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="CustomPropertySource",
+ fields=[
+ ("created_at", models.DateTimeField(auto_now_add=True)),
+ ("updated_at", models.DateTimeField(auto_now=True, null=True)),
+ (
+ "id",
+ models.UUIDField(
+ default=posthog.models.utils.uuid7,
+ editable=False,
+ primary_key=True,
+ serialize=False,
+ ),
+ ),
+ ("source_column", models.CharField(max_length=400)),
+ ("key_column", models.CharField(max_length=400)),
+ ("is_enabled", models.BooleanField(default=True)),
+ ("consecutive_failures", models.PositiveIntegerField(default=0)),
+ ("last_synced_at", models.DateTimeField(blank=True, null=True)),
+ ("last_sync_error", models.TextField(blank=True, null=True)),
+ (
+ "created_by",
+ models.ForeignKey(
+ blank=True,
+ db_constraint=False,
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ to=settings.AUTH_USER_MODEL,
+ ),
+ ),
+ (
+ "definition",
+ models.OneToOneField(
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="source",
+ to="customer_analytics.custompropertydefinition",
+ ),
+ ),
+ (
+ "saved_query",
+ models.ForeignKey(
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ related_name="+",
+ to="data_modeling.datawarehousesavedquery",
+ ),
+ ),
+ (
+ "team",
+ models.ForeignKey(
+ db_constraint=False,
+ on_delete=django.db.models.deletion.CASCADE,
+ to="posthog.team",
+ ),
+ ),
+ ],
+ options={
+ "abstract": False,
+ },
+ ),
+ AddForeignKeyNotValid(
+ model_name="custompropertysource",
+ name="custompropertysource_team_id_fk",
+ column="team_id",
+ to_table="posthog_team",
+ to_column="id",
+ ),
+ AddForeignKeyNotValid(
+ model_name="custompropertysource",
+ name="custompropertysource_created_by_id_fk",
+ column="created_by_id",
+ to_table="posthog_user",
+ to_column="id",
+ ),
+ ]
diff --git a/products/customer_analytics/backend/migrations/0011_custompropertysource_validate_fks.py b/products/customer_analytics/backend/migrations/0011_custompropertysource_validate_fks.py
new file mode 100644
index 000000000000..2a65aa339e71
--- /dev/null
+++ b/products/customer_analytics/backend/migrations/0011_custompropertysource_validate_fks.py
@@ -0,0 +1,14 @@
+from django.db import migrations
+
+from posthog.migration_helpers import ValidateForeignKey
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("customer_analytics", "0010_custompropertysource"),
+ ]
+
+ operations = [
+ ValidateForeignKey(model_name="custompropertysource", name="custompropertysource_created_by_id_fk"),
+ ValidateForeignKey(model_name="custompropertysource", name="custompropertysource_team_id_fk"),
+ ]
diff --git a/products/customer_analytics/backend/migrations/max_migration.txt b/products/customer_analytics/backend/migrations/max_migration.txt
index 43dc6dcd6ea7..21b6750ba376 100644
--- a/products/customer_analytics/backend/migrations/max_migration.txt
+++ b/products/customer_analytics/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0009_custompropertyvalue_validate_fks
+0011_custompropertysource_validate_fks
diff --git a/products/customer_analytics/backend/models/__init__.py b/products/customer_analytics/backend/models/__init__.py
index be5c16683721..e3a0e2676683 100644
--- a/products/customer_analytics/backend/models/__init__.py
+++ b/products/customer_analytics/backend/models/__init__.py
@@ -1,5 +1,6 @@
from .account import Account
from .custom_property_definition import DATA_TYPE_BY_DISPLAY_TYPE, CustomPropertyDefinition, DataType, DisplayType
+from .custom_property_source import CustomPropertySource
from .custom_property_value import CustomPropertyValue
from .customer_journey import CustomerJourney
from .customer_profile_config import CustomerProfileConfig
@@ -9,6 +10,7 @@ __all__ = [
"DATA_TYPE_BY_DISPLAY_TYPE",
"Account",
"CustomPropertyDefinition",
+ "CustomPropertySource",
"CustomPropertyValue",
"CustomerJourney",
"CustomerProfileConfig",
diff --git a/products/customer_analytics/backend/models/custom_property_source.py b/products/customer_analytics/backend/models/custom_property_source.py
new file mode 100644
index 000000000000..0c306a6c9862
--- /dev/null
+++ b/products/customer_analytics/backend/models/custom_property_source.py
@@ -0,0 +1,27 @@
+from django.db import models
+
+from posthog.models.scoping.root_mixin import TeamScopedRootMixin
+from posthog.models.utils import CreatedMetaFields, UpdatedMetaFields, UUIDModel
+
+
+class CustomPropertySource(TeamScopedRootMixin, UUIDModel, CreatedMetaFields, UpdatedMetaFields):
+ team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, db_constraint=False)
+ created_by = models.ForeignKey(
+ "posthog.User", on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False
+ )
+
+ definition = models.OneToOneField(
+ "customer_analytics.CustomPropertyDefinition", on_delete=models.CASCADE, related_name="source"
+ )
+ saved_query = models.ForeignKey(
+ "data_modeling.DataWarehouseSavedQuery", on_delete=models.SET_NULL, null=True, related_name="+"
+ )
+
+ source_column = models.CharField(max_length=400)
+ key_column = models.CharField(max_length=400)
+
+ is_enabled = models.BooleanField(default=True)
+ consecutive_failures = models.PositiveIntegerField(default=0)
+
+ last_synced_at = models.DateTimeField(null=True, blank=True)
+ last_sync_error = models.TextField(null=True, blank=True)