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-warehouse): remove inline schema discovery from per-schema sync (#57993)

Marcus Hofed9dd8d32218
diff --git a/posthog/temporal/data_imports/external_data_job.py b/posthog/temporal/data_imports/external_data_job.py
index 875cc4b9d3b6..9c0b1477c35d 100644
--- a/posthog/temporal/data_imports/external_data_job.py
+++ b/posthog/temporal/data_imports/external_data_job.py
@@ -44,10 +44,6 @@ from posthog.temporal.data_imports.workflow_activities.import_data_sync import (
ImportDataActivityInputs,
import_data_activity_sync,
)
-from posthog.temporal.data_imports.workflow_activities.sync_new_schemas import (
- SyncNewSchemasActivityInputs,
- sync_new_schemas_activity,
-)
from posthog.temporal.ducklake.ducklake_copy_data_imports_workflow import (
DataImportsDuckLakeCopyInputs,
DuckLakeCopyDataImportsWorkflow,
@@ -308,18 +304,6 @@ class ExternalDataJobWorkflow(PostHogWorkflow):
update_inputs.status = ExternalDataJob.Status.BILLING_LIMIT_REACHED
return
- await workflow.execute_activity(
- sync_new_schemas_activity,
- SyncNewSchemasActivityInputs(source_id=str(inputs.external_data_source_id), team_id=inputs.team_id),
- start_to_close_timeout=dt.timedelta(minutes=10),
- retry_policy=RetryPolicy(
- initial_interval=dt.timedelta(seconds=10),
- maximum_interval=dt.timedelta(seconds=60),
- maximum_attempts=3,
- non_retryable_error_types=["NotNullViolation", "IntegrityError", "BaseSSHTunnelForwarderError"],
- ),
- )
-
job_inputs = ImportDataActivityInputs(
team_id=inputs.team_id,
run_id=job_id,
diff --git a/posthog/temporal/data_imports/settings.py b/posthog/temporal/data_imports/settings.py
index c42b3ec83566..c2ad6724c66f 100644
--- a/posthog/temporal/data_imports/settings.py
+++ b/posthog/temporal/data_imports/settings.py
@@ -13,7 +13,6 @@ from posthog.temporal.data_imports.external_data_job import (
create_external_data_job_model_activity,
create_source_templates,
import_data_activity_sync,
- sync_new_schemas_activity,
trigger_schedule_buffer_one_activity,
update_external_data_job_model,
)
@@ -27,6 +26,7 @@ from posthog.temporal.data_imports.workflow_activities.emit_signals import (
EmitDataImportSignalsWorkflow,
emit_data_import_signals_activity,
)
+from posthog.temporal.data_imports.workflow_activities.sync_new_schemas import sync_new_schemas_activity
WORKFLOWS = [
ExternalDataJobWorkflow,
diff --git a/posthog/temporal/tests/data_imports/test_end_to_end.py b/posthog/temporal/tests/data_imports/test_end_to_end.py
index bc84b9b33d9d..1dc51fcb4639 100644
--- a/posthog/temporal/tests/data_imports/test_end_to_end.py
+++ b/posthog/temporal/tests/data_imports/test_end_to_end.py
@@ -87,7 +87,11 @@ from posthog.temporal.data_imports.workflow_activities.calculate_table_size impo
CalculateTableSizeActivityInputs,
calculate_table_size_activity,
)
-from posthog.temporal.data_imports.workflow_activities.sync_new_schemas import ExternalDataSourceType
+from posthog.temporal.data_imports.workflow_activities.sync_new_schemas import (
+ ExternalDataSourceType,
+ SyncNewSchemasActivityInputs,
+ sync_new_schemas_activity,
+)
from posthog.temporal.ducklake import ACTIVITIES as DUCKLAKE_ACTIVITIES
from posthog.temporal.ducklake.ducklake_copy_data_imports_workflow import DuckLakeCopyDataImportsWorkflow
from posthog.temporal.utils import ExternalDataWorkflowInputs
@@ -3342,6 +3346,12 @@ async def test_postgres_deleting_schemas(team, postgres_config, postgres_connect
return list(schemas)
+ # Schema discovery now runs on its own per-source schedule — simulate a tick
+ # of that schedule to discover the second table.
+ await sync_to_async(sync_new_schemas_activity)(
+ SyncNewSchemasActivityInputs(source_id=str(inputs.external_data_source_id), team_id=inputs.team_id)
+ )
+
schemas = await get_schemas()
assert len(schemas) == 2
@@ -3351,6 +3361,11 @@ async def test_postgres_deleting_schemas(team, postgres_config, postgres_connect
await _execute_run(str(uuid.uuid4()), inputs, [])
+ # Simulate the next tick of the per-source discovery schedule.
+ await sync_to_async(sync_new_schemas_activity)(
+ SyncNewSchemasActivityInputs(source_id=str(inputs.external_data_source_id), team_id=inputs.team_id)
+ )
+
schemas = await get_schemas()
# It should have soft deleted the unsynced table
@@ -3398,6 +3413,11 @@ async def test_postgres_deleting_schemas_with_pre_synced_data(team, postgres_con
return list(schemas)
+ # Schema discovery now runs on its own per-source schedule — simulate a tick.
+ await sync_to_async(sync_new_schemas_activity)(
+ SyncNewSchemasActivityInputs(source_id=str(inputs.external_data_source_id), team_id=inputs.team_id)
+ )
+
schemas = await get_schemas()
assert len(schemas) == 2
@@ -3405,7 +3425,6 @@ async def test_postgres_deleting_schemas_with_pre_synced_data(team, postgres_con
await postgres_connection.execute("DROP TABLE {schema}.table_1".format(schema=postgres_config["schema"]))
await postgres_connection.commit()
- # Sync the second table - this will trigger `sync_new_schemas_activity`
unsynced_schema_ids = [s.id for s in schemas if s.id != inputs.external_data_schema_id]
assert len(unsynced_schema_ids) == 1
unsynced_schema_id = unsynced_schema_ids[0]
@@ -3420,6 +3439,11 @@ async def test_postgres_deleting_schemas_with_pre_synced_data(team, postgres_con
[],
)
+ # Simulate the next tick of the per-source discovery schedule.
+ await sync_to_async(sync_new_schemas_activity)(
+ SyncNewSchemasActivityInputs(source_id=str(inputs.external_data_source_id), team_id=inputs.team_id)
+ )
+
schemas = await get_schemas()
# Because table_1 has already been synced and we hold data for it, we dont delete the schema
assert len(schemas) == 2