Uh oh!
There was an error while loading. Please reload this page.
sqflite_tvos: resolve getDatabasesPath under Library/Caches (Documents isn't writable on device) - #4
Conversation
Documents is not writable in the tvOS sandbox on physical devices, so the previous default failed every openDatabase with SQLITE_CANTOPEN (the simulator sandbox permits the write, masking it). Caches is the tvOS-writable location consistent with the platform's purgeable-storage model.
MAUstaoglu
left a comment
There was a problem hiding this comment.
Thanks — this is a well-evidenced report, and the hardware/simulator split is exactly the kind of thing that's easy to miss. The change itself is right: tvOS only guarantees writable storage under Library/Caches and tmp, so resolving getDatabasesPath() to Documents was never going to work on a real device.
I checked one thing before asking for changes: handleOpenDatabaseCall already creates the parent directory (SqflitePlugin.m:516-526), so returning the Caches path without an explicit createDirectory is fine here — Library/Caches gets created on first open if it's missing. No extra work needed on that front.
Two things before this can merge:
1. Version bump + CHANGELOG.sqflite_tvos is published on pub.dev at 0.0.1, so the fix can't reach users without version: 0.0.2 in pubspec.yaml and a matching ## 0.0.2 entry in CHANGELOG.md.
2. Call out the behaviour change in that entry. Anyone who developed against the simulator has a database sitting under Documents; after this lands getDatabasesPath() points elsewhere and they'll silently get a fresh empty DB rather than an error. Harmless on device (it never worked there), but it should be written down.
Suggested entry:
## 0.0.2***Fix:**`getDatabasesPath()` now resolves under `Library/Caches` instead of
Documents. On a physical Apple TV the tvOS sandbox does not permit writes to
Documents, so the canonical
`openDatabase(join(await getDatabasesPath(), 'x.db'))` failed with
`SQLITE_CANTOPEN`. The simulator sandbox permits the write, which masked this.
***Behaviour change:** apps that created a database against the simulator under
the old Documents path will resolve to a new, empty database. tvOS storage is
purgeable by platform contract — data that must survive belongs on a server or
in iCloud Key-Value Storage.Separately, and not your problem to fix here: this implies path_provider_tvos has the same issue — it returns .documentDirectory for getApplicationDocumentsDirectory(), and its header comment claims the standard NSSearchPath* lookups "work unchanged" on tvOS. If Documents isn't writable on hardware, that comment is wrong and the directory is unusable. I'll open a separate issue to verify and fix that.
Nice catch — please push the version bump and CHANGELOG and I'll merge.
Adds a PR template covering the two things most easily missed in this monorepo: per-package version bumps and CHANGELOG entries. Every package here is published to pub.dev independently, so a user-visible fix that doesn't bump pubspec.yaml never reaches anyone — which is exactly what happened in #4. The template also asks whether a change was verified on real hardware rather than only the simulator, since the simulator's sandbox is more permissive and masks device-only failures, and prompts contributors to flag behaviour changes and sibling packages affected by the same tvOS constraint.
…th fix Requested in PR review: version bump so the fix can ship to pub.dev, and a CHANGELOG entry documenting the behaviour change for simulator-created databases under the old Documents path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
SupposedlySam
commented
Jul 20, 2026
Thank you! Ready for your review. |
MAUstaoglu
commented
Jul 20, 2026
Version bump and CHANGELOG look right — thanks for turning that around. Worth adding for the record: I verified your premise independently on a physical Apple TV 4K (tvOS 26.5) with a plain
So your diagnosis holds exactly, and Two notes that came out of it:
More interesting: this isn't limited to sqflite. Merging. Thanks for taking the time to write this up properly — the before/after and the repro made it straightforward to confirm. |
Thanks for the plugin ports — sqflite on tvOS worked well once the database landed in the right place. Sharing a hardware finding in case it's useful, since the simulator hides it.
Why
On a physical Apple TV the tvOS sandbox doesn't allow writing under Documents, but
getDatabasesPath()resolves there — so the canonicalopenDatabase(join(await getDatabasesPath(), 'x.db'))fails at open withSQLITE_CANTOPEN. The simulator sandbox permits the write, so it only shows up on real hardware.Library/Cachesis writable, so this points the default there. (README updated to match; the previous note recommended Documents / Application Support.)Repro
flutter-tvos create demo && cd demo, addsqflite+sqflite_tvos,path,path_provider+path_provider_tvosfinal db = await openDatabase(join(await getDatabasesPath(), 'x.db'));DEVELOPMENT_TEAM,flutter-tvos build tvos --profile, install + launch on a physical Apple TVBefore
After
Verified on an Apple TV 4K (tvOS 26.5): the default-path open now succeeds under
Library/Caches. One trade-off worth noting in case it matters for the default — Caches is purgeable by the OS, so durable data shouldn't live in a plain sqflite DB on tvOS regardless; the README now says as much.