Database schema updates

前端 未结 4 1009
情深已故
情深已故 2021-02-01 06:56

I\'m working on an AIR application that uses a local SQLite database and was wondering how I could manage database schema updates when I distribute new versions of the applicati

4条回答
  •  星月不相逢
    2021-02-01 07:42

    In the case of SQLite, you can make use of the user_version pragma to track the version of the database. To get the version:

    PRAGMA user_version
    

    To set the version:

    PRAGMA user_version = 5
    

    I then keep each group of updates in an SQL file (that's embedded in the app) and run the updates needed to get up to the most recent version:

    Select Case currentUserVersion
    Case 1
      // Upgrade to version 2
    Case 2
      // Upgrade to version 3
    Case etc...
    End Select
    

    This allows the app to update itself to the most recent version regardless of the current version of the DB.

提交回复
热议问题