[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