Database schema updates

前端 未结 4 1003
情深已故
情深已故 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:28

    IMO the easiest thing to do is to treat an update from e.g. 1.0 to 1.5 as a succession of updates from 1.0 to 1.1, 1.1 to 1.2, and so forth. For each version change, keep a conversion script/piece of code around.

    Then, keep a table with a version field in the database, and compile into the the app the required version. On startup, if the version field does not match the compiled-in version, run all the required conversion scripts, one by one.

    The conversion scripts should ideally start a transaction and write the new version into the database as the last statement before committing the transaction.

提交回复
热议问题