Best way to handle database migrations on QML
-
Hi guys,
I'm developing a single file ORM library for QML.
For now it's doing most of the main operations on tables.
You can see it here, with a basic documentation as well: https://github.com/danielfranca/quickmodelBut now I'm trying to implement a way to have migrations, and can't find a good solution for that.
I don't want anything complex, my goal will be to have something that you simply change the table you want and increase the database version (then the tables gonna be recreated and populated with existent data).
I know about the changeVersion method on LocalStorage: http://doc.qt.io/qt-5/qtquick-localstorage-qmlmodule.html
But I'm not sure about how to use it.
i.e:
I call openDatabaseSync with version 1.0 and create my tables.
Then I change it to version 1.1 and call changeVersion("1.0", "1.1")But the next time my app runs it's not gonna open the database, instead it'll give me an error "Version mismatch", because now the database ini says that the database version is 1.1, not 1.0.
And if I just change the open parameters to send "1.1", it's not gonna even open in the first run, giving the same error, because ini file will say that the version is 1.0, not 1.1.
To workaround this issue I'm just playing around with my own version control, and ignoring the builtin QML solution.
But it looks wrong =/
Probably I'm missing something and couldn't understand correctly.
Does anyone can help me find out a good solution?Best,
Daniel -
Hello, I am also developping an ORM for QML and I had the same problem. I do not know if this is the best solution but, I think that saving informations like the database name and version in a Settings {} component will permit to manage changes when they occur.
Hope it helped.