Skip to content

Database Migration Options

randomcoder edited this page Jun 3, 2012 · 2 revisions

There will be times when we make changes to the database schema that break the app. We need a means of migrating the database in these cases.

Migration in Boot

The first proposal is to perform migration checks in Boot.scala. This way the migration will be performed after the database is initialise and before the main app is started.

The proposed mechanism involves storing a set of migration functions against a db version number that introduced the changes.

  1. Check the stored db version number.
  • If there is no number then assume version 0
  1. Compare the retrieved version, with the current version
  • Current version is stored in main properties file.
  1. For each version change between stored version and current version apply the changes mapped to that version.

This means that the first changes will be for version 1.

Migration of Changed Record Classes

To handle cases where the structure of a record changes in a breaking fashion, e.g. changing the type of an existing record then I suggest the old version be renamed to a transitional record type that uses the same collection as the original type and then all records from the transitional type can be used to create new records of the new type with a transformation function.

Whether or not the transitional classes are kept over time is an issue to think about.

Clone this wiki locally