Question

I have an application written in C++ which uses an SQLite database to store information. I need a way of assigning a version number to the database. By this I mean, I need to be able to assign a version number to the state of the database, and if a new 'state' (version) is available, then I need to update the current database state to match the state of the updated version.

I am wondering whether it would be good practice to store the information required for this to happen in a table. I would need the version number, and then some way of storing the tables and their columns related to each version number. This would allow me to make comparisons etc.

I realise that this question Set a version to a SQLite database file is related, however it doesn't quite answer my question, as I am unsure if my approach is correct, and if so, how I go about achieving this.

All help is much appreciated.

Was it helpful?

Solution

Use PRAGMA user_version to read and store an integer value in the database file.

When the version in your code and database file are the same, do nothing. When they are different, upgrade/downgrade accordingly and update the version number.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top