HomePhabricator
Diffusion Comm 7c0a2863ec05

[native/sqlite] refactor code to perform migration inside one transaction

Description

[native/sqlite] refactor code to perform migration inside one transaction

Summary:
We want to perform getting version, migration, and updating version inside one transaction.

Unfortunately, migration 22 which is setting journal mode can not be done inside the transaction, because it will result in an error: cannot change into wal mode from within a transaction (1). That is why first we need to check the version, perform if shouldBeInTransaction is false, then start the transaction and again check the version (If the app will run into issues like those described in previous links in this time another thread could already updated the version).
If another thread will do it within getting the version and performing migration (not in the transaction) we do not run into issues because setting journal mode is an idempotent operation.

Note: whenever code will face issues right now there are break and return statements but it will be handled in a different way after implementing ENG-1974

Test Plan:
Perform migrations (decrement version or logout user) and check if

  • DB schema has the proper structure
  • journal_mode is set properly to value wal

Text case described here:
https://phab.comm.dev/D5377#161885

Reviewers: marcin, jon, atul, tomek

Reviewed By: marcin, atul, tomek

Subscribers: ashoat, tomek, atul, abosh

Differential Revision: https://phab.comm.dev/D5377

Details

Provenance
kamilAuthored on Oct 17 2022, 4:29 AM
Reviewer
marcin
Differential Revision
D5377: [native/sqlite] refactor code to perform migration inside one transaction
Parents
rCOMMb64ff5e82738: [native] Fix appearance of "Join Chat" in light mode
Branches
Unknown
Tags
Unknown