Skip to content

feat(ios): store databases in Application Support safely - #324

Open
chrispader wants to merge 5 commits into
mainfrom
@chrispader/fix/ios-database-migration
Open

feat(ios): store databases in Application Support safely#324
chrispader wants to merge 5 commits into
mainfrom
@chrispader/fix/ios-database-migration

Conversation

@chrispader

@chrispader chrispader commented Sep 10, 2026

Copy link
Copy Markdown
Member

iOS apps that expose Documents through file sharing also expose Nitro SQLite databases, but moving those databases without every SQLite recovery file can corrupt data after a crash. #323 adds an opt-in Application Support location, but its migration omits rollback journals and only applies to databases passed through open(). This replacement keeps Nicol谩s Bonet's original commit and adds complete recovery-file handling plus consistent open(), attach(), and drop() behavior.

  • Migrates the database, rollback journal, WAL, and shared-memory files as one set.
  • Removes stale destination journals before copying and keeps using the source after any inspection, cleanup, copy, or deletion failure.
  • Migrates databases before attach() and removes old or partial generations from both locations during drop().
  • Adds C++ regression tests against the bundled SQLite, including real WAL and hot-journal recovery after an unclean process exit.

Reproduction

  1. Create primary and attached databases with a version that stores them in Documents.
  2. Leave either a rollback journal or WAL files beside a database, then install a build with RNNitroSQLite_DatabaseLocation set to ApplicationSupport.
  3. Open or attach each database and verify the database and its journal files move to Application Support without losing data.
  4. Delete a database whose migration was interrupted and verify no old or partial generation remains in either location.

Fixes #289.
Supersedes #323.

NicolasBonet and others added 5 commits September 8, 2026 10:33
The Documents directory becomes user-visible in the Files app when an app
enables file sharing, exposing raw databases and their -wal/-shm journals
to accidental sharing, modification, or deletion.

Setting RNNitroSQLite_DatabaseLocation to "ApplicationSupport" in
Info.plist stores databases in Library/Application Support instead
(persistent, backed up, never user-visible). Databases created by older
app versions are moved out of Documents when they are opened: the
database and its journals are copied as a set before the originals are
deleted, and if anything fails the database keeps being opened from
Documents and the migration retries on the next open.

Fixes #289

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

iOS: databases are stored in the Documents directory, which can be exposed to users via the Files app

2 participants