db: add missing bookmarks_categories migration (22→23)#6888
db: add missing bookmarks_categories migration (22→23)#6888chrisdebian wants to merge 2 commits into
Conversation
The bookmarks_categories table was registered as a Room entity but was omitted from MIGRATION_21_22, causing a crash on upgraded installs. Users already at version 22 are fixed by the new MIGRATION_22_23. Also adds BookmarkCategoryTableTest covering all four DAO methods (insert, delete, doesExist, getAllCategories), and updates MigrationTest to verify bookmarks_categories exists after both migration paths. Fixes commons-app#6435
|
Thanks @chrisdebian! The changes mostly look good. I'll run the workflows and start testing them. |
|
✅ Generated APK variants! |
|
Hi, just checking in on this one — it's been about 12 days since it was opened. Happy to rebase or make any adjustments if that would help move it forward. Thanks, Chris |
|
@chrisdebian are you able to reproduce the issue? If yes, could you share the steps to reproduce? |
|
Hi @RitikaPahwa4444 — I identified the bug through code analysis rather than direct reproduction. To trigger it you would need a device running an older build where the database is at version 21, then upgrade to a build that included the I don't have a test device with an old enough build to reproduce the upgrade path directly. The Happy to assist with anything else that would help move the review forward. Thanks, Chris |
|
No worries, @chrisdebian. I tried checking out the old code and installing the app on my device, bookmarking categories and then installing the new version, but that didn't crash. fallbackToDestructiveMigration is likely preventing it.
I haven't run this yet, but is it able to demonstrate the failure if it's without the migration? |
|
Hi Ritika, Yes — the The reason manual install-over-install testing might not reproduce it is that it depends on having a real v22 database that was written before Thanks for testing — let me know if the test run raises any questions. |
|
Any idea why fallbackToDestructiveMigration wouldn't recreate the table (empty since there's no migration) but result into a crash instead? |
|
`fallbackToDestructiveMigration` only kicks in when Room can't find any migration between two schema versions. In this case `MIGRATION_21_22` exists, so Room follows it and considers the upgrade successful — it has no way to know the migration was incomplete. The crash comes later, at runtime, when the app tries to query `bookmarks_categories` and the table simply isn't there. That also explains why a fresh install doesn't hit the issue: Room creates all tables from the current schema directly, so `bookmarks_categories` is present from the start. Only devices that migrated through the incomplete `MIGRATION_21_22` are affected. |
|
This migration did not exist in the commit when we'd started noticing the issue: . |
|
That's a useful clarification — it reinforces the same crash path. Without |
Fixes #6435.
Summary
The
bookmarks_categoriestable is registered as a Room entity inAppDatabasebut was not created inMIGRATION_21_22. Users who upgraded from version 21 to 22 via that migration ended up with a database missing the table, causing the crash reported in #6435.Since
MIGRATION_21_22has already been applied to existing installs, modifying it would not help those users. Instead, a newMIGRATION_22_23creates the missing table, andAppDatabaseis bumped to version 23.Changes
AppDatabase: version bumped 22 → 23CommonsApplicationModule: addsMIGRATION_22_23which createsbookmarks_categories; registers it inaddMigrations()MigrationTest: registersMIGRATION_22_23in the existing 21→22 test path; adds assertion thatbookmarks_categoriesexists; adds a dedicatedtestMigration22To23testBookmarkCategoryTableTest(new): covers all fourBookmarkCategoriesDaomethods —insert,delete,doesExist,getAllCategories; previously at 0% coverageTest results
73, Chris 2E0FRU