Skip to content

Fix: Correct legacy version semver assignment (api#40)#41

Open
ScuttleBot wants to merge 1 commit intomainfrom
fix/legacy-version-semver
Open

Fix: Correct legacy version semver assignment (api#40)#41
ScuttleBot wants to merge 1 commit intomainfrom
fix/legacy-version-semver

Conversation

@ScuttleBot
Copy link
Copy Markdown

Problem

All legacy benchmark versions were incorrectly assigned the same semver label 1.0.0-beta.1 instead of sequential beta numbers.

Root Cause

The previous backfill migration (20260406_backfill_legacy_versions.sql) used a correlated subquery that evaluated incorrectly during UPDATE:

SELECT COUNT(*) + 1 FROM benchmark_versions bv2 
WHERE bv2.semver IS NULL 
  AND bv2.created_at < benchmark_versions.created_at

This subquery had two issues:

  1. The bv2.semver IS NULL condition meant it could only see unprocessed rows
  2. The correlated reference to the same table during UPDATE caused evaluation order issues in D1's query planner

Solution

This new migration:

  1. Resets any rows with incorrect semver (LIKE '1.0.0-beta.%') back to NULL
  2. Uses ROW_NUMBER() window function with a proper subquery pattern
  3. Assigns sequential numbers beta.1, beta.2, beta.3... based on created_at order

Changes

  • Adds migrations/20260406_fix_legacy_version_semver.sql

Fixes api#40

The previous backfill migration (20260406_backfill_legacy_versions.sql) had a bug
where it used a correlated subquery that evaluated incorrectly during UPDATE,
causing all legacy versions to get assigned '1.0.0-beta.1'.

The problematic pattern was:
  SELECT COUNT(*) + 1 FROM benchmark_versions bv2
  WHERE bv2.semver IS NULL
  AND bv2.created_at < benchmark_versions.created_at

This subquery had two issues:
1. The bv2.semver IS NULL condition meant it could only see unprocessed rows
2. The correlated reference to the same table during UPDATE caused evaluation
   order issues in D1

This new migration:
1. Resets any rows with incorrect semver (LIKE '1.0.0-beta.%')
2. Uses ROW_NUMBER() window function with a proper subquery pattern
3. Assigns sequential numbers based on created_at order

Fixes api#40
@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
pinchbench-api bf3abc8 Commit Preview URL

Branch Preview URL
Apr 06 2026, 11:35 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants