Migration

A migration is an operation that transforms the database from one state to another. Each migration has two methods: "Up" and "Down". The first one applies the changes of the migrations to your database, the second method is responsible for undoing all changes.

Versioning

To make migrations work it's necessary to give each migration a unique ID. NMigrations will execute your migrations according to these IDs. You may use version numbers or timestamps for these IDs - however timestamps are recommended since the same version number may be used by different developers who are writing migrations concurrently which results in a conflict.

[Migration(2009, 11, 11, 9, 42, 0)]
public class InitialMigration : IMigration
{
	public void Up(Database db)
	{
	}
	
	public void Down(Database db)
	{

	}
}

The example shows a migration that uses a timestamp for versioning.

Last edited Nov 13, 2009 at 11:43 PM by sebastian_klose, version 2

Comments

amunk Nov 21, 2010 at 9:29 AM 
A tip: Specify the version of the migration using the long parameter and use a value representing the datetime in format yyyyMMddHHmmss for an alternative way to use the datetime as a versionumber.