mattermost-mobile-upstream/patches
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
..
@gorhom+bottom-sheet+5.2.13.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
@nozbe+watermelondb+0.28.1-0.patch fix(android): open every SQLite connection in WAL, not just the JSI one (#10117) 2026-09-03 18:06:02 +05:30
@react-native-community+netinfo+12.0.1.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
@rneui+base+5.0.0.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
@types+commonmark-react-renderer+4.3.4.patch Update libraries and dependencies (#7678) 2023-11-25 07:46:13 +08:00
@types+react-syntax-highlighter+15.5.13.patch Upgrade RN as well as update or replace other dependencies (#8011) 2024-06-19 09:33:45 +08:00
expo-image+55.0.10.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
expo-video-thumbnails+55.0.14.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
ratex-react-native+0.1.4.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
react-native-keyboard-controller+1.21.10.patch Fix crash on android caused by keyboard controller (#9902) 2026-07-07 15:31:44 +08:00
react-native-keychain+10.0.0.patch Update dependencies (#8721) 2025-04-07 09:30:06 +08:00
react-native-notifications+5.2.2.patch Fix Regressions (#9808) 2026-06-04 06:54:40 +08:00
react-native-safe-area-context+5.7.0.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
react-native-share+12.3.1.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
react-native-walkthrough-tooltip+1.6.0.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
react-native-webrtc+124.0.7.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
react-native+0.83.9.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00
react-syntax-highlighter+16.1.1.patch Migrate from RNN to Expo router (#9402) 2026-05-13 17:44:55 +08:00