[Interest] Best way to handle database migrations on QML

Gian Maxera gmaxera at gmail.com
Fri Oct 23 13:28:21 CEST 2015


Hello Daniel,
I also develop website using Laravel (a PHP framework), and for migration they use a special table called “migration” with two column: “migration” and “batch”.
The “migration” is a unique name identifying the migration.
“batch” is a incremental number indicating where the migration has been done.
Suppose in the table you see:

“Migration 1”, 1
“Migration 2”, 1
“Migration 3”, 2
“Migration 4”, 3
“Migration 5”, 3

This it means that your database has been “migrated” three times. The first time it apply “Migration 1” and “Migration 2”, the second time it apply “Migration 3” and the third time it apply “Migration 4” and “Migration 5”.

I don’t know if it’s a suitable approach for your case. But it seems to me simple and effective.

Ciao,
Gianluca.


> On 23 Oct 2015, at 12:21, Daniel França <daniel.franca at gmail.com> wrote:
> 
> Any idea?
> 
> Em qui, 22 de out de 2015 às 13:30, Daniel França <daniel.franca at gmail.com <mailto:daniel.franca at gmail.com>> escreveu:
> 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/quickmodel <https://github.com/danielfranca/quickmodel>
> 
> But 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 <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
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151023/229599cd/attachment.html>


More information about the Interest mailing list