fix(db): add manual migration from 38 to 37 to prevent data loss on downgrade#3859
fix(db): add manual migration from 38 to 37 to prevent data loss on downgrade#3859kairosci wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Room migration MIGRATION_38_37 (schema 38→37) that rebuilds the artist table and drops ArtistPageCache, exposes MusicDatabase.delegate as public, and refactors DI providers to create MusicDatabase via InternalDatabase.newInstance and derive InternalDatabase from MusicDatabase.delegate. ChangesDB migration + DI provider changes
Sequence Diagram(s)sequenceDiagram
participant AppModule
participant InternalDatabase
participant Room
participant MusicDatabase
AppModule->>InternalDatabase: call InternalDatabase.newInstance(context)
InternalDatabase->>Room: build database with .addMigrations(MIGRATION_38_37)
InternalDatabase->>MusicDatabase: construct MusicDatabase(delegate)
AppModule->>MusicDatabase: obtain MusicDatabase
AppModule->>MusicDatabase: access .delegate to provide InternalDatabase
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/src/main/kotlin/com/metrolist/music/db/MusicDatabase.kt`:
- Around line 821-823: The CREATE TABLE statement in MIGRATION_38_37 (in
MusicDatabase.kt) uses `DEFAULT false` for the INTEGER boolean-like columns
`isLocal` and `isPodcastChannel` on the `artist_new` table; change those
defaults to `DEFAULT 0` so the SQL is compatible with older SQLite
versions—locate the SQL string used in MIGRATION_38_37 that creates `artist_new`
and replace both `DEFAULT false` occurrences with `DEFAULT 0`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 62ba354a-5b9b-48f8-9da9-cc2ab9acd689
📒 Files selected for processing (1)
app/src/main/kotlin/com/metrolist/music/db/MusicDatabase.kt
|
mark to draft because I want understand before if v38 with cached artist and songs works |
Problem
While testing PRs or branches containing a database schema bump to version 38 (such as PR 3807), I noticed a fatal
IllegalStateExceptionwhen returning tomainor downgrading to version 37. Room crashes because it requires a downgrade migration path that doesn't exist. Using destructive migration fallback on downgrade is not an option as it results in total user data loss.Furthermore, I discovered that the dependency injection in
AppModule.ktwas instantiating the Room database using a bareRoom.databaseBuilder, completely bypassingInternalDatabase.newInstance(context). This caused ALL manual database configurations, migrations, and callbacks to be ignored by the app.Cause
main, Room throws an exception:A migration from 38 to 37 was required but not found.AppModule.ktwas ignoringMusicDatabase.newInstance()which meant that even if a migration was added there, Room would never see it.Solution
AppModule.ktto actually useInternalDatabase.newInstance(context)and properly extract the delegate, so all manual migrations and configurations are correctly applied.MIGRATION_38_37insideMusicDatabase.kt.ArtistPageCachetable (added in 38) and gracefully reverts theartisttable structure to its schema at version 37 by reconstructing the table.Testing
MusicDatabase.ktcompiles successfully and the SQL matches the Room schema for version 37 exactly../gradlew :app:assembleFossDebugto ensurekspverification passes successfully on my end.Related Issues
Summary by CodeRabbit