Skip to content

feat(db): add self‑healing migration logic - #788

Merged
haiphucnguyen merged 1 commit into
askimo-ai:mainfrom
derek201759:feature/fix-database-migration-issue
Oct 29, 2026
Merged

haiphucnguyen merged 1 commit into
askimo-ai:mainfrom
derek201759:feature/fix-database-migration-issue

Conversation

@derek201759

Copy link
Copy Markdown
Contributor

Summary

I hit SQLITE_ERROR: no such column: deleted_at (and potentially other guarded columns) despite running the latest build. Root cause: PRAGMA user_version can drift ahead of the database's actual column set — e.g. when a WAL-mode .db file is copied/synced without its matching -wal/-shm files, or a DB is manually restored/edited. Since DatabaseManager.migrateIfNeeded() only ran migrations when oldVersion < newVersion, a database with an already-current user_version but missing columns would silently skip the AfterVersion callback that would have added them.

Related Issue(s)

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

- Re‑apply all migration actions on startup to recover from missing or out‑of‑sync DB files
- Introduce repairAll(driver) in SqlDelightSchemaMigrations for idempotent re‑application
- Call repairAll from DatabaseManager after user_version checks
- Guarantees that schema is always up‑to‑date without requiring manual migration steps

@haiphucnguyen haiphucnguyen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @derek201759 !

@haiphucnguyen
haiphucnguyen merged commit 7370674 into askimo-ai:main Oct 29, 2026
12 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.

2 participants