问题描述
我正在尝试使用流利的migrator在我的项目中进行迁移.但是由于缺少文档,我正在努力找出如何回滚并为迁移类调用Down
方法.
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.
我使用初始版本1的类设置数据库:
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:
这很好.因此,我然后编写了第二个迁移类以进行测试:
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");
}
}
再次运行批处理文件后,一切正常.然后,我查看了流畅的迁移器工具的命令行选项,并看到了--version
选项.我假设要回滚到以前的版本,我只需提供--version 1
即可调用AddNewTable
的Down
.但是,这没有发生.控制台仅显示提交事务"方法,然后关闭.但是该表尚未删除,版本号也没有更改.
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?
推荐答案
要向下迁移,请使用-t migrate:down
.除了上下之外,migrate.exe的帮助还列出了回滚rollback:toversion
和rollback:all
.
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
.
这篇关于在Fluent Migrator中回滚到以前的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!