A migration is a group of transformation applied to the database schema (or sometimes data) to port the database from one version to another. The
Up()
method must apply the modifications (eg.: create a table) and the
Down()
method must revert, or rollback the modifications (eg.: delete a table).
Each migration must be decorated with the [Migration(0)]
attribute. Each migration number (0) must be unique, or else a DuplicatedVersionException
will be trown.
All migrations are executed inside a transaction. If an exception is thrown, the transaction will be rolledback and transformations wont be applied.
It is best to keep a limited number of transformation inside a migration so you can easely move from one version of to another with fine grain modifications. You should give meaningful name to the migration class and prepend the migration number to the filename so they keep ordered, eg.: 002_CreateTableTest.cs
.
Use the Database
property to apply transformation and the Logger
property to output informations in the console (or other). For more details on transformations see ITransformationProvider.