: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(warehouse): validate xmin sync type and surface availability (#64723)
Daniel RC21367a7e79f1
diff --git a/products/data_warehouse/backend/api/external_data_schema.py b/products/data_warehouse/backend/api/external_data_schema.pyindex ceb1d3fbc277..c64e93b7120b 100644--- a/products/data_warehouse/backend/api/external_data_schema.py+++ b/products/data_warehouse/backend/api/external_data_schema.py@@ -31,6 +31,7 @@ from products.data_warehouse.backend.data_load.service import (external_data_workflow_exists,is_any_external_data_schema_paused,is_cdc_enabled_for_team,+ is_xmin_enabled_for_team,pause_external_data_schedule,sync_cdc_extraction_schedule,sync_external_data_job_workflow,@@ -181,6 +182,32 @@ def unsupported_row_filter_reason(*, is_direct_postgres: bool, is_cdc: bool) ->return None+def _apply_primary_key_columns(+ data: dict[str, Any],+ payload: dict[str, Any],+ instance: Any,+ label: str,+) -> None:+ """Apply primary_key_columns from request data to the sync_type_config payload.++ Raises ValidationError if the PK changed after data has been synced, or if no PK is set.+ """+ new_pk = data.get("primary_key_columns")+ if new_pk:+ old_pk = payload.get("primary_key_columns")+ if new_pk != old_pk and instance.table is not None:+ raise ValidationError(+ "Primary key cannot be changed after data has been synced. "+ "Delete the synced data first, then change the primary key."+ )+ payload["primary_key_columns"] = new_pk+ elif not payload.get("primary_key_columns"):+ raise ValidationError(+ f"{label} requires a primary key on table '{instance.name}'. "+ "Provide primary_key_columns or refresh schema discovery to pick one up."+ )++class ExternalDataSchemaSerializer(serializers.ModelSerializer):table = serializers.SerializerMethodField(read_only=True)incremental = serializers.SerializerMethodField(read_only=True)@@ -189,7 +216,7 @@ class ExternalDataSchemaSerializer(serializers.ModelSerializer):choices=ExternalDataSchema.SyncType.choices,required=False,allow_null=True,- help_text="Sync strategy: incremental, full_refresh, append, or cdc.",+ help_text="Sync strategy: incremental, full_refresh, append, cdc, or xmin.",)incremental_field = serializers.CharField(required=False, allow_null=True, help_text="Column name used to track sync progress."@@ -510,6 +537,24 @@ class ExternalDataSchemaSerializer(serializers.ModelSerializer):if not is_cdc_enabled_for_team(team):raise ValidationError("CDC is not enabled for this team")+ # Close the enum-exposure window: `XMIN` is a valid `SyncType` choice, so the field accepts+ # "xmin" the moment the foundation lands. Reject it unless the source is Postgres, the flag is+ # on for the team, and the table actually advertises xmin support — otherwise a raw PATCH would+ # persist an xmin schema that silently degrades to full_refresh.+ if sync_type == ExternalDataSchema.SyncType.XMIN:+ from posthog.models import Team++ if instance.source.source_type != ExternalDataSourceType.POSTGRES:+ raise ValidationError("xmin replication is only available for Postgres sources.")+ team = Team.objects.get(id=self.context["team_id"])+ if not is_xmin_enabled_for_team(team):+ raise ValidationError("xmin replication is not enabled for this team")+ if not self._xmin_available_for_schema(instance):+ raise ValidationError(+ f"xmin replication is not available for table '{instance.name}'. "+ "It requires a Postgres heap table or materialized view on PostgreSQL 13+."+ )+# Reject non-webhook sync types for webhook-only schemas (e.g. Stripe Discount —# no API list endpoint, so anything other than webhook produces an empty sync).if "sync_type" in data and sync_type != ExternalDataSchema.SyncType.WEBHOOK:@@ -587,22 +632,15 @@ class ExternalDataSchemaSerializer(serializers.ModelSerializer):# CDC needs a PK for UPDATE/DELETE merges. Accept the caller's PK or reuse what# discovery already stored; refuse the switch when neither is set.- new_pk = data.get("primary_key_columns")- if new_pk:- old_pk = payload.get("primary_key_columns")- # Same rule as incremental: the PK is the merge key, so it can't change once data- # has synced (`instance.table` exists). Delete the synced data to change it.- if new_pk != old_pk and instance.table is not None:- raise ValidationError(- "Primary key cannot be changed after data has been synced. "- "Delete the synced data first, then change the primary key."- )- payload["primary_key_columns"] = new_pk- elif not payload.get("primary_key_columns"):- raise ValidationError(- f"CDC requires a primary key on table '{instance.name}'. "- "Provide primary_key_columns or refresh schema discovery to pick one up."- )+ _apply_primary_key_columns(data, payload, instance, "CDC")++ validated_data["sync_type_config"] = payload+ elif sync_type == ExternalDataSchema.SyncType.XMIN:+ payload = instance.sync_type_config++ # xmin requires a primary key for clean upsert dedup, mirroring CDC. Accept the caller's+ # PK or reuse what discovery already stored; refuse the switch when neither is set.+ _apply_primary_key_columns(data, payload, instance, "xmin replication")validated_data["sync_type_config"] = payloadelse:@@ -818,6 +856,22 @@ class ExternalDataSchemaSerializer(serializers.ModelSerializer):return Falsereturn any(s.name == schema.name and s.webhook_only for s in source_schemas)+ def _xmin_available_for_schema(self, schema: ExternalDataSchema) -> bool:+ """True when the source advertises xmin support for this table (Postgres heap table or+ materialized view, PG13+). Runs discovery so a raw PATCH can't enable xmin on a table that+ has no physical `xmin` (plain views, foreign tables, partitioned parents)."""+ source = schema.source+ if not source.job_inputs:+ return False+ try:+ source_type = ExternalDataSourceType(source.source_type)+ source_impl = SourceRegistry.get_source(source_type)+ config = source_impl.parse_config(source.job_inputs)+ source_schemas = source_impl.get_schemas(config, schema.team_id, names=[schema.name])+ except Exception:+ return False+ return any(s.name == schema.name and s.supports_xmin for s in source_schemas)+def _maybe_create_webhook(self, schema: ExternalDataSchema) -> None:source = schema.sourceif not source.job_inputs:@@ -1144,12 +1198,19 @@ class ExternalDataSchemaViewset(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):# strings, so bool(...) would treat "False" as truthy. str_to_bool decodes both.source_cdc_enabled = str_to_bool(source.job_inputs.get("cdc_enabled"))cdc_available = schema.supports_cdc if is_cdc_enabled_for_team(self.team) and source_cdc_enabled else None+ # xmin is Postgres-only AND flag-gated, mirroring the database_schema endpoint.+ xmin_available = (+ schema.supports_xmin+ if (source.source_type == ExternalDataSourceType.POSTGRES and is_xmin_enabled_for_team(self.team))+ else None+ )data = {"incremental_fields": schema.incremental_fields,"incremental_available": schema.supports_incremental,"append_available": schema.supports_append,"cdc_available": cdc_available,+ "xmin_available": xmin_available,"full_refresh_available": not schema.webhook_only,"supports_webhooks": schema.supports_webhooks,"webhook_only": schema.webhook_only,diff --git a/products/data_warehouse/backend/api/external_data_source.py b/products/data_warehouse/backend/api/external_data_source.pyindex c24673a79a28..06249af83b33 100644--- a/products/data_warehouse/backend/api/external_data_source.py+++ b/products/data_warehouse/backend/api/external_data_source.py@@ -88,6 +88,7 @@ from products.data_warehouse.backend.data_load.service import (ensure_cdc_slot_cleanup_schedule,is_any_external_data_schema_paused,is_cdc_enabled_for_team,+ is_xmin_enabled_for_team,sync_cdc_extraction_schedule,sync_discover_schemas_schedule,sync_external_data_job_workflow,@@ -489,7 +490,7 @@ class ExternalDataSourceBulkUpdateSchemaSerializer(serializers.Serializer):required=False,allow_null=True,choices=ExternalDataSchema.SyncType.choices,- help_text="Requested sync mode for the schema.",+ help_text="Requested sync mode for the schema (incremental, full_refresh, append, cdc, or xmin).",)incremental_field = serializers.CharField(required=False,@@ -2235,6 +2236,9 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi# which makes a network round-trip per call. With large schema lists (e.g. Slack workspaces with# thousands of channels) the per-iteration call inflated the response loop past the 120s gateway.cdc_enabled = is_cdc_enabled_for_team(self.team)+ xmin_enabled = is_xmin_enabled_for_team(self.team)+ # xmin is Postgres-only — gate on the source type so the capability never leaks to another SQL source.+ is_postgres = source_type_model == ExternalDataSourceType.POSTGRESdata = [{"table": schema.name,@@ -2244,6 +2248,7 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi"incremental_available": schema.supports_incremental,"append_available": schema.supports_append,"cdc_available": schema.supports_cdc if cdc_enabled else None,+ "xmin_available": schema.supports_xmin if (is_postgres and xmin_enabled) else None,"incremental_field": schema.incremental_fields[0]["field"]if len(schema.incremental_fields) > 0 and len(schema.incremental_fields[0]["field"]) > 0else None,diff --git a/products/data_warehouse/backend/api/test/test_external_data_schema.py b/products/data_warehouse/backend/api/test/test_external_data_schema.pyindex aa07f5a5ba3b..a1021445f086 100644--- a/products/data_warehouse/backend/api/test/test_external_data_schema.py+++ b/products/data_warehouse/backend/api/test/test_external_data_schema.py@@ -104,6 +104,7 @@ class TestExternalDataSchema(APIBaseTest):"incremental_available": False,"append_available": True,"cdc_available": None,+ "xmin_available": None,"full_refresh_available": True,"supports_webhooks": True,"webhook_only": False,@@ -213,6 +214,7 @@ class TestExternalDataSchema(APIBaseTest):"incremental_available": True,"append_available": True,"cdc_available": None,+ "xmin_available": None,"full_refresh_available": True,"supports_webhooks": False,"webhook_only": False,@@ -287,6 +289,62 @@ class TestExternalDataSchema(APIBaseTest):assert response.status_code == status.HTTP_200_OKassert response.json()["cdc_available"] is expected_cdc_available+ @parameterized.expand(+ [+ # (test name, source_type, supports_xmin, expected_xmin_available)+ ("postgres_capable", ExternalDataSourceType.POSTGRES, True, True),+ ("postgres_not_capable", ExternalDataSourceType.POSTGRES, False, False),+ ("non_postgres_capable", ExternalDataSourceType.MYSQL, True, None),+ ]+ )+ def test_incremental_fields_xmin_available_gating(+ self, _name: str, source_type, supports_xmin: bool, expected_xmin_available+ ):+ # xmin is Postgres-only: the endpoint must report `xmin_available=None` for any other source,+ # even one that erroneously sets `supports_xmin=True`.+ from posthog.temporal.data_imports.sources.mysql.source import MySQLSource+ from posthog.temporal.data_imports.sources.postgres.source import PostgresSource++ source_impl = PostgresSource if source_type == ExternalDataSourceType.POSTGRES else MySQLSource+ source = ExternalDataSource.objects.create(+ team=self.team,+ source_type=source_type,+ job_inputs={"host": "h", "port": 5432, "database": "d", "user": "u", "password": "p", "schema": "public"},+ )+ schema = ExternalDataSchema.objects.create(+ name="some_table",+ team=self.team,+ source=source,+ should_sync=True,+ status=ExternalDataSchema.Status.COMPLETED,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ )++ fake_schema = SourceSchema(+ name="some_table",+ supports_incremental=False,+ supports_append=False,+ supports_xmin=supports_xmin,+ incremental_fields=[],+ columns=[("id", "integer", False)],+ detected_primary_keys=["id"],+ )++ with (+ mock.patch.object(source_impl, "validate_credentials", return_value=(True, None)),+ mock.patch.object(source_impl, "get_schemas", return_value=[fake_schema]),+ mock.patch(+ "products.data_warehouse.backend.api.external_data_schema.is_xmin_enabled_for_team",+ return_value=True,+ ),+ ):+ response = self.client.post(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}/incremental_fields",+ )++ assert response.status_code == status.HTTP_200_OK+ assert response.json()["xmin_available"] is expected_xmin_available+def test_incremental_fields_matches_schema_by_name(self):source = ExternalDataSource.objects.create(team=self.team, source_type=ExternalDataSourceType.STRIPE, job_inputs={"stripe_secret_key": "test_key"}@@ -702,6 +760,222 @@ class TestExternalDataSchema(APIBaseTest):schema.refresh_from_db()assert schema.sync_type_config["primary_key_columns"] == ["id"]+ def _xmin_postgres_source(self) -> ExternalDataSource:+ return ExternalDataSource.objects.create(+ team=self.team,+ source_type=ExternalDataSourceType.POSTGRES,+ job_inputs={"host": "h", "port": 5432, "database": "d", "user": "u", "password": "p", "schema": "public"},+ )++ @staticmethod+ def _xmin_discovery_patches(supports_xmin: bool = True, flag_enabled: bool = True):+ from posthog.temporal.data_imports.sources.postgres.source import PostgresSource++ fake_schema = SourceSchema(+ name="public.orders",+ supports_incremental=False,+ supports_append=False,+ supports_xmin=supports_xmin,+ incremental_fields=[],+ columns=[("id", "integer", False)],+ detected_primary_keys=["id"],+ )+ return (+ mock.patch.object(PostgresSource, "get_schemas", return_value=[fake_schema]),+ mock.patch(+ "products.data_warehouse.backend.api.external_data_schema.is_xmin_enabled_for_team",+ return_value=flag_enabled,+ ),+ )++ def test_update_schema_to_xmin_succeeds_with_primary_key(self):+ source = self._xmin_postgres_source()+ schema = ExternalDataSchema.objects.create(+ name="public.orders",+ team=self.team,+ source=source,+ should_sync=False,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ sync_type_config={},+ )++ get_schemas_patch, flag_patch = self._xmin_discovery_patches()+ with get_schemas_patch, flag_patch:+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"sync_type": "xmin", "primary_key_columns": ["id"]},+ )++ assert response.status_code == status.HTTP_200_OK, response.content+ schema.refresh_from_db()+ assert schema.sync_type == ExternalDataSchema.SyncType.XMIN+ assert schema.sync_type_config["primary_key_columns"] == ["id"]+ # xmin never sets CDC state.+ assert "cdc_mode" not in schema.sync_type_config++ def test_update_schema_to_xmin_rejected_without_primary_key(self):+ source = self._xmin_postgres_source()+ schema = ExternalDataSchema.objects.create(+ name="public.orders",+ team=self.team,+ source=source,+ should_sync=False,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ sync_type_config={},+ )++ get_schemas_patch, flag_patch = self._xmin_discovery_patches()+ with get_schemas_patch, flag_patch:+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"sync_type": "xmin"},+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST+ assert "primary key" in str(response.json()).lower()+ schema.refresh_from_db()+ assert schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH++ def test_update_schema_to_xmin_rejected_for_non_postgres(self):+ source = ExternalDataSource.objects.create(+ team=self.team,+ source_type=ExternalDataSourceType.MYSQL,+ job_inputs={"host": "h", "port": 3306, "database": "d", "user": "u", "password": "p", "schema": "public"},+ )+ schema = ExternalDataSchema.objects.create(+ name="public.orders",+ team=self.team,+ source=source,+ should_sync=False,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ sync_type_config={"primary_key_columns": ["id"]},+ )++ with mock.patch(+ "products.data_warehouse.backend.api.external_data_schema.is_xmin_enabled_for_team",+ return_value=True,+ ):+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"sync_type": "xmin", "primary_key_columns": ["id"]},+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST+ assert "postgres" in str(response.json()).lower()+ schema.refresh_from_db()+ assert schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH++ def test_update_schema_to_xmin_rejected_when_table_not_capable(self):+ # A plain view / partitioned parent reports supports_xmin=False — reject even with a PK.+ source = self._xmin_postgres_source()+ schema = ExternalDataSchema.objects.create(+ name="public.orders",+ team=self.team,+ source=source,+ should_sync=False,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ sync_type_config={"primary_key_columns": ["id"]},+ )++ get_schemas_patch, flag_patch = self._xmin_discovery_patches(supports_xmin=False)+ with get_schemas_patch, flag_patch:+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"sync_type": "xmin", "primary_key_columns": ["id"]},+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST+ assert "not available" in str(response.json()).lower()+ schema.refresh_from_db()+ assert schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH++ def test_update_schema_to_xmin_rejected_when_flag_disabled(self):+ source = self._xmin_postgres_source()+ schema = ExternalDataSchema.objects.create(+ name="public.orders",+ team=self.team,+ source=source,+ should_sync=False,+ sync_type=ExternalDataSchema.SyncType.FULL_REFRESH,+ sync_type_config={"primary_key_columns": ["id"]},+ )++ get_schemas_patch, flag_patch = self._xmin_discovery_patches(flag_enabled=False)+ with get_schemas_patch, flag_patch:+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"sync_type": "xmin", "primary_key_columns": ["id"]},+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST+ assert "not enabled" in str(response.json()).lower()+ schema.refresh_from_db()+ assert schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH++ def test_update_schema_xmin_accepts_row_filters(self):+ source = self._xmin_postgres_source()+ schema = ExternalDataSchema.objects.create(+ name="public.orders",+ team=self.team,+ source=source,+ should_sync=False,+ sync_type=ExternalDataSchema.SyncType.XMIN,+ sync_type_config={+ "primary_key_columns": ["id"],+ "schema_metadata": {"columns": [{"name": "id", "data_type": "integer", "is_nullable": False}]},+ },+ )++ get_schemas_patch, flag_patch = self._xmin_discovery_patches()+ with get_schemas_patch, flag_patch:+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"row_filters": [{"column": "id", "operator": ">", "value": "5"}]},+ format="json",+ )++ assert response.status_code == status.HTTP_200_OK, response.content+ schema.refresh_from_db()+ assert schema.row_filters == [{"column": "id", "operator": ">", "value": "5"}]++ @parameterized.expand(+ [+ ("one_minute_rejected", "1min", 400),+ ("five_minute_accepted", "5min", 200),+ ]+ )+ def test_update_schema_xmin_floors_at_five_minutes(self, _name, sync_frequency, expected_status):+ # xmin does not get CDC's 1-minute cadence — it floors at the normal 5-minute incremental cadence.+ source = self._xmin_postgres_source()+ schema = ExternalDataSchema.objects.create(+ name="public.orders",+ team=self.team,+ source=source,+ should_sync=True,+ status=ExternalDataSchema.Status.COMPLETED,+ sync_type=ExternalDataSchema.SyncType.XMIN,+ sync_type_config={"primary_key_columns": ["id"]},+ )++ get_schemas_patch, flag_patch = self._xmin_discovery_patches()+ with (+ get_schemas_patch,+ flag_patch,+ mock.patch(+ "products.data_warehouse.backend.api.external_data_schema.external_data_workflow_exists",+ return_value=False,+ ),+ mock.patch("products.data_warehouse.backend.api.external_data_schema.sync_external_data_job_workflow"),+ ):+ response = self.client.patch(+ f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",+ data={"sync_type": "xmin", "primary_key_columns": ["id"], "sync_frequency": sync_frequency},+ )++ assert response.status_code == expected_status, response.content+ if expected_status == 400:+ assert "1-minute" in str(response.json()).lower() or "cdc" in str(response.json()).lower()+@parameterized.expand([("incremental", ExternalDataSchema.SyncType.INCREMENTAL, 400),diff --git a/products/data_warehouse/backend/api/test/test_external_data_source.py b/products/data_warehouse/backend/api/test/test_external_data_source.pyindex 6a65a1289c1b..5d90c3da5164 100644--- a/products/data_warehouse/backend/api/test/test_external_data_source.py+++ b/products/data_warehouse/backend/api/test/test_external_data_source.py@@ -3447,6 +3447,57 @@ class TestExternalDataSource(APIBaseTest):validate.assert_called_once()self.assertEqual(validate.call_args.args[2], "direct")+ @parameterized.expand(+ [+ # (test name, source_type, supports_xmin, expected_xmin_available)+ ("postgres_capable", "Postgres", True, True),+ ("postgres_not_capable", "Postgres", False, False),+ ("non_postgres", "MySQL", True, None),+ ]+ )+ @patch("products.data_warehouse.backend.api.external_data_source.SourceRegistry.get_source")+ def test_database_schema_xmin_available_gating(+ self, _name, source_type, supports_xmin, expected_xmin_available, mock_get_source+ ):+ # xmin is Postgres-only: the discovery response reports `xmin_available=None` for any other+ # source, regardless of the (erroneous) per-schema `supports_xmin` flag.+ from posthog.temporal.data_imports.sources.mysql.source import MySQLSource++ source = PostgresSource() if source_type == "Postgres" else MySQLSource()+ mock_get_source.return_value = source++ fake_schema = SourceSchema(+ name="public.accounts",+ supports_incremental=False,+ supports_append=False,+ supports_xmin=supports_xmin,+ columns=[("id", "integer", False)],+ foreign_keys=[],+ )++ with (+ patch.object(source, "validate_credentials_for_access_method", return_value=(True, None)),+ patch.object(source, "get_schemas", return_value=[fake_schema]),+ patch(+ "products.data_warehouse.backend.api.external_data_source.is_xmin_enabled_for_team", return_value=True+ ),+ ):+ response = self.client.post(+ f"/api/environments/{self.team.pk}/external_data_sources/database_schema/",+ data={+ "source_type": source_type,+ "host": "localhost",+ "port": 5432,+ "database": "app",+ "user": "user",+ "password": "pass",+ "schema": "public",+ },+ )++ self.assertEqual(response.status_code, status.HTTP_200_OK)+ self.assertIs(response.json()[0]["xmin_available"], expected_xmin_available)+def test_database_schema(self):postgres_connection = psycopg.connect(host=settings.PG_HOST,@@ -3742,6 +3793,7 @@ class TestExternalDataSource(APIBaseTest):"incremental_available": True,"append_available": True,"cdc_available": None,+ "xmin_available": None,"incremental_field": "id","sync_type": None,"supports_webhooks": False,@@ -3812,6 +3864,7 @@ class TestExternalDataSource(APIBaseTest):"incremental_available": True,"append_available": True,"cdc_available": None,+ "xmin_available": None,"incremental_field": "id","sync_type": None,"supports_webhooks": False,diff --git a/products/data_warehouse/backend/data_load/service.py b/products/data_warehouse/backend/data_load/service.pyindex 441324c0e8ca..e6efa5a08453 100644--- a/products/data_warehouse/backend/data_load/service.py+++ b/products/data_warehouse/backend/data_load/service.py@@ -400,6 +400,17 @@ def is_cdc_enabled_for_team(team: Team) -> bool:)+def is_xmin_enabled_for_team(team: Team) -> bool:+ import posthoganalytics++ return posthoganalytics.feature_enabled(+ "dwh-postgres-xmin",+ str(team.organization_id),+ groups={"organization": str(team.organization_id)},+ group_properties={"organization": {"id": str(team.organization_id)}},+ )++# ---------------------------------------------------------------------------# CDC extraction scheduling (source-level)# ---------------------------------------------------------------------------diff --git a/products/warehouse_sources/frontend/generated/api.schemas.ts b/products/warehouse_sources/frontend/generated/api.schemas.tsindex 1e5e0e13a5d7..05d4e79e913e 100644--- a/products/warehouse_sources/frontend/generated/api.schemas.ts+++ b/products/warehouse_sources/frontend/generated/api.schemas.ts@@ -138,7 +138,7 @@ export interface ExternalDataSchemaApi {readonly incremental: boolean/** @nullable */readonly status: string | null- /** Sync strategy: incremental, full_refresh, append, or cdc.+ /** Sync strategy: incremental, full_refresh, append, cdc, or xmin.** * `full_refresh` - full_refresh* * `incremental` - incremental@@ -278,7 +278,7 @@ export interface PatchedExternalDataSchemaApi {readonly incremental?: boolean/** @nullable */readonly status?: string | null- /** Sync strategy: incremental, full_refresh, append, or cdc.+ /** Sync strategy: incremental, full_refresh, append, cdc, or xmin.** * `full_refresh` - full_refresh* * `incremental` - incremental@@ -2463,7 +2463,7 @@ export interface ExternalDataSourceBulkUpdateSchemaApi {id: string/** Whether the schema should be queryable/synced. */should_sync?: boolean- /** Requested sync mode for the schema.+ /** Requested sync mode for the schema (incremental, full_refresh, append, cdc, or xmin).** * `full_refresh` - full_refresh* * `incremental` - incrementaldiff --git a/products/warehouse_sources/frontend/generated/api.zod.ts b/products/warehouse_sources/frontend/generated/api.zod.tsindex 253eceda4cea..c55e1a935be4 100644--- a/products/warehouse_sources/frontend/generated/api.zod.ts+++ b/products/warehouse_sources/frontend/generated/api.zod.ts@@ -25,7 +25,7 @@ export const ExternalDataSchemasCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -127,7 +127,7 @@ export const ExternalDataSchemasUpdateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -229,7 +229,7 @@ export const ExternalDataSchemasPartialUpdateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -331,7 +331,7 @@ export const ExternalDataSchemasCancelCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -433,7 +433,7 @@ export const ExternalDataSchemasIncrementalFieldsCreateBody = /* @__PURE__ */ zo]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -535,7 +535,7 @@ export const ExternalDataSchemasReloadCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -637,7 +637,7 @@ export const ExternalDataSchemasResyncCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -1467,7 +1467,7 @@ export const ExternalDataSourcesBulkUpdateSchemasPartialUpdateBody = /* @__PURE_]).optional().describe(- 'Requested sync mode for the schema.\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'+ 'Requested sync mode for the schema (incremental, full_refresh, append, cdc, or xmin).\n\n\* `full_refresh` - full_refresh\n\* `incremental` - incremental\n\* `append` - append\n\* `webhook` - webhook\n\* `cdc` - cdc\n\* `xmin` - xmin'),incremental_field: zod.string()diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 79e43a382e01..3dfa967ebdef 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -21108,7 +21108,7 @@ export namespace Schemas {readonly incremental: boolean;/** @nullable */readonly status: string | null;- /** Sync strategy: incremental, full_refresh, append, or cdc.+ /** Sync strategy: incremental, full_refresh, append, cdc, or xmin.** * `full_refresh` - full_refresh* * `incremental` - incremental@@ -21203,7 +21203,7 @@ export namespace Schemas {id: string;/** Whether the schema should be queryable/synced. */should_sync?: boolean;- /** Requested sync mode for the schema.+ /** Requested sync mode for the schema (incremental, full_refresh, append, cdc, or xmin).** * `full_refresh` - full_refresh* * `incremental` - incremental@@ -35446,7 +35446,7 @@ export namespace Schemas {readonly incremental?: boolean;/** @nullable */readonly status?: string | null;- /** Sync strategy: incremental, full_refresh, append, or cdc.+ /** Sync strategy: incremental, full_refresh, append, cdc, or xmin.** * `full_refresh` - full_refresh* * `incremental` - incrementaldiff --git a/services/mcp/src/generated/warehouse_sources/api.ts b/services/mcp/src/generated/warehouse_sources/api.tsindex 4cbb9f3096ed..bb48b64e9076 100644--- a/services/mcp/src/generated/warehouse_sources/api.ts+++ b/services/mcp/src/generated/warehouse_sources/api.ts@@ -56,7 +56,7 @@ export const ExternalDataSchemasPartialUpdateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -167,7 +167,7 @@ export const ExternalDataSchemasCancelCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -287,7 +287,7 @@ export const ExternalDataSchemasIncrementalFieldsCreateBody = /* @__PURE__ */ zo]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -398,7 +398,7 @@ export const ExternalDataSchemasReloadCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zod@@ -509,7 +509,7 @@ export const ExternalDataSchemasResyncCreateBody = /* @__PURE__ */ zod.object({]).optional().describe(- 'Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'+ 'Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin'),incremental_field: zod.string().nullish().describe('Column name used to track sync progress.'),incremental_field_type: zoddiff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-cancel.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-cancel.jsonindex 807d7db27c1b..acaf51db5225 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-cancel.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-cancel.json@@ -161,7 +161,7 @@"type": "null"}],- "description": "Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"+ "description": "Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"}},"required": ["id"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-incremental-fields-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-incremental-fields-create.jsonindex 807d7db27c1b..acaf51db5225 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-incremental-fields-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-incremental-fields-create.json@@ -161,7 +161,7 @@"type": "null"}],- "description": "Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"+ "description": "Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"}},"required": ["id"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-partial-update.jsonindex 807d7db27c1b..acaf51db5225 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-partial-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-partial-update.json@@ -161,7 +161,7 @@"type": "null"}],- "description": "Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"+ "description": "Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"}},"required": ["id"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-reload.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-reload.jsonindex 807d7db27c1b..acaf51db5225 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-reload.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-reload.json@@ -161,7 +161,7 @@"type": "null"}],- "description": "Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"+ "description": "Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"}},"required": ["id"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-resync.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-resync.jsonindex 807d7db27c1b..acaf51db5225 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-resync.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/external-data-schemas-resync.json@@ -161,7 +161,7 @@"type": "null"}],- "description": "Sync strategy: incremental, full_refresh, append, or cdc.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"+ "description": "Sync strategy: incremental, full_refresh, append, cdc, or xmin.\n\n* `full_refresh` - full_refresh\n* `incremental` - incremental\n* `append` - append\n* `webhook` - webhook\n* `cdc` - cdc\n* `xmin` - xmin"}},"required": ["id"],