Skip to content

db: add missing bookmarks_categories migration (22→23)#6888

Open
chrisdebian wants to merge 2 commits into
commons-app:mainfrom
chrisdebian:fix/6435-missing-bookmarks-categories-migration
Open

db: add missing bookmarks_categories migration (22→23)#6888
chrisdebian wants to merge 2 commits into
commons-app:mainfrom
chrisdebian:fix/6435-missing-bookmarks-categories-migration

Conversation

@chrisdebian

Copy link
Copy Markdown

Fixes #6435.

Summary

The bookmarks_categories table is registered as a Room entity in AppDatabase but was not created in MIGRATION_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_22 has already been applied to existing installs, modifying it would not help those users. Instead, a new MIGRATION_22_23 creates the missing table, and AppDatabase is bumped to version 23.

Changes

  • AppDatabase: version bumped 22 → 23
  • CommonsApplicationModule: adds MIGRATION_22_23 which creates bookmarks_categories; registers it in addMigrations()
  • MigrationTest: registers MIGRATION_22_23 in the existing 21→22 test path; adds assertion that bookmarks_categories exists; adds a dedicated testMigration22To23 test
  • BookmarkCategoryTableTest (new): covers all four BookmarkCategoriesDao methods — insert, delete, doesExist, getAllCategories; previously at 0% coverage

Test results

MigrationTest        — 2 tests, 0 failures
BookmarkCategoryTableTest — 7 tests, 0 failures

73, Chris 2E0FRU

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
@RitikaPahwa4444

Copy link
Copy Markdown
Collaborator

Thanks @chrisdebian! The changes mostly look good. I'll run the workflows and start testing them.

@github-actions

Copy link
Copy Markdown

✅ Generated APK variants!

@chrisdebian

Copy link
Copy Markdown
Author

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

@RitikaPahwa4444

Copy link
Copy Markdown
Collaborator

@chrisdebian are you able to reproduce the issue? If yes, could you share the steps to reproduce?

@chrisdebian

Copy link
Copy Markdown
Author

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 MIGRATION_21_22 code (which created the bookmarks_categories entity in AppDatabase but forgot to include it in the migration SQL). On the next launch, any code path that queries bookmarks_categories hits the crash from #6435.

I don't have a test device with an old enough build to reproduce the upgrade path directly. The MigrationTest in the PR exercises the 21 → 22 → 23 migration chain and asserts that bookmarks_categories exists after the full upgrade, which is the programmatic equivalent.

Happy to assist with anything else that would help move the review forward.

Thanks, Chris

@RitikaPahwa4444

RitikaPahwa4444 commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

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.

The MigrationTest in the PR exercises the 21 → 22 → 23 migration chain and asserts that bookmarks_categories exists after the full upgrade, which is the programmatic equivalent.

I haven't run this yet, but is it able to demonstrate the failure if it's without the migration?

@chrisdebian

Copy link
Copy Markdown
Author

Hi Ritika,

Yes — the MigrationTest should demonstrate the failure if the migration is removed. It creates a database at schema version 21 and runs it through all migrations to version 23, then asserts that bookmarks_categories exists. Without the 22→23 migration step that creates that table, the assertion would fail.

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 bookmarks_categories existed. If the device never ran the app at the affected v22 version (or if bookmarks were never used), Room may not have encountered the missing table at runtime.

Thanks for testing — let me know if the test run raises any questions.

@RitikaPahwa4444

Copy link
Copy Markdown
Collaborator

Any idea why fallbackToDestructiveMigration wouldn't recreate the table (empty since there's no migration) but result into a crash instead?

@chrisdebian

Copy link
Copy Markdown
Author

`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.

@RitikaPahwa4444

Copy link
Copy Markdown
Collaborator

This migration did not exist in the commit when we'd started noticing the issue:

.

@chrisdebian

Copy link
Copy Markdown
Author

That's a useful clarification — it reinforces the same crash path. Without fallbackToDestructiveMigration, Room throws an IllegalStateException at startup when it can't find a migration at all. But since MIGRATION_21_22 was defined (just incomplete), Room followed it and considered the upgrade done — so the startup check passed and the crash happened later at runtime when the code tried to access bookmarks_categories. Either way, MIGRATION_22_23 is the right fix: it provides the explicit path and creates the table if it isn't there.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no such table bookmarks_categories

2 participants