[MS-1516] Force Room as default database after a fresh user login - #1758
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the post-login flow so that after a fresh SID login, the app immediately treats Room as the default enrolment records database (instead of allowing the Realm→Room migration mechanism to determine the active DB), aligning with MS-1516.
Changes:
- Added
forceRoomAsDefaultDatabase()to cancel the migration worker and mark the Realm→Room migration as completed. - Updated
LoginCheckViewModelto call the new force method only after a fresh login (and not for already-signed-in users). - Added/updated tests covering the new “fresh login forces Room” behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| infra/enrolment-records/repository/src/main/java/com/simprints/infra/enrolment/records/repository/local/migration/RealmToRoomMigrationScheduler.kt | Adds a new API to force Room as default by cancelling migration work and updating migration flags. |
| infra/enrolment-records/repository/src/test/java/com/simprints/infra/enrolment/records/repository/local/migration/RealmToRoomMigrationSchedulerTest.kt | Adds test coverage for the new scheduler method behavior. |
| feature/login-check/src/main/java/com/simprints/feature/logincheck/LoginCheckViewModel.kt | Threads “fresh login” state into the flow and triggers forcing Room only after a successful fresh login. |
| feature/login-check/src/test/java/com/simprints/feature/logincheck/LoginCheckViewModelTest.kt | Adds tests asserting the force behavior happens only on fresh login and not for already signed-in users. |
ede3611 to
e644520
Compare
e644520 to
4f4b472
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
infra/enrolment-records/repository/src/main/java/com/simprints/infra/enrolment/records/repository/local/migration/RealmToRoomMigrationWorker.kt:76
CancellationExceptionis treated as an expected cancellation here, but it can still be logged as an error earlier inprocessRecords()(thecatch (e: Exception)aroundroomDataSource.performActions(...)will catchCancellationExceptiontoo). That can create noisy error logs/Crashlytics signals for deliberate cancellations (e.g.forceRoomAsDefaultDatabase()). Consider adding a dedicatedcatch (e: CancellationException) { throw e }before the generic catch insideprocessRecords()to avoid logging cancellations as errors.
} catch (e: CancellationException) {
// The work may have been canceled deliberately (e.g. forceRoomAsDefaultDatabase())
Simber.i("[RealmToRoomMigrationWorker] Migration cancelled: ${e.message}", tag = REALM_DB_MIGRATION)
throw e
infra/enrolment-records/repository/src/main/java/com/simprints/infra/enrolment/records/repository/local/migration/RealmToRoomMigrationScheduler.kt:43
- The KDoc says this “forces Room … ignoring the migration flags”, but the implementation actually overrides the flags by setting
MigrationStatus.COMPLETED(which elsewhere is documented as “Migration finished successfully”). This is potentially misleading for future maintainers since no migration is performed here; consider clarifying in the KDoc that this marks the migration as completed to switch the default DB and does not migrate existing Realm data.
/**
* Forces Room to become the default enrolment records database immediately, ignoring the migration flags
*/
suspend fun forceRoomAsDefaultDatabase() {
4f4b472 to
a53d9b5
Compare
|



JIRA ticket
Will be released in: 2026.3.0
Notable changes
Testing guidance
Additional work checklist