Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Best way to handle database migrations on QML
Forum Updated to NodeBB v4.3 + New Features

Best way to handle database migrations on QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
localstorageqmldatabase
2 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danielfranca
    wrote on last edited by
    #1

    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

    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

    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

    1 Reply Last reply
    0
    • ibiaI Offline
      ibiaI Offline
      ibia
      wrote on last edited by ibia
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved