#region License //The contents of this file are subject to the Mozilla Public License //Version 1.1 (the "License"); you may not use this file except in //compliance with the License. You may obtain a copy of the License at //http://www.mozilla.org/MPL/ //Software distributed under the License is distributed on an "AS IS" //basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the //License for the specific language governing rights and limitations //under the License. #endregion namespace Migrator.Framework { /// /// 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. /// /// /// /// The following migration creates a new Customer table. /// (File 003_AddCustomerTable.cs) /// /// [Migration(3)] /// public class AddCustomerTable : Migration /// { /// public override void Up() /// { /// Database.AddTable("Customer", /// new Column("Name", typeof(string), 50), /// new Column("Address", typeof(string), 100) /// ); /// } /// public override void Down() /// { /// Database.RemoveTable("Customer"); /// } /// } /// /// public abstract class Migration : IMigration { private ITransformationProvider _transformationProvider; public string Name { get { return StringUtils.ToHumanName(GetType().Name); } } /// /// Defines tranformations to port the database to the current version. /// public abstract void Up(); /// /// This is run after the Up transaction has been committed /// public virtual void AfterUp() { } /// /// Defines transformations to revert things done in Up. /// public abstract void Down(); /// /// This is run after the Down transaction has been committed /// public virtual void AfterDown() { } /// /// Represents the database. /// . /// /// Migration.Framework.ITransformationProvider public ITransformationProvider Database { get { return _transformationProvider; } set { _transformationProvider = value; } } /// /// This gets called once on the first migration object. /// public virtual void InitializeOnce(string[] args) { } } }