Skip to content

Switch persistence layer from Realm to SQLite (TypeORM + react-native-sqlite-storage)#139

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/switch-from-realm-to-sqlite
Draft

Switch persistence layer from Realm to SQLite (TypeORM + react-native-sqlite-storage)#139
Copilot wants to merge 2 commits intomainfrom
copilot/switch-from-realm-to-sqlite

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 31, 2026

MongoDB Realm is deprecated and being removed in September 2025. This replaces it with TypeORM backed by react-native-sqlite-storage, which is compatible with React Native 0.71.

New: src/persistence/sqlitedb/

  • entities/AttemptSchema.ts — TypeORM EntitySchema for STIF.Attempt. Indexed eventId and inspectionStart columns mirror the existing Realm query patterns; complex sub-objects (solutions, infractions, event) stored as JSON text columns. Includes rowToAttempt / attemptToRow serializers.
  • entities/SolveRecordingSchema.ts — TypeORM EntitySchema for STIF.SolveRecording.
  • index.tsAppDataSource configuration + attemptsVersion global counter (via react-hooks-global-state, already a dependency) that replaces Realm's live-query observation: hooks re-fetch whenever a write bumps the counter.
  • DatabaseProvider.tsx — React context provider wrapping DataSource initialization; exposes useDatabase().

Updated

  • All src/persistence/hooks/ — migrated from Realm APIs to TypeORM repositories. useAttemptRestoration wraps clear()+save() in a transaction for atomicity.
  • src/ui/App.tsxRealmProviderDatabaseProvider; Realm Flipper plugin removed.
  • package.json — removes realm, @realm/react, realm-flipper-plugin-device; adds typeorm@^0.3.26, react-native-sqlite-storage@^6.0.1.

Deleted

  • src/persistence/realmdb/ — replaced entirely.

Design notes

  • No decorators: Uses EntitySchema throughout to avoid reflect-metadata / experimentalDecorators, which conflict with isolatedModules: true in tsconfig.json.
  • Data migration path: The existing JSONL backup/restore (backup.ts / restore.ts) is unchanged and serves as the migration path for existing users — back up on the old version, restore on the new one.
  • synchronize: true auto-creates tables on first launch. Future schema changes should switch to TypeORM migrations.

Copilot AI linked an issue Mar 31, 2026 that may be closed by this pull request
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Switch from Realm to SQLite database Switch persistence layer from Realm to SQLite (TypeORM + react-native-sqlite-storage) Mar 31, 2026
Copilot AI requested a review from thehale March 31, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch from Realm to SQLite

3 participants