Migrate off content providers and onto Room

Open
#6,768 5 comments 1 reaction 1 assignee View on GitHub

Maintainers usually reply within 1 day

@psh is already working on this.

Since Mar 21, 2026.

Assessment

This issue has not been assessed yet.

Description

help needed unit tests needed

The app still has five content providers -

  • CategoryContentProvider
    • fr.free.nrw.commons.category.CategoryContentProvider
  • RecentSearchesContentProvider
    • fr.free.nrw.commons.explore.recentsearches.RecentSearchesContentProvider
  • RecentLanguagesContentProvider
    • fr.free.nrw.commons.recentlanguages.RecentLanguagesContentProvider
  • BookmarkPicturesContentProvider
    • fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider
  • BookmarkItemsContentProvider
    • fr.free.nrw.commons.bookmarks.items.BookmarkItemsContentProvider

These write to a different SQLite database file than room, so migration will me moving data from one database to the other when the time comes.

Step-by-step migration plan
  1. Consistent code in content providers - extract the table definitions from the couple of content providers that still have them (Recent Languages and Content) so we can focus on the queries in subsequent steps.
  2. Move the DBOpenHelper to the more modern androidx.sqlite.db.SupportSQLiteOpenHelper pointing at existing (legacy) database file. Content provider queries will need to update as the SupportSQLiteOpenHelper is slightly different.
  3. Create Room based entities and DAOs that match the queries in the content providers
  4. 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.
  5. Get an instance of SupportSQLiteOpenHelper from a Room DB, letting content providers share the same database file as Room. Create a database migration that copies data from the old file to the Room database (sql SELECT and INSERT statements, pretty easy)
  6. Swap references in the rest of the app from content provider queries to Room based entities now that we've proven they work and all the data lives in the same database. Ensure that we dont "leak" database entities out in other layers of the app.
  7. Delete content providers
Process

Do the work one-step at a time. Create an issue, have it assigned to you and in its description reference this as "parent" - this will link child issues and allow a one-stop-shop for measuring progress and avoid confusion -

parent: #6768

Similarly in your pull request when you complete the work -

closes: <your issue id>
relates to parent: #6768

Steps 3, 4 and 6 can be broken down per content provider to reduce the size of PR's.

Dominant language
Kotlin
Stars
1.2k
Forks
1.4k
Avg merge
1d 4h
Merged PRs (30d)
156

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from commons-app/apps-android-commons

All issues in commons-app/apps-android-commons

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.