Conversation
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/PluginStore.java
Fixed
Show fixed
Hide fixed
03dd081 to
14e6630
Compare
| return runBlocking { | ||
| val allPlugins = sitePluginDao.getActiveSitePlugins(site.localId()) | ||
| val extractedRequestedPluginName = plugin.pluginName.substringAfterLast('/') | ||
| allPlugins.firstOrNull { sitePlugin -> | ||
| val extractedPluginName = sitePlugin.name.substringAfterLast('/') | ||
| extractedPluginName == extractedRequestedPluginName | ||
| } | ||
| } |
There was a problem hiding this comment.
2b12dd5 to
447ddb7
Compare
All tests use the new DAO methods (upsert, replaceAllSitePlugins) and proper coroutine testing with runTest instead of runBlocking.
447ddb7 to
c39c421
Compare
c39c421 to
1455fd6
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates the SitePluginModel from WellSql to Room database, simplifying the data model and modernizing the persistence layer. The migration removes several fields that were not actively used (displayName, pluginUrl, description, authorUrl, settingsUrl, isAutoUpdateEnabled) and introduces a new Room entity with a streamlined schema.
Key Changes
- Replaced WellSql-based
PluginSqlUtilsandPluginSqlUtilsWrapperwith RoomSitePluginDao - Converted
SitePluginModelfrom a Java WellSql entity to a Kotlin Room entity with composite primary key (siteId, slug) - Updated all stores and clients to use the new DAO methods (suspend functions and blocking interop methods)
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/plugin/SitePluginModel.kt | New Room entity replacing the Java WellSql model, with simplified schema containing only essential fields |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/SitePluginDao.kt | New DAO with suspend functions for plugin CRUD operations and deprecated blocking methods for Java interop |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.kt | Added migration to drop the old SitePluginModel table from WellSql |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WPAndroidDatabase.kt | Updated Room database version to 33 and registered SitePluginModel entity |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/PluginStore.java | Replaced SQL utils with DAO calls and added null checks for plugin upserts |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/PluginCoroutineStore.kt | Updated to use SitePluginDao with suspend functions |
| libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WooCommerceStore.kt | Replaced SQL utils with DAO and added runBlocking wrappers for non-suspend methods |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/plugin/PluginRestClient.java | Simplified response mapping to match new model structure |
| libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/plugin/PluginResponseModel.kt | Updated domain model conversion to use new constructor-based approach |
| libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/system/WCSystemPluginResponse.kt | Updated system plugin mapping to new SitePluginModel structure |
| libs/fluxc/src/testFixtures/kotlin/org/wordpress/android/fluxc/wp/site/SitePluginFixtures.kt | Added test fixture factory for creating test plugins |
| libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/plugin/SitePluginDaoTest.kt | New comprehensive DAO tests replacing old SQL utils tests |
| libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/store/PluginCoroutineStoreTest.kt | Updated tests to use new model and DAO mocks |
| WooCommerce/src/test/kotlin/com/woocommerce/android/ui/subscriptions/IsEligibleForSubscriptionsTest.kt | Updated to use test fixtures instead of creating plugins manually |
| WooCommerce/src/main/kotlin/com/woocommerce/android/ui/prefs/plugins/PluginsViewModel.kt | Minor update to clarify filter lambda parameter type |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/plugin/SitePluginModel.kt
Outdated
Show resolved
Hide resolved
| import org.wordpress.android.fluxc.model.plugin.SitePluginModel | ||
|
|
||
| @Dao | ||
| abstract class SitePluginDao { |
There was a problem hiding this comment.
The DAO query is selecting from table "SitePluginEntity" but the entity annotation specifies tableName as "SitePluginEntity". While this is consistent, it might cause confusion since the old WellSql table was named "SitePluginModel". Consider adding a comment in the migration or documentation explaining the table name change from "SitePluginModel" to "SitePluginEntity" to help with debugging and future reference.
| abstract class SitePluginDao { | |
| abstract class SitePluginDao { | |
| // NOTE: The Room table "SitePluginEntity" replaces the legacy WellSql table "SitePluginModel". | |
| // This rename happened during the migration from WellSql to Room; keep this in mind when | |
| // debugging older migrations, logs, or database contents that still reference "SitePluginModel". |
There was a problem hiding this comment.
It's by design and consistent with already more than 30 migrations 👍. I don't see that this comment will help to navigate.
|
|
||
| @Entity( | ||
| tableName = "SitePluginEntity", | ||
| primaryKeys = ["siteId", "slug"] |
There was a problem hiding this comment.
The entity uses a composite primary key of (siteId, slug), but the slug field can potentially be an empty string based on the API response (as seen in the Hello Dolly plugin example where textdomain is empty). This could cause issues if multiple plugins with empty slugs are inserted for the same site, resulting in primary key conflicts.
Consider adding validation or handling for empty slugs, or using a different primary key strategy (e.g., using name instead of slug, or generating a unique identifier).
| primaryKeys = ["siteId", "slug"] | |
| primaryKeys = ["siteId", "name"] |
There was a problem hiding this comment.
I've added name to the key in 654bef2 - just in case, as it's true that we should be very cautious with API responses 👍
| siteId: Int = 1, | ||
| name: String = "", | ||
| version: String = "1.0.0", | ||
| slug: String = name.lowercase().replace(" ", "-"), |
There was a problem hiding this comment.
The default slug generation using name.lowercase().replace(" ", "-") could produce an empty string if the name parameter is empty (which it is by default). This would cause primary key issues since slug is part of the composite primary key. Consider either:
- Providing a non-empty default for name
- Adding validation to ensure slug is never empty
- Using a different default slug generation that guarantees a non-empty value (e.g., "test-plugin-${random()}")
There was a problem hiding this comment.
This is testFixtures directory, not a production code. It's okay to make fake assumptions here.
...c/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/plugin/PluginResponseModel.kt
Show resolved
Hide resolved
libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/store/PluginCoroutineStoreTest.kt
Show resolved
Hide resolved
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WooCommerceStore.kt
Show resolved
Hide resolved
libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WooCommerceStore.kt
Show resolved
Hide resolved
libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.kt
Show resolved
Hide resolved
...main/java/org/wordpress/android/fluxc/network/rest/wpcom/plugin/PluginWPComRestResponse.java
Show resolved
Hide resolved
samiuelson
left a comment
There was a problem hiding this comment.
The PR tests good 👍 I left a couple of unresolved comments from Copilot to verify.
It's probably possible that `slug` could be empty. For such cases, `name` should be also taken into account for primary key. If both `name` and `slug` would be empty - then we can assume something is really wrong and not a valid state
`SitePluginModel` is now a data class, so mocking it causes lint error
|
Thank you @samiuelson for review! I checked the opened comments, replied to them and added one fix in 654bef2 with explanation. |
The primary key change was introduced in 654bef2. I assume here that both name and slug of plugin don't change
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #15098 +/- ##
============================================
+ Coverage 38.63% 38.65% +0.01%
Complexity 10448 10448
============================================
Files 2178 2178
Lines 123901 123849 -52
Branches 17093 17097 +4
============================================
Hits 47875 47875
+ Misses 71206 71151 -55
- Partials 4820 4823 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Closes: AINFRA-547: Migrate
SitePluginModelDescription
This PR migrates
SitePluginModelfromWellSqltoRoom.Test Steps
Plugins list
Plugin installation
Images/gif
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.