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.

perf(tests): skip django migrate on sqlx-managed persons test db (#60167)

Raúl Negrón-Oterob00676b3f3d0
diff --git a/posthog/settings/data_stores.py b/posthog/settings/data_stores.py
index c9f733a46624..46f1824c0774 100644
--- a/posthog/settings/data_stores.py
+++ b/posthog/settings/data_stores.py
@@ -173,6 +173,16 @@ if persons_db_writer_url:
DATABASES["persons_db_writer"]["DISABLE_SERVER_SIDE_CURSORS"] = True
DATABASES["persons_db_reader"]["DISABLE_SERVER_SIDE_CURSORS"] = True
+ if TEST:
+ # The persons DB schema is built by sqlx (rust/persons_migrations), not Django —
+ # PersonDBRouter.allow_migrate blocks every Django migration on it. Without MIGRATE=False,
+ # pytest-django's setup_databases still walks and records all ~1,300 Django migrations
+ # against the empty persons test database on every shard (~300s of pure overhead, scaling
+ # with migration count), even though the router skips the actual DDL. Skipping migrate here
+ # leaves conftest.run_persons_sqlx_migrations to build the real schema.
+ DATABASES["persons_db_writer"]["TEST"] = {"MIGRATE": False, "DEPENDENCIES": []}
+ DATABASES["persons_db_reader"]["TEST"] = {"MIRROR": "persons_db_writer"}
+
DATABASE_ROUTERS.insert(0, "posthog.person_db_router.PersonDBRouter")