fix(db): tolerate missing workers column in benchmark read queries#407
Open
arygupt wants to merge 1 commit into
Open
fix(db): tolerate missing workers column in benchmark read queries#407arygupt wants to merge 1 commit into
arygupt wants to merge 1 commit into
Conversation
#405's read queries select the `workers` column added by migration 006. Migrations are applied manually (pnpm admin:db:migrate), separately from the Vercel app deploy, so the deploy shipped a query referencing a column the production DB didn't have yet. Postgres fails to plan a bare reference to a non-existent column ("column \"workers\" does not exist"), so every cache-miss request to /api/v1/benchmarks 500'd — surfacing as the ~63% error rate after #405 (cache hits returned stale blobs; only misses hit the DB). Read `workers` via `to_jsonb(row) -> 'workers'` in all three read paths (getLatestBenchmarks base-table + view branches, getAllBenchmarksForHistory). JSON key lookup is a runtime op that returns NULL for an absent key instead of failing at parse time, so the endpoint keeps serving every other field whether or not migration 006 has run. Identical behavior once the column exists. Adds a regression test asserting the read queries never reference the workers column directly.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @arygupt's task in 1m 6s —— View job Claude Code Review
🟢 LGTM — no blocking issues foundThe fix correctly addresses the parse-time column lookup problem. Verified against
Operationally, as the PR body notes: migration 006 still needs to be applied to populate the column. This change just removes the hard ordering dependency between migration and deploy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Production error rate on
/api/v1/benchmarksspiked to ~63% immediately after #405 merged (Vercel error chart). Root cause:SELECT ... br.workers / lb.workers— a column added by migration006_benchmark_results_workers.sql.pnpm admin:db:migrate), separately from the Vercel app deploy. The app deploy shipped the new query, but migration 006 was not applied to prod, so the column doesn't exist there.column "workers" does not exist), so the statement throws and the route returns 500.Why ~63% and not 100%:
/api/v1/benchmarksis wrapped incachedQuery({ blobOnly: true }). Cache hits return pre-#405 blobs (200); only cache misses run the SQL → 500. The Neon panel shows 0% connection errors because the connection succeeds — only the query fails.Fix
Read
workersviato_jsonb(row) -> 'workers'in all three read paths:getLatestBenchmarks— base-table (date) branchgetLatestBenchmarks— materialized-view (no-date) branchgetAllBenchmarksForHistoryA JSON key lookup is a runtime operation that returns
NULLfor an absent key, instead of failing at parse time like a bare column reference. So the endpoint keeps serving every other field whether or not migration 006 has been applied. Behavior is identical once the column exists (jsonb in → jsonb out).This makes the read path resilient to migration/deploy ordering — a forgotten or not-yet-run migration degrades to "workers is null" instead of taking down the endpoint.
Note on the operational fix
This PR stops the 500s on its own. Migration 006 should still be applied to prod (
pnpm admin:db:migrate) so the measured-powerworkersdata is actually populated — and the cache purged afterward. This change just removes the hard dependency on migration-before-deploy ordering.Tests
packages/db/src/queries/benchmarks.test.ts— recording-mockDbClientasserts none of the three read queries reference theworkerscolumn directly (regression guard).pnpm typecheck,pnpm lint,pnpm fmt, and full db suite (226 tests) pass.Note
Low Risk
Targeted SQL selection change on read-only benchmark queries plus unit tests; no auth or write-path changes, with identical results once migration 006 exists.
Overview
Fixes production 500s on
/api/v1/benchmarkswhen the app ships before migration 006 adds theworkerscolumn: barebr.workers/lb.workersinSELECTfails at plan time, whileto_jsonb(row) -> 'workers'still plans and yields null until the column exists.All three benchmark read paths in
packages/db/src/queries/benchmarks.tsare updated—getLatestBenchmarks(date-filtered base table and materialized-view branches) andgetAllBenchmarksForHistory. Behavior is unchanged once migration 006 is applied.Adds
benchmarks.test.tswith a recording mockDbClientso generated SQL must use theto_jsonbform and must not match\b(br|lb)\.workers\b.Reviewed by Cursor Bugbot for commit d9f2a93. Bugbot is set up for automated code reviews on this repo. Configure here.