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.

fix(hogbox-preview): apply cyclotron node migrations before plugins starts (#113899)

Frank Hamandc2edcdac28e4
diff --git a/tools/hogbox-preview/hogbox_preview/stack.py b/tools/hogbox-preview/hogbox_preview/stack.py
index b55cb007254a..4342c2a287f6 100644
--- a/tools/hogbox-preview/hogbox_preview/stack.py
+++ b/tools/hogbox-preview/hogbox_preview/stack.py
@@ -208,6 +208,8 @@ class PostHogPreviewStack:
# Pass image=None to fall back to the build-from-checkout escape hatch.
IMAGE = "ghcr.io/posthog/posthog:master"
CDP_IMAGE = "ghcr.io/posthog/posthog-node:master"
+ SQLX_MIGRATE_IMAGE = "ghcr.io/posthog/posthog/sqlx-migrate:master"
+ CYCLOTRON_NODE_DATABASE_URL = "postgres://posthog:posthog@db:5432/cyclotron_node"
STATIC_PROXY_IMAGE = "caddy:2-alpine"
STATIC_PROXY_CADDYFILE = "preview-static.Caddyfile"
OTEL_COLLECTOR_CONFIG = "preview-otel-collector.yaml"
@@ -572,7 +574,7 @@ class PostHogPreviewStack:
# The checkout mount from dev-full masks the compiled code in the published image.
" volumes: !override []",
" environment:",
- " - CYCLOTRON_NODE_DATABASE_URL=postgres://posthog:posthog@db:5432/cyclotron_node",
+ f" - CYCLOTRON_NODE_DATABASE_URL={self.CYCLOTRON_NODE_DATABASE_URL}",
" - CDP_REDIS_HOST=redis7",
" - CDP_VALKEY_HOST=valkey",
" - CDP_VALKEY_PORT=6379",
@@ -580,6 +582,15 @@ class PostHogPreviewStack:
" - PERSONHOG_ADDR=personhog-router:50052",
" - PERSONHOG_ENABLED=true",
*_OTEL_ENV,
+ " cyclotron-node-migrate:",
+ f" image: {self.SQLX_MIGRATE_IMAGE}",
+ " profiles:",
+ " - migrate",
+ " command: cyclotron-node",
+ " environment:",
+ f" - CYCLOTRON_NODE_DATABASE_URL={self.CYCLOTRON_NODE_DATABASE_URL}",
+ " volumes:",
+ " - ./rust/cyclotron-node-migrations:/migrations/cyclotron-node-migrations:ro",
]
lines += self._self_capture_services() + self._telemetry_services() + self._celery_worker_service()
# Mirror the bake script's personhog service definitions (hogland
@@ -935,6 +946,12 @@ class PostHogPreviewStack:
name="person-uuid-index",
timeout=900,
)
+ self.backend.run_long(
+ f"{self._compose('run --rm -T cyclotron-node-migrate')} || "
+ 'echo "WARN: cyclotron node migrations failed, so plugins cannot dequeue jobs in this preview" >&2',
+ name="migrate-cyclotron-node",
+ timeout=900,
+ )
self.backend.run_long(
self._compose("run --rm -T web python manage.py migrate_clickhouse"),
name="migrate-clickhouse",
diff --git a/tools/hogbox-preview/tests/test_deep_health.py b/tools/hogbox-preview/tests/test_deep_health.py
index df09786bdd79..444f1e1a0d8f 100644
--- a/tools/hogbox-preview/tests/test_deep_health.py
+++ b/tools/hogbox-preview/tests/test_deep_health.py
@@ -20,6 +20,7 @@ sibling tests.
from __future__ import annotations
+import re
from contextlib import ExitStack
import unittest
@@ -198,6 +199,17 @@ class OverrideTemporalParityTest(unittest.TestCase):
self.assertIn("register_temporal_search_attributes", script)
self.assertIn("WARN", script) # non-fatal fallthrough, not a bare run
+ def test_migrate_applies_the_prs_cyclotron_node_migrations_tolerantly(self):
+ backend = _RecordingBackend()
+ stack = PostHogPreviewStack(backend)
+ stack.write_override()
+ stack.migrate()
+ override = backend.files[f"{stack.repo_dir}/{stack.OVERRIDE}"]
+ migrate_block = re.split(r"\n \S", override.split(" cyclotron-node-migrate:", 1)[1], maxsplit=1)[0]
+ self.assertIn("./rust/cyclotron-node-migrations:/migrations/cyclotron-node-migrations:ro", migrate_block)
+ script = next(run for run in backend.long_runs if "cyclotron-node-migrate" in run)
+ self.assertIn("WARN", script)
+
def test_reset_database_recreates_temporal(self):
# The wiped postgres volume held temporal's DBs, and only temporal's
# auto-setup ENTRYPOINT recreates that schema — so a reset that leaves