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