beroNet / Open-PBX

embedded PBX based on Asterisk, which runs on a beroNet Gateway
MIT License
5 stars 3 forks source link

database upgrade path #10

Closed crich closed 11 years ago

crich commented 11 years ago

We need some sort of upgrade path for the database. If somebody adds a feature now, which requires a database change, a device with an old database wouldn't work properly anymore.

in beroFix we use a database migration path when we update the firmware:

  1. copy the old data to temp-tables
  2. drop the tables
  3. create new tables with default values
  4. re-instert data from the temp-tables

The database needs a version number and the migration skript would check that versionnr. against its own version and would apply all the changes step by step up to most recent version.

another option, which could work is:

  1. export all database content in a datafile
  2. drop the database
  3. create the new database
  4. import all the content again

this would also be very nice, since we would have an export/import for the config than, which we could use for backup&restore.

ghost commented 11 years ago

Done.

I've chosen the later option because of the easier handling of importing/exporting the database.

A few things to consider:

  1. After making changes to the database-structure, please increment DB_VERSION
  2. To ensure the functionality of the migration-process, only change the database by adding new stuff (fields, tables) and don't change existing tables if possible.
  3. Setting sane defaults when adding a new field to a table is always a good idea.
  4. Import only works, if the version of the settings to be imported is <= the version of the currently installed database.
  5. Downgrading the database is also not supported.

Things I've tested so far: