在 Fluent Migrator 中回滚到以前的版本
我正在尝试使用流畅的迁移器来进行我的项目的迁移。但由于缺乏文档,我正在努力弄清楚如何回滚并为我的迁移类调用 Down
方法。
我使用初始版本 1 类设置了数据库:
[Migration(1)]
public class Baseline : Migration
{
public override void Up()
{
Execute.Script("1_Baseline\\baseline.sql");
}
public override void Down() { }
}
我通过包含以下内容的批处理文件运行迁移:
“....\tools\fluttermigrator\migrate.exe”--connection“数据 源=.\sqlexpress;初始目录=ekmDomains;集成 安全性 = true;multipleactiveresultsets = true;" --db SqlServer2005 --target "bin\Release\EkmDomains.Migrations.dll"
这工作正常。因此,我编写了第二个迁移类来测试它:
[Migration(2)]
public class AddNewTable : Migration
{
public override void Up()
{
Create.Table("NewTable").WithColumn("name").AsString();
}
public override void Down()
{
Delete.Table("NewTable");
}
}
再次运行批处理文件后,一切正常。然后我查看了 Fluent 迁移工具的命令行选项,并看到了一个 --version
选项。我假设要回滚到以前的版本,我只需提供 --version 1
并且将调用 AddNewTable
的 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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要向下迁移,请使用
-t migrate:down
。除了 down 和 up 之外,migrate.exe 的帮助还列出了 rollback、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
androllback:all
.