mattermost-mobile-upstream/android/app
yasser khan f5e7f9982b
fix(android): open every SQLite connection in WAL, not just the JSI one (#10117)
* fix(android): open every SQLite connection in WAL, not just the JSI one

#10109 re-enabled `pragma journal_mode = WAL` in WatermelonDB's shared
Database.cpp. Android runs WatermelonDB through JSI -- watermelondb-jsi is in
settings.gradle and WatermelonDBJSIPackage is registered in MainApplication --
so that pragma applies there, and both databases are created with `jsi: true`.

But the app also opens those same files from native Kotlin, on the push
notification path, and every one of those connections was opened without WAL:

  - DatabaseHelper.setDefaultDatabase -> WMDatabase.getInstance(path, context),
    whose 2-arg overload this repo's patch had stripped ENABLE_WRITE_AHEAD_LOGGING
    from (app.db)
  - getDatabaseForServer -> WMDatabase.buildDatabase(..., CREATE_IF_NECESSARY),
    hardcoded here, for every server database
  - WMDatabaseDriver's constructor, stripped by the same patch, for the bridge
    path WatermelonDB falls back to when JSI is unavailable

Journal mode is a property of the database file, not of a connection. When
Android's SQLiteConnection opens a database without ENABLE_WRITE_AHEAD_LOGGING it
issues its own `PRAGMA journal_mode` on open and drags the file back out of WAL
underneath the live JSI connection. Two connections disagreeing about the journal
is what produced `watermelondb.sqlite: (11) database disk image is malformed`
while adding a server -- the first write to app.db.

The paths provably collide: the patched WMDatabase.getInstance rewrites
`file:///…/files/app.db` to `/…/files/databases/app.db`, which is exactly what
the JS side opens as `${Paths.document.uri}/databases/app.db`.

This was consistent before #10109 because the patch disabled WAL in two
independent places -- the Java flags and the C++ pragma -- so everything was
non-WAL and agreed. #10109 re-enabled only the C++ half. The coherent states are
all-on or all-off; this makes it all-on, so #10109 is kept.

Reverting the two patch hunks rather than editing them leaves upstream's flags
untouched, which is why the diff removes them instead of rewriting them.

Not verified on a device here; it needs an Android build against the WAL-on repro.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Address review: trim WAL comment and regenerate watermelondb patch

Regenerate @nozbe+watermelondb+0.28.1-0.patch via patch-package after
restoring ENABLE_WRITE_AHEAD_LOGGING in node_modules, instead of
hand-editing the patch. Trim the verbose comment in getDatabaseForServer.

Co-authored-by: yasser khan <attitude3cena.yf@gmail.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-09-03 18:06:02 +05:30
..
src fix(android): open every SQLite connection in WAL, not just the JSI one (#10117) 2026-09-03 18:06:02 +05:30
build.gradle Bump app build number to 805 (#10086) 2026-08-20 16:51:49 +03:00
debug.keystore Detox android fix smoke tests (#7193) 2023-03-11 13:08:17 +01:00
google-services.json Update google-services.json (#9553) 2026-02-26 18:28:06 -05:00
proguard-rules.pro Fix MM 56723 (#7883) 2024-04-24 17:12:56 +02:00