Skip to content

developingchris/fluentmigrator

 
 

Repository files navigation

FluentMigrator

Fluent migrations for .NET!

Project Info

Getting started with the example project

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
from the command line in the projects root directory. This will
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

Example Migration


[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");
	}
}

Example usage of console runner

tools\fluentmigrator\FluentMigrator.Console.exe /connection "Data Source=db\db.sqlite;Version=3;" /db sqlite /target build\Migrations.dll

About

fluent migrations for .net

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%