: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
fix(devex): stop dagster CI replaying migrations twice on a schema cache miss (#85352)
Julian Bez4ff9e4d6b1ef
diff --git a/.github/workflows/ci-dagster.yml b/.github/workflows/ci-dagster.ymlindex d711c8b2f351..4dc305646a71 100644--- a/.github/workflows/ci-dagster.yml+++ b/.github/workflows/ci-dagster.yml@@ -414,34 +414,45 @@ jobs:restore-keys: |${{ needs.changes.outputs.schema_cache_key }}- - name: Prime test_posthog and posthog from cached schema (PR)- # Primes both test_posthog (used by pytest --reuse-db) and the prod-style- # posthog db (read by migrate_clickhouse → InstanceSetting). pytest's- # keepdb=True path layers any PR-added migrations on top.- # On cache miss, fall through to a full migrate so migrate_clickhouse works.+ - name: Prime test_posthog from cached schema+ # Treat cache problems as misses; the migrate step below rebuilds the DB+ # whenever this one reports restored=false.+ id: prime-schemaif: ${{ github.event_name == 'pull_request' }}run: |+ echo "restored=false" >> "$GITHUB_OUTPUT"if [ ! -f schema.sql.gz ]; then- echo "::notice::Schema cache miss — falling through to full migrate"- python manage.py migrate+ echo "::notice::Schema cache miss; the migrate step will build test_posthog"exit 0fimkdir -p .postgres-backupsmv schema.sql.gz .postgres-backups/schema-latest.sql.gz- if ! ./bin/hogli db:restore-schema-fresh; then- echo "::warning::Schema restore failed (stale/incompatible cached dump?) — falling through to full migrate"- python manage.py migrate- exit 0+ if ./bin/hogli db:restore-test-db; then+ echo "restored=true" >> "$GITHUB_OUTPUT"+ else+ echo "::warning::Schema restore failed (stale/incompatible cached dump?); the migrate step will build test_posthog"fi- gunzip -c .postgres-backups/schema-latest.sql.gz | \- docker compose -f docker-compose.dev.yml exec -T db psql -q -U posthog posthog- - name: Run Django migrations (master)- # Master pushes don't restore from cache (the artifact-producing run- # is in ci-backend, not here). Run a full migrate so migrate_clickhouse- # can read posthog_instancesetting from a populated posthog db.- if: ${{ github.event_name != 'pull_request' }}- run: python manage.py migrate+ - name: Migrate test_posthog from scratch+ # Any run without a restored schema cache (master pushes, PR cache misses)+ # replays the full migration chain here, in a process that exits before+ # tests: the executor's memory high-water stays resident in whichever+ # process runs it, and pytest must not carry it through the test phase.+ # pytest --reuse-db adopts the DB like the PR prime above; any failure+ # falls back to the in-pytest migrate.+ if: ${{ github.event_name != 'pull_request' || steps.prime-schema.outputs.restored != 'true' }}+ env:+ DATABASE_URL: postgres://posthog:posthog@localhost:5432/test_posthog+ run: |+ admin_psql() { docker compose -f docker-compose.dev.yml exec -T db psql -U posthog postgres "$@"; }+ if ! admin_psql -c "DROP DATABASE IF EXISTS test_posthog;" -c "CREATE DATABASE test_posthog;"; then+ echo "::warning::Could not recreate test_posthog; pytest --reuse-db will run the full migrate itself"+ exit 0+ fi+ if ! python manage.py migrate; then+ echo "::warning::Out-of-process migrate failed; pytest --reuse-db will run the full migrate itself"+ admin_psql -c "DROP DATABASE IF EXISTS test_posthog;" || true+ fi- name: Run persons migrationsrun: |@@ -451,6 +462,11 @@ jobs:sqlx migrate run --source rust/persons_migrations/- name: Run clickhouse migrations+ # Reads posthog_instancesetting through Django, so it needs a migrated+ # Postgres db. test_posthog is the only one this job maintains, which is+ # what ci-mcp.yml and ci-e2e-playwright.yml do with their own single db.+ env:+ DATABASE_URL: postgres://posthog:posthog@localhost:5432/test_posthogrun: python manage.py migrate_clickhouse- name: Restore test durations from cache