HomePhabricator
Diffusion Comm ccc4e5f12d6c

[native/sqlite] infer db schema from `sqlite_orm`

Description

[native/sqlite] infer db schema from sqlite_orm

Summary:
Instead of running all migrations to create a fresh database, we can synchronize schema with the structure declared in make_storage (task).

According to sqlite_orm docs "sync_schema function that takes responsibility of comparing actual db file schema with one you specified in make_storage call and if something is not equal it alters or drops/creates schema." which suits to our needs.

Note: we used this method previously and was removed in https://phab.comm.dev/D1765, more details in this notion note.
However, this time we use this in a different context, not for migration but for creating a clean database schema, so mentioned in previous links problems with deleting data should not appear.

Test Plan:
Logout user (it'll recreate database) or clean install app on the device to make sure current db version is 0 - migration should not start and schema should be created (can be checked without encryption using eg. sqlite3).
In any other scenario when db version is different from 0 migration should run (or no if the version is equal to the highest migration index) as it was previously

Reviewers: tomek, atul, marcin, jon, ashoat

Reviewed By: tomek, atul, marcin, ashoat

Subscribers: varun, ashoat, atul, abosh

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