Fluent migrations for .NET!
- Project Home: code.google.com/p/fluentmigrator
- Discussions: [email protected]
- Bug/Feature Tracking: fluentmigrator.lighthouseapp.com/
The example project is a class library that contains the migrations, and a rakefile to wrap the Migrator.Console.exe calls.
You will need ruby, rubygems and the rake gem installed. Instructions to do this can be found here
Run
rake compile
compile the application and copy the required files over to the example project
src/FluentMigrator.Example/tools/FluentMigrator. cd into the example project and compile it:
cd src\FluentMigrator.Example
rake
rake -T
This will list the available commands
rake clean
rake compile
rake db:delete
rake db:migrate
rake db:migrate:up
rake db:migrate:down
rake db:rollback
The db:migrate commands can take an optional VERSION parameter
rake db:migrate VERSION=20090906205342
db:rollback can take an optional STEPS parameter.
rake db:rollback STEPS=2
[Migration(1)]
public class TestCreateAndDropTableMigration: Migration
{
public override void Up()
{
Create.Table("TestTable")
.WithColumn("Id").AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("Name").AsString(255).NotNullable().WithDefaultValue("Anonymous");
Create.Table("TestTable2")
.WithColumn("Id").AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("Name").AsString(255).Nullable()
.WithColumn("TestTableId").AsInt32().NotNullable();
Create.Index("ix_Name").OnTable("TestTable2").OnColumn("Name").Ascending()
.WithOptions().NonClustered();
Create.Column("Name2").OnTable("TestTable2").AsBoolean().Nullable();
Create.ForeignKey("fk_TestTable2_TestTableId_TestTable_Id")
.FromTable("TestTable2").ForeignColumn("TestTableId")
.ToTable("TestTable").PrimaryColumn("Id");
Insert.IntoTable("TestTable").Row(new { Name = "Test" });
}
public override void Down()
{
Delete.Table("TestTable2");
Delete.Table("TestTable");
}
}
tools\fluentmigrator\FluentMigrator.Console.exe /connection "Data Source=db\db.sqlite;Version=3;" /db sqlite /target build\Migrations.dll