Rolling back to previous version in Fluent Migrator

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 02:27:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8383858/rolling-back-to-previous-version-in-fluent-migrator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!