11

I am attempting to get migrations working with my project using fluent migrator. But due to the lack of documentation I am struggling to figure out how to rollback and have the Down method called for my migration class.

I set up the db with an initial version 1 class:

[Migration(1)]
public class Baseline : Migration
{
    public override void Up()
    {
        Execute.Script("1_Baseline\\baseline.sql");
    }

    public override void Down() { }
}

I am running migrations via a batch file containing the following:

"....\tools\fluentmigrator\migrate.exe" --connection "Data Source=.\sqlexpress;Initial Catalog=ekmDomains;Integrated Security=true;multipleactiveresultsets=true;" --db SqlServer2005 --target "bin\Release\EkmDomains.Migrations.dll"

This works fine. So I then wrote a second migration class just to test it out:

[Migration(2)]
public class AddNewTable : Migration
{
    public override void Up()
    {
        Create.Table("NewTable").WithColumn("name").AsString();
    }

    public override void Down()
    {
        Delete.Table("NewTable");
    }
}

Again after running the batch file, everything works ok. I then looked at the command line options for the fluent migrator tool, and saw a --version option. I assumed that to rollback to a previous version I would simply supply --version 1 and the Down of AddNewTable would be called. That, however, did not happent. The console simply displays a 'committing transaction` method then closes. But the table has not been deleted and the version number hasn't changed.

Am I doing this the wrong way or can anyone see some fundamental flaw in how I am doing this?

A. Gladkiy
  • 3,134
  • 5
  • 38
  • 82
jcvandan
  • 14,124
  • 18
  • 66
  • 103

1 Answers1

17

To migrate down, you use -t migrate:down. Besides down and up, the help for migrate.exe also lists rollback, rollback:toversion and rollback:all.

Liam
  • 27,717
  • 28
  • 128
  • 190
iheartsql
  • 186
  • 1
  • 3
  • This is all covered in more detail on the [fluent migrator console docs](https://fluentmigrator.github.io/articles/runners/runner-console.html#--task--tvalue-optional) – Liam Jun 06 '18 at 08:30