-
Notifications
You must be signed in to change notification settings - Fork 136
Migrate ThemeModel to Room
#15045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Migrate ThemeModel to Room
#15045
Conversation
- Convert all classes and methods to Kotlin syntax - Use @JvmField for properties accessed from Java code - Maintain exact same behavior and API - All tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Convert ThemeModel to Room entity with composite primary key (siteId, themeId, isWpComTheme) - Create ThemeDao with direct @upsert exposure following OrderStatusDao pattern - Remove ThemeSqlUtils and move business logic to ThemeStore - Add LocalIdConverter for Room type conversion - Add comprehensive ThemeDaoTest with 13 test cases - Rewrite ThemeStoreUnitTest from Java to Kotlin - Update WPAndroidDatabase to version 31 with AutoMigration - Use site.localId() instead of LocalId(site.id) - Use runBlocking without dispatcher to preserve threading behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Generated by 🚫 Danger |
Updates ThemeRepository to use the new Room-based ThemeModel constructor with all required parameters instead of the deprecated default constructor. This fixes compilation errors in the Wasabi debug unit tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The LocalIdConverter was defined in both fluxc and fluxc-plugin modules, causing a "Type is defined multiple times" error during dex merging. Since fluxc-plugin already depends on fluxc via api dependency, it inherits the LocalIdConverter from the fluxc module. Removed the duplicate from fluxc-plugin to resolve the build error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
- Remove unused imports from ThemeStore, ThemeDao, and ThemeStoreUnitTest - Fix import ordering in WPAndroidDatabase (ThemeModel should come before persistence imports) - Remove unused createSite function from ThemeDaoTest - Rename test functions to follow detekt naming convention: "when X, then Y" All 19 detekt issues have been resolved. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #15045 +/- ##
============================================
- Coverage 38.61% 38.52% -0.09%
- Complexity 10311 10312 +1
============================================
Files 2163 2167 +4
Lines 122674 122936 +262
Branches 16934 16945 +11
============================================
+ Hits 47365 47366 +1
- Misses 70503 70765 +262
+ Partials 4806 4805 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Move ThemeStoreUnitTest from fluxc-tests to fluxc/store package - Create ThemeTestUtils with createTestTheme helper function - Create SiteTestUtils with generateWPComSite helper function - Update ThemeDaoTest to use shared createTestTheme utility - Update ThemeStoreUnitTest to use shared utilities This consolidates theme-related tests in the fluxc module and provides reusable test helpers for creating test themes and sites. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…at didn't make much sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates ThemeModel from WellSQL to Room database, modernizing the persistence layer for theme management in FluxC. The migration includes converting Java code to Kotlin and updating all related components.
Key Changes
- Converted
ThemeModelfrom Java/WellSQL to Kotlin data class with Room annotations - Migrated persistence from
ThemeSqlUtils(WellSQL) toThemeDao(Room) - Converted
ThemeStoreandThemeRestClientfrom Java to Kotlin
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.kt | Converted to Kotlin data class with Room entity annotations and composite primary key |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dao/ThemeDao.kt | New Room DAO with suspend functions for theme data access |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/converters/LocalIdConverter.kt | Type converter for Room to handle LocalId custom type |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WPAndroidDatabase.kt | Updated database to version 31, added ThemeModel entity and LocalIdConverter |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.kt | Converted to Kotlin, integrated Room database with runBlocking for backward compatibility |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.kt | Converted to Kotlin, updated ThemeModel construction to use data class constructor |
| libs/fluxc/src/test/java/org/wordpress/android/fluxc/utils/ThemeTestUtils.kt | New test utility for creating test themes |
| libs/fluxc/src/test/java/org/wordpress/android/fluxc/utils/SiteTestUtils.kt | New test utility for creating test sites |
| libs/fluxc/src/test/java/org/wordpress/android/fluxc/store/ThemeStoreUnitTest.kt | New Room-based unit tests for ThemeStore |
| libs/fluxc/src/test/java/org/wordpress/android/fluxc/persistence/ThemeDaoTest.kt | Comprehensive unit tests for ThemeDao operations |
| WooCommerce/src/main/kotlin/com/woocommerce/android/ui/themes/ThemeRepository.kt | Updated to use new ThemeModel data class constructor |
| libs/fluxc/schemas/org.wordpress.android.fluxc.persistence.WPAndroidDatabase/31.json | Room database schema for version 31 with ThemeModel table |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val retrievedTheme = themeStore.getInstalledThemeByThemeId(site, testThemeId) | ||
| assertThat(retrievedTheme) | ||
| .usingRecursiveComparison() | ||
| .ignoringFields("active") | ||
| .isEqualTo(testTheme) |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test comparison is incomplete. The testTheme is created with siteId = LocalId(0) (line 69), but when inserted via setActiveThemeForSite (line 76), the theme is copied with siteId = site.localId() which is LocalId(556) based on the test site. The comparison should either:
- Ignore the "siteId" field in addition to "active", or
- Create the testTheme with the correct siteId upfront
Currently, this test would fail because the siteId values don't match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually passes because in ThemeStore#setActiveThemeForSite we set the site id like
val activeTheme = theme.copy(
siteId = site.localId(),
isWpComTheme = false,
active = true
)I agree it's not very readable, but themes created in ThemeRestClient always set siteId = LocalId(0),.
I think this part of codebase could use some refactoring to fix this and remove the event bus architecture, but I also want to limit this PR to be focused on database migration.
Related: #15011
Closes: AINFRA-548: Migrate
ThemeModelDescription
This PR migrates
ThemeModelfromWellSqltoRoom. As always, these PRs focus on migrations, but in this specific case I also decided to migrate a few classes from Java to Kotlin, to be able to runsuspendmethods.Test Steps
Smoke test theme functionality:
Images/gif
Before (trunk)
After
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.