Skip to content

rtw/fluentmigrator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Example usage of NAnt runner

<?xml version="1.0" encoding="UTF-8" ?>
<project name="fluentmigrator" xmlns="http://nant.sf.net/release/0.85/nant.xsd" default="migrate">
	<loadtasks assembly="../../build/FluentMigrator.NAnt.dll" />

	<target name="migrate" description="Migrate the database to the latest version">
	  	<migrate
	    		database="sqlite"
	    		connection="Data Source=:memory:;Version=3;New=True;"
			namespace="FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3"
	    		target="../../build/FluentMigrator.Tests.dll"
		/>
	</target>

	<target name="migrate-rollback" description="Migrate the database back one version">
	  	<migrate
	    		database="sqlite"
	    		connection="Data Source=:memory:;Version=3;New=True;"
			namespace="FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3"
	    		target="../../build/FluentMigrator.Tests.dll"
			task="rollback"
		/>
	</target>

	<target name="migrate-rollback-all" description="Migrates the database back to original state prior to applying migrations">
	  	<migrate
	    		database="sqlite"
	    		connection="Data Source=:memory:;Version=3;New=True;"
			namespace="FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3"
	    		target="../../build/FluentMigrator.Tests.dll"
			task="rollback:all"
		/>
	</target>
</project>

About

fluent migrations for .net

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%