Skip to content

Added tests for migration legacy to room#6797

Merged
RitikaPahwa4444 merged 7 commits intocommons-app:mainfrom
rovertrack:dbtests
Mar 27, 2026
Merged

Added tests for migration legacy to room#6797
RitikaPahwa4444 merged 7 commits intocommons-app:mainfrom
rovertrack:dbtests

Conversation

@rovertrack
Copy link
Copy Markdown
Contributor

@rovertrack rovertrack commented Mar 24, 2026

Fixes #6777
relates to parent: #6768

  • Write tests using Room's Room.inMemoryDatabaseBuilder() to create tables with legacy code, and prove that room based entities can read from it, and vice-versa. This will let you write a test for step 5, demonstrating that the migration will work correctly.

What changes did you make and why?
added the inmemorydatabasebuilder helper class thanks to @psh comment

added tests

  • BookmarkPicturestableTest.kt
  • BookmarkItemsTabletest.kt
  • CategoryTableTest.kt
  • RecentSearchesTableTest.kt
  • RecentLanguagesTableTest.kt

all implemented tests passed ✅

Copy link
Copy Markdown
Collaborator

@RitikaPahwa4444 RitikaPahwa4444 left a comment

Choose a reason for hiding this comment

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

Thanks @rovertrack. I'm reviewing the tests. Meanwhile, could you check the comment I added?

Comment thread app/src/main/java/fr/free/nrw/commons/db/AppDatabase.kt Outdated
@rovertrack
Copy link
Copy Markdown
Contributor Author

rovertrack commented Mar 26, 2026

@RitikaPahwa4444 please check the latest commit
i have bumped the version and added data migration which moves data of the 5 legacy tables from "commons.db" to "commons_room.db"

wrote MigrationTest.kt which proves that the migration from old legacy db to room db is done suucessfully

before :

Screenshot 2026-03-27 013914

after :
Screenshot 2026-03-27 014231

also completes #6798

please review this, thanks

Copy link
Copy Markdown
Collaborator

@RitikaPahwa4444 RitikaPahwa4444 left a comment

Choose a reason for hiding this comment

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

Mostly looks good. I'll test it once and merge.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Robolectric/Room-based tests and wiring to support verifying interoperability and migration between the legacy commons.db (content-provider tables) and the Room database as part of the ongoing “content providers → Room” migration plan (issue #6777, parent #6768).

Changes:

  • Introduces an InMemoryDatabaseTest base to run Room in-memory DB tests and execute legacy SQL against the same DB.
  • Adds per-table tests for legacy table compatibility with new Room entities/DAOs (categories, bookmarks, bookmark items, recent searches, recent languages).
  • Bumps Room DB to v22, adds new Room entities/DAOs, and adds a MIGRATION_21_22 intended to copy data from commons.dbcommons_room.db.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
app/src/test/kotlin/fr/free/nrw/commons/db/InMemoryDatabaseTest.kt Base test harness for Room in-memory DB + legacy SQL helpers
app/src/test/kotlin/fr/free/nrw/commons/db/CategoryTableTest.kt Category legacy↔Room compatibility tests
app/src/test/kotlin/fr/free/nrw/commons/db/BookmarkPictureTableTest.kt Bookmark pictures legacy↔Room compatibility tests
app/src/test/kotlin/fr/free/nrw/commons/db/BookmarkItemsTableTest.kt Bookmark items legacy↔Room compatibility tests
app/src/test/kotlin/fr/free/nrw/commons/db/RecentSearchesTableTest.kt Recent searches legacy↔Room compatibility tests
app/src/test/kotlin/fr/free/nrw/commons/db/RecentLanguagesTableTest.kt Recent languages legacy↔Room compatibility tests
app/src/test/kotlin/fr/free/nrw/commons/db/MigrationTest.kt Adds a Robolectric test intended to validate the 21→22 migration
app/src/main/java/fr/free/nrw/commons/db/AppDatabase.kt Adds new entities/DAOs to Room DB and bumps version to 22
app/src/main/java/fr/free/nrw/commons/di/CommonsApplicationModule.kt Registers MIGRATION_21_22 and implements data-copy migration logic
app/src/main/java/fr/free/nrw/commons/data/DBOpenHelper.kt Allows injecting a delegate openHelper for tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/test/kotlin/fr/free/nrw/commons/db/InMemoryDatabaseTest.kt
Comment thread app/src/main/java/fr/free/nrw/commons/di/CommonsApplicationModule.kt Outdated
Comment thread app/src/main/java/fr/free/nrw/commons/di/CommonsApplicationModule.kt Outdated
Comment thread app/src/test/kotlin/fr/free/nrw/commons/db/MigrationTest.kt
Comment thread app/src/test/kotlin/fr/free/nrw/commons/db/MigrationTest.kt Outdated
@rovertrack
Copy link
Copy Markdown
Contributor Author

rovertrack commented Mar 27, 2026

@RitikaPahwa4444 I have made the improvements suggested by copilot
please review them .
thanks

@RitikaPahwa4444 RitikaPahwa4444 merged commit 3712f78 into commons-app:main Mar 27, 2026
2 checks passed
@rovertrack
Copy link
Copy Markdown
Contributor Author

rovertrack commented Mar 27, 2026

Thanks @RitikaPahwa4444
this closes #6798 too )

@github-actions
Copy link
Copy Markdown

✅ Generated APK variants!

Roniscend pushed a commit to Roniscend/apps-android-commons that referenced this pull request Apr 14, 2026
* added tests for migration legacy to room

* added data migration from commons.db to commons_room.db

* changes

* assertion changes

---------

Co-authored-by: Ritika Pahwa <83745993+RitikaPahwa4444@users.noreply.github.com>
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.

Write tests for migration to room

3 participants