Skip to content

fix(core): rename the legacy blob table before creating the new one - #65661

Open
ccclucky wants to merge 3 commits into
anomalyco:devfrom
ccclucky:blob-table-rename
Open

ccclucky wants to merge 3 commits into
anomalyco:devfrom
ccclucky:blob-table-rename

Conversation

@ccclucky

Copy link
Copy Markdown

Issue for this PR

Closes #63913

Type of change

  • Bug fix

What does this PR do?

20261025123711_blob does a bare CREATE TABLE blob (...) for the content-addressed table. A database that went through the V1→V2 migration can already hold the legacy blob(id, data) table (the desktop drafts migration creates it in the same file), so the migration dies with table blob already exists and the rest of the upgrade, including opencode serve --service, never completes.

Before creating the new table, the migration now renames a blob table that has no hash column to blob_v1_legacy. Nothing references that table, and whatever rows it holds survive the rename. A blob table that already has the new shape is left alone and still fails loudly, so a half-applied schema is never silently replaced.

The desktop drafts half of the report (20260906234153_drafts colliding with document) is a separate migration in packages/desktop and is not changed here.

How did you verify your code works?

  • New case in packages/core/test/database-migration.test.ts seeds the legacy blob(id, data) table with a row and applies the migration: the resulting blob has hash, and blob_v1_legacy still holds the row.
  • bun test test/database-migration.test.ts in packages/core: 25 pass.
  • Real upgrade smoke on a local user database copy: dropped the journal row for 20261025123711_blob plus blob and blob_ref, restored a blob(id, data) row, then ran DatabaseMigration.apply. On the base it fails at 20261025123711_blob; with this change it completes, blob has the new shape, and the legacy row is in blob_v1_legacy.
  • bun typecheck in packages/core: no type errors.

Visual

Not a UI change.

Screenshots / recordings

Not applicable.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. On the base, I built a database whose blob table has the old (id, data) layout, as described in the issue, and opencode serve failed at 20261025123711_blob with table `blob` already exists. With this PR, the same database migrates and the server starts. blob has the new layout, blob_ref is created, and the old row is kept in blob_v1_legacy. The new test passes here and fails on the base. tsc -b for packages/core passes.

The check before the rename works the same way as the existing PRAGMA table_info guards in the session-metadata and workspace-name migrations, and nothing reads the renamed table. #64203 already fixed the desktop half of #63913, so with this change the whole issue is covered.

Public API: unchanged.

No blocking concerns.

This branch has not been deployed

No deployments
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.

db: 2.3.0 migrations fail on V1→V2 databases ("table blob already exists")

1 participant