How to manage SQLite DB (fist install, updates to scheme, etc)


Does anyone have any advice/experience working with the SQLite DBs these apps. I can follow the example Expo team published on Github easily enough however It leaves me with so many questions…

How will I load in a DB pre populated with records?
How can I make updates to the scheme if needed during an app update (what if a user skips one update and jumps versions if I end up making migration scripts)

Any advice on this topic would be greatly appreciated…


I have a version table that has one column and just one row. This tracks what version of the database a client has. I then write a migration function that migrates from one version to the next. So I could have two functions MigrateFrom0To1, MigrateFrom1To2 and so on. Within my JS code I have a constant that says what database schema version this version of the code works with. Initially it would be 1. Each time I need to change the database structure, I increase the version number and add a new migration function.

Then at startup, I would run each migration function until I get to my target version. The last step of each migration would be to update the version record to represent the version I have migrated to. The very first launch of the app would have no version table and this would indicate you need to run the MigrateFrom0To1 function, which would create the version table and populate the single row.


This is a great solution. Lots of work but once it’s in place it should be fine. Thank you for the tips!