Quickstart - richardprior/MigSharp GitHub Wiki
Download the latest version of Mig#, and add a reference to the MigSharp.dll
in your project (Migrate.exe
is a command-line interface to Mig# which you do not need in order to write or execute migrations).
First, you want to write a migration. You do this by implementing the IMigration
interface and applying the MigrationExportAttribute
. For example:
[MigrationExport]
internal class Migration1 : IMigration
{
public void Up(IDatabase db)
{
db.CreateTable(TableName)
.WithPrimaryKeyColumn(ColumnNames[0], DbType.Int32);
}
}
Note that the timestamp of the migration is inferred by its post-fix. In the example above, this is 1.
The actual execution of migrations on a specific database is performed using the Migrator
type. In order to instantiate it, you need to provide the connection string and the name of the database provider:
var migrator = new Migrator(connectionString, ProviderNames.SqlServer);
To update the database to the latest version, simply call MigrateAll
and pass-in the assembly where you have defined the migration(s). For example:
migrator.MigrateAll(typeof(Migration1).Assembly);
This was a super-fast quick-intro for the caffeine drinkers amongst you. For more details, see the Manual.