Skip to content

fix(core): migrate legacy local databases - #34188

Closed
nasko25 wants to merge 3 commits into
anomalyco:devfrom
nasko25:dev
Closed

fix(core): migrate legacy local databases#34188
nasko25 wants to merge 3 commits into
anomalyco:devfrom
nasko25:dev

Conversation

@nasko25

@nasko25 nasko25 commented Jun 27, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #33887, closes #32361, closes #28013, closes #33828

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes two legacy local database migration issues.

Older databases can have a Drizzle journal table named __drizzle_migrations with only id, hash, and created_at. The migration bridge expected a name column, so startup
failed with no such column: name. In the full TUI this looked like a blank hang because the screen was already cleared.

Older sessions can also be attached to a previous project ID. Current code may resolve the same repo from its normalized git remote, while old rows used a root-commit project ID.
If there is no cached .git/opencode ID, the app creates a new project row and /sessions appears empty.

This PR handles both cases during migration:

  • seed the new migration table from old Drizzle journal row count when migration names are unavailable
  • migrate existing project/session/workspace rows with the same worktree into the currently resolved project ID
  • update GlobalBus to avoid a typed EventEmitter.emit override that fails current typecheck

How did you verify your code works?

  • bun test test/database-migration.test.ts -t "seeds unnamed Drizzle journal entries"
  • bun test test/project/project.test.ts -t "migrates uncached root project data"
  • bun typecheck from packages/core
  • bun typecheck from packages/opencode
  • Tested a rebuilt local binary against an affected database: startup works and /sessions shows old sessions again.

Screenshots / recordings

N/A

Checklist

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

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

Since this is an existing PR that tackles the same migration issue, you should check whether PR #31121 is still open/active or if it was closed/rejected, and understand why a new PR #34188 is being created to address the same problem.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

1 participant