: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(ci): fall back to newest schema dump when exact cache keys miss (#85645)
Georges-Antoine Assic4c1b930a1a2
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 05dbb64ed33f..2b52610fcde8 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -501,6 +501,7 @@ jobs:matrix: ${{ steps.discover.outputs.matrix }}schema_cache_key: ${{ steps.schema-key.outputs.key }}schema_migrations_key: ${{ steps.schema-key.outputs.migrations_key }}+ schema_prefix_key: ${{ steps.schema-key.outputs.prefix_key }}django_shards: ${{ steps.discover.outputs.django_shards }}steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2@@ -542,6 +543,16 @@ jobs:fi# Exact branch-point key, kept as the fallback restore key below.echo "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUT+ # Last-resort restore prefix: matches the newest saved dump of any+ # migration set, for the window where both exact keys miss. Gated on+ # checkout age (a day) because a re-run of an old run keeps its original+ # commit: a stale checkout can lack migrations the newest dump records,+ # and the migrate top-ups only apply forward, so they cannot repair a+ # dump that is newer than the code.+ HEAD_AGE_SECONDS=$(( $(date +%s) - $(git show -s --format=%ct HEAD) ))+ if [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then+ echo "prefix_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-" >> $GITHUB_OUTPUT+ fi# Shared key: hash merge-base schema inputs, not PR head, so PR migrations still# apply as the pytest delta. uv.lock covers third-party migration changes; the# postgres image is folded in so a server-version bump invalidates the key.@@ -987,10 +998,15 @@ jobs:uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3with:path: schema.sql.gz- # Prefer the shared content key; fall back to the exact merge-base SHA key.+ # Prefer the shared content key; fall back to the exact merge-base SHA key,+ # then to the newest dump of any migration set. Right after a migration+ # lands on master both exact keys miss until ci-backend re-dumps, and a+ # from-scratch migrate costs ~17 minutes per shard; pytest's keepdb+ # migrate tops a slightly stale dump up in seconds instead.key: ${{ needs.turbo-discover.outputs.schema_migrations_key || needs.turbo-discover.outputs.schema_cache_key }}restore-keys: |${{ needs.turbo-discover.outputs.schema_cache_key }}+ ${{ needs.turbo-discover.outputs.schema_prefix_key }}- 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.@@ -1935,10 +1951,15 @@ jobs:uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3with:path: schema.sql.gz- # Prefer the shared content key; fall back to the exact merge-base SHA key.+ # Prefer the shared content key; fall back to the exact merge-base SHA key,+ # then to the newest dump of any migration set. Right after a migration+ # lands on master both exact keys miss until ci-backend re-dumps, and a+ # from-scratch migrate costs ~17 minutes per shard; pytest's keepdb+ # migrate tops a slightly stale dump up in seconds instead.key: ${{ needs.turbo-discover.outputs.schema_migrations_key || needs.turbo-discover.outputs.schema_cache_key }}restore-keys: |${{ needs.turbo-discover.outputs.schema_cache_key }}+ ${{ needs.turbo-discover.outputs.schema_prefix_key }}- 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.diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 0fc12a44455f..7448a1bf3629 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -397,6 +397,7 @@ jobs:matrix: ${{ steps.discover.outputs.matrix }}schema_cache_key: ${{ steps.schema-key.outputs.key }}schema_migrations_key: ${{ steps.schema-key.outputs.migrations_key }}+ schema_prefix_key: ${{ steps.schema-key.outputs.prefix_key }}django_shards: ${{ steps.discover.outputs.django_shards }}steps:@@ -441,6 +442,16 @@ jobs:fi# Exact branch-point key, kept as the fallback restore key below.echo "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUT+ # Last-resort restore prefix: matches the newest saved dump of any+ # migration set, for the window where both exact keys miss. Gated on+ # checkout age (a day) because a re-run of an old run keeps its original+ # commit: a stale checkout can lack migrations the newest dump records,+ # and the migrate top-ups only apply forward, so they cannot repair a+ # dump that is newer than the code.+ HEAD_AGE_SECONDS=$(( $(date +%s) - $(git show -s --format=%ct HEAD) ))+ if [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then+ echo "prefix_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-" >> $GITHUB_OUTPUT+ fi# Shared key: hash merge-base schema inputs, not PR head, so PR migrations still# apply as the pytest delta. uv.lock covers third-party migration changes; the# postgres image is folded in so a server-version bump invalidates the key.@@ -983,10 +994,15 @@ jobs:uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3with:path: schema.sql.gz- # Prefer the shared content key; fall back to the exact merge-base SHA key.+ # Prefer the shared content key; fall back to the exact merge-base SHA key,+ # then to the newest dump of any migration set. Right after a migration+ # lands on master both exact keys miss until ci-backend re-dumps, and a+ # from-scratch migrate costs ~17 minutes per shard; pytest's keepdb+ # migrate tops a slightly stale dump up in seconds instead.key: ${{ needs.turbo-discover.outputs.schema_migrations_key || needs.turbo-discover.outputs.schema_cache_key }}restore-keys: |${{ needs.turbo-discover.outputs.schema_cache_key }}+ ${{ needs.turbo-discover.outputs.schema_prefix_key }}- name: Prime test_posthog from cached schema# Treat cache problems as misses; the migrate step below rebuilds the DB@@ -2944,10 +2960,15 @@ jobs:uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3with:path: schema.sql.gz- # Prefer the shared content key; fall back to the exact merge-base SHA key.+ # Prefer the shared content key; fall back to the exact merge-base SHA key,+ # then to the newest dump of any migration set. Right after a migration+ # lands on master both exact keys miss until ci-backend re-dumps, and a+ # from-scratch migrate costs ~17 minutes per shard; pytest's keepdb+ # migrate tops a slightly stale dump up in seconds instead.key: ${{ needs.turbo-discover.outputs.schema_migrations_key || needs.turbo-discover.outputs.schema_cache_key }}restore-keys: |${{ needs.turbo-discover.outputs.schema_cache_key }}+ ${{ needs.turbo-discover.outputs.schema_prefix_key }}- name: Prime test_posthog from cached schema# Treat cache problems as misses; the migrate step below rebuilds the DBdiff --git a/.github/workflows/ci-dagster.yml b/.github/workflows/ci-dagster.ymlindex 4dc305646a71..5c26c90f570f 100644--- a/.github/workflows/ci-dagster.yml+++ b/.github/workflows/ci-dagster.yml@@ -76,6 +76,7 @@ jobs:matrix_include: ${{ steps.build-matrix.outputs.include || '[]' }}schema_cache_key: ${{ steps.schema-key.outputs.key }}schema_migrations_key: ${{ steps.schema-key.outputs.migrations_key }}+ schema_prefix_key: ${{ steps.schema-key.outputs.prefix_key }}steps:# For pull requests it's not necessary to checkout the code, but we# also want this to run on master so we need to checkout.@@ -278,6 +279,16 @@ jobs:exit 0fiecho "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUT+ # Last-resort restore prefix: matches the newest saved dump of any+ # migration set, for the window where both exact keys miss. Gated on+ # checkout age (a day) because a re-run of an old run keeps its original+ # commit: a stale checkout can lack migrations the newest dump records,+ # and the migrate top-ups only apply forward, so they cannot repair a+ # dump that is newer than the code.+ HEAD_AGE_SECONDS=$(( $(date +%s) - $(git show -s --format=%ct HEAD) ))+ if [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then+ echo "prefix_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-" >> $GITHUB_OUTPUT+ fi# Shared migration-set key. Must match ci-backend.yml's save-side computation byte for byte or it never hits.MIG_FILES=$(git ls-tree -r --format='%(objectname) %(path)' "$MERGE_BASE" \| grep -E '/migrations/[^/]+\.py$|^[0-9a-f]+ uv\.lock$' \@@ -409,10 +420,16 @@ jobs:id: schema-cachewith:path: schema.sql.gz- # Prefer the shared content key; fall back to the exact merge-base SHA key.+ # Prefer the shared content key; fall back to the exact merge-base SHA key,+ # then to the newest dump of any migration set. Right after a migration+ # lands on master both exact keys miss until ci-backend re-dumps, and the+ # full-migrate fallthrough (~17 min) has blown this job's 40-minute budget+ # before; pytest's keepdb migrate tops a slightly stale dump up in seconds,+ # the same way it already layers PR-added migrations.key: ${{ needs.changes.outputs.schema_migrations_key || needs.changes.outputs.schema_cache_key }}restore-keys: |${{ needs.changes.outputs.schema_cache_key }}+ ${{ needs.changes.outputs.schema_prefix_key }}- name: Prime test_posthog from cached schema# Treat cache problems as misses; the migrate step below rebuilds the DBdiff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.ymlindex 06702f2e9d4d..fdb74784822d 100644--- a/.github/workflows/ci-e2e-playwright.yml+++ b/.github/workflows/ci-e2e-playwright.yml@@ -92,6 +92,7 @@ jobs:oldest_supported: ${{ steps.read-versions.outputs.oldest_supported }}schema_cache_key: ${{ steps.schema-key.outputs.key }}schema_migrations_key: ${{ steps.schema-key.outputs.migrations_key }}+ schema_prefix_key: ${{ steps.schema-key.outputs.prefix_key }}steps:# fetch-depth=1000 + blob:none mirrors ci-backend / ci-dagster so HEAD^2# (PR branch tip) is reachable for the merge-base step below without the@@ -310,6 +311,16 @@ jobs:echo "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUTREF="$MERGE_BASE"fi+ # Last-resort restore prefix: matches the newest saved dump of any+ # migration set, for the window where both exact keys miss. Gated on+ # checkout age (a day) because a re-run of an old run keeps its original+ # commit: a stale checkout can lack migrations the newest dump records,+ # and the migrate top-ups only apply forward, so they cannot repair a+ # dump that is newer than the code.+ HEAD_AGE_SECONDS=$(( $(date +%s) - $(git show -s --format=%ct HEAD) ))+ if [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then+ echo "prefix_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-" >> $GITHUB_OUTPUT+ fi# Shared migration-set key: mirrors the save-side computation in# ci-backend.yml (same inputs, hash, and prefix) so it hits whenever# the ref's migration files match a saved master schema — far more@@ -768,7 +779,10 @@ jobs:# PRs and master pushes alike. Both keys are produced by ci-backend on# master push. Prefer the shared migration-set key (stable while master's# migration files are unchanged); fall back to the exact merge-base SHA key- # (PRs only). Cache miss falls through to a full migrate below.+ # (PRs only), then to the newest dump of any migration set — right after a+ # migration lands on master both exact keys miss until ci-backend re-dumps,+ # and the migrate step below tops a slightly stale dump up in seconds.+ # Cache miss falls through to a full migrate below.if: (github.event_name == 'pull_request' || github.event_name == 'push') && (needs.changes.outputs.schema_migrations_key != '' || needs.changes.outputs.schema_cache_key != '')uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3id: schema-cache@@ -777,6 +791,7 @@ jobs:key: ${{ needs.changes.outputs.schema_migrations_key || needs.changes.outputs.schema_cache_key }}restore-keys: |${{ needs.changes.outputs.schema_cache_key }}+ ${{ needs.changes.outputs.schema_prefix_key }}- name: Prime posthog_e2e_test from cached schema# Schema dump is from master's `posthog` db but schemas are db-name agnostic.diff --git a/.github/workflows/ci-mcp.yml b/.github/workflows/ci-mcp.ymlindex 2899c311ef55..dac3bbf1bb47 100644--- a/.github/workflows/ci-mcp.yml+++ b/.github/workflows/ci-mcp.yml@@ -493,6 +493,16 @@ jobs:exit 0fiecho "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUT+ # Last-resort restore prefix: matches the newest saved dump of any+ # migration set, for the window where both exact keys miss. Gated on+ # checkout age (a day) because a re-run of an old run keeps its original+ # commit: a stale checkout can lack migrations the newest dump records,+ # and the migrate top-ups only apply forward, so they cannot repair a+ # dump that is newer than the code.+ HEAD_AGE_SECONDS=$(( $(date +%s) - $(git show -s --format=%ct HEAD) ))+ if [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then+ echo "prefix_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-" >> $GITHUB_OUTPUT+ fi# Shared migration-set key. Must match ci-backend.yml's save-side computation byte for byte or it never hits.MIG_FILES=$(git ls-tree -r --format='%(objectname) %(path)' "$MERGE_BASE" \| grep -E '/migrations/[^/]+\.py$|^[0-9a-f]+ uv\.lock$' \@@ -513,10 +523,15 @@ jobs:uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3with:path: schema.sql.gz- # Prefer the shared content key; fall back to the exact merge-base SHA key.+ # Prefer the shared content key; fall back to the exact merge-base SHA key,+ # then to the newest dump of any migration set. Right after a migration+ # lands on master both exact keys miss until ci-backend re-dumps; the+ # migrate step below tops a slightly stale dump up in seconds instead of+ # replaying the full history.key: ${{ steps.schema-key.outputs.migrations_key || steps.schema-key.outputs.key }}restore-keys: |${{ steps.schema-key.outputs.key }}+ ${{ steps.schema-key.outputs.prefix_key }}- name: Prime posthog from cached schema# No-op on cache miss; manage.py migrate below falls back to a full migrate.diff --git a/.github/workflows/ci-rust-flags-integration.yml b/.github/workflows/ci-rust-flags-integration.ymlindex 27a693fb77f2..1f28fdf1134b 100644--- a/.github/workflows/ci-rust-flags-integration.yml+++ b/.github/workflows/ci-rust-flags-integration.yml@@ -155,6 +155,16 @@ jobs:exit 0fiecho "key=posthog-schema-master-${MERGE_BASE}" >> $GITHUB_OUTPUT+ # Last-resort restore prefix: matches the newest saved dump of any+ # migration set, for the window where both exact keys miss. Gated on+ # checkout age (a day) because a re-run of an old run keeps its original+ # commit: a stale checkout can lack migrations the newest dump records,+ # and the migrate top-ups only apply forward, so they cannot repair a+ # dump that is newer than the code.+ HEAD_AGE_SECONDS=$(( $(date +%s) - $(git show -s --format=%ct HEAD) ))+ if [ "$HEAD_AGE_SECONDS" -lt 86400 ]; then+ echo "prefix_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-" >> $GITHUB_OUTPUT+ fi# Must match ci-backend.yml's save-side computation byte for byte or the key never hits.MIG_FILES=$(git ls-tree -r --format='%(objectname) %(path)' "$MERGE_BASE" \| grep -E '/migrations/[^/]+\.py$|^[0-9a-f]+ uv\.lock$' \@@ -175,9 +185,15 @@ jobs:uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3with:path: schema.sql.gz+ # Prefer the shared content key; fall back to the exact merge-base SHA key,+ # then to the newest dump of any migration set. Right after a migration+ # lands on master both exact keys miss until ci-backend re-dumps; the+ # migrate step below tops a slightly stale dump up in seconds instead of+ # replaying the full history.key: ${{ steps.schema-key.outputs.migrations_key || steps.schema-key.outputs.key }}restore-keys: |${{ steps.schema-key.outputs.key }}+ ${{ steps.schema-key.outputs.prefix_key }}- name: Prime test_posthog from cached schema# hogli db:restore-test-db is unusable here: it shells into the docker compose db service.