Migrate Persistence Layer from JSON Files to Room Database #2

Open
opened 2026-02-17 23:06:09 +00:00 by hmalik144 · 0 comments
Owner

Description
The current implementation relies on manual JSON file I/O for data persistence. This approach is becoming difficult to maintain, lacks thread safety, and does not support complex queries or indexing.

We need to migrate the storage engine to Room (SQLite) to improve performance, data integrity, and to leverage structured data observation (Flow/LiveData).

Technical Implementation Plan

  1. Dependency Updates
  • Add androidx.room dependencies to app/build.gradle.

  • Configure KSP (Kotlin Symbol Processing) for annotation handling.

  • Define the Database version (starting at 1).

  1. Schema Definition
  • Convert existing JSON data models into Room @Entity classes.

  • Implement @Dao (Data Access Objects) for CRUD operations.

  • Create the @Database abstract class to provide the singleton instance.

  1. Data Migration Logic. Create a Migration Utility to:
  • Read existing .json files from Internal Storage.
  • Map JSON objects to Room Entity objects.
  • Bulk insert into the new database.
  • Securely delete the legacy JSON files post-verification.
  1. Repository Refactor
  • Update the Repository Pattern to inject the new DAO.

  • Replace manual file-parsing logic with Room query calls.

  • (Optional) Expose data as Flow for reactive UI updates.

**Description** The current implementation relies on manual JSON file I/O for data persistence. This approach is becoming difficult to maintain, lacks thread safety, and does not support complex queries or indexing. We need to migrate the storage engine to Room (SQLite) to improve performance, data integrity, and to leverage structured data observation (Flow/LiveData). **Technical Implementation Plan** 1. Dependency Updates - [ ] Add androidx.room dependencies to app/build.gradle. - [ ] Configure KSP (Kotlin Symbol Processing) for annotation handling. - [ ] Define the Database version (starting at 1). 2. Schema Definition - [ ] Convert existing JSON data models into Room @Entity classes. - [ ] Implement @Dao (Data Access Objects) for CRUD operations. - [ ] Create the @Database abstract class to provide the singleton instance. 3. Data Migration Logic. Create a Migration Utility to: - [ ] Read existing .json files from Internal Storage. - [ ] Map JSON objects to Room Entity objects. - [ ] Bulk insert into the new database. - [ ] Securely delete the legacy JSON files post-verification. 4. Repository Refactor - [ ] Update the Repository Pattern to inject the new DAO. - [ ] Replace manual file-parsing logic with Room query calls. - [ ] (Optional) Expose data as Flow<T> for reactive UI updates.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hmalik144/simple-notes-sync#2
No description provided.