We want to perform getting version, migration, and updating version inside one transaction.
- [task](https://linear.app/comm/issue/ENG-2048/refactor-sqlite-migration-to-get-version-perform-action-and-update)
- [more context](https://linear.app/comm/issue/ENG-1910/sqlite-table-olm-persist-account-exists-even-though-db-migration#comment-8e8a1fe9)
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](https://linear.app/comm/issue/ENG-1974/analysis-of-errors-in-sqlitequeryexecutor)