Rolling back to previous version in Fluent Migrator
Asked Answered
L

1

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?

Lubumbashi answered 5/12, 2011 at 10:23 Comment(0)
P
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.

Pfeiffer answered 6/12, 2011 at 18:31 Comment(1)
This is all covered in more detail on the fluent migrator console docsWarmblooded

© 2022 - 2024 — McMap. All rights reserved.