You can run migrations against your database schema now.
Please note, support is limited to a one way migration.

A Migration is defined as one or more of the following things.
  • Add a table(s)
  • Remove a table(s)
  • Add a column(s) to an existing table
  • Remove a column(s) from an existing table
  • Change Column(s) types
  • Execute arbitrary database commands

1. To setup the migrator, setup a new project (class library) in your solution and copy DataAccess.Migrations.exe into your project.

After you copy the required files into your project set the following properties under project properties -> debug
  • Start External Program: <path to project>\bin\Debug\DataAccess.Migrations.exe
  • Command Line Arguments: Path:<path to project>\bin\Debug\Migrations.dll

Set the following things on the project files
  • DataAccess.Migrations.exe -> Copy to output always

2. Add Reference to required assemblies
  • DataAccess.Migrations.exe
  • Whatever is required for your datastore (in the example mysql)

references.png

3. Add a file to setup your migrator
In this file, inherit from DBMigrator and implement GetDataStore()

namespace Migrations
{
    public class Migrator : DBMigrator
    {
        protected override IDataStore GetDataStore()
        {
            return new MySqlDataStore(ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
        }
    }
}



4. Add a folder for your migrations, views, and stored procedures
  • <Project>\Migrations
  • <Project>\Migrations\StoredProcs
  • <Project>\Migrations\Views

folders.png

5. Define your migrations
Add a code file to your migrations folder for each migration you want to run, give it a name and inherit from DBMigration.

After you have done this implement the functions you need, when you run the project it will perform the migrations for you.

namespace Migrations.Migrations
{
    public class Foo : DBMigration
    {
        public override System.Linq.Expressions.Expression AddColumn()
        {
            return this.MakeExpression<Bar, string>(r => r.Name);
        }
    }
}


The migrator will pull the column properties from the standard sauce attributes. If you have a migration that needs to run after another simply add a RequiredAfter to your migration class

namespace Migrations.Migrations
{
    [RequiredAfter(typeof(AddBar))]
    public class Foo : DBMigration
    {
        public override System.Linq.Expressions.Expression AddColumn()
        {
            return this.MakeExpression<Bar, string>(r => r.Name);
        }
    }
}


When you run the migrator it will perform the migrations per the definitions. If you want the migrator to handle definitions of views and such, add the .sql file to the appropriate folder and set it to be an embeded resource.

Last edited Dec 14, 2013 at 6:29 PM by iamkrillin, version 2

Comments

No comments yet.