Skip to content

fix(core): refuse to start against a database migrated by a newer version#11

Merged
CreatorGhost merged 1 commit into
devfrom
db-version-guard
Jul 12, 2026
Merged

fix(core): refuse to start against a database migrated by a newer version#11
CreatorGhost merged 1 commit into
devfrom
db-version-guard

Conversation

@CreatorGhost

@CreatorGhost CreatorGhost commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Port of upstream anomalyco/opencode#36429.

Startup now compares the database's applied migration count against the binary's known migrations and fails fast with a clear error when the DB is ahead (i.e. was migrated by a newer version), instead of running against a schema it doesn't understand and corrupting state.

Verified: bun test test/database-migration.test.ts (17 pass) and bun typecheck from packages/core. Applied cleanly.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented the application from starting against databases migrated by a newer version.
    • Added compatibility handling for unknown older migration records, allowing startup to continue safely.
  • Tests

    • Added coverage for newer database versions being rejected.
    • Added coverage confirming older unknown migration records remain supported.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0bc19cf1-5929-4c75-960a-41fded4ce02a

📥 Commits

Reviewing files that changed from the base of the PR and between f862420 and 37447c9.

📒 Files selected for processing (2)
  • packages/core/src/database/migration.ts
  • packages/core/test/database-migration.test.ts

📝 Walkthrough

Walkthrough

Database migration startup now detects unknown migration IDs newer than the current migration set and aborts with a fatal error. Tests cover rejection of future IDs and acceptance of older unknown IDs.

Changes

Migration safety

Layer / File(s) Summary
Future migration guard and validation
packages/core/src/database/migration.ts, packages/core/test/database-migration.test.ts
DatabaseMigration.apply rejects databases containing unknown migration IDs newer than the latest known ID, while tests verify that newer IDs fail and older unknown IDs succeed.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change and verification, but it omits required template sections like issue link, type of change, and checklist. Add the missing template sections: issue reference, type of change, screenshots if relevant, and the checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: startup now refuses databases migrated by a newer version.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch db-version-guard

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CreatorGhost

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@CreatorGhost

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@CreatorGhost CreatorGhost merged commit 1ae150a into dev Jul 12, 2026
4 of 7 checks passed
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.

1 participant