回滚到FluentMigrator中的特定迁移 [英] Rollback to a specfic Migration in FluentMigrator

查看:187
本文介绍了回滚到FluentMigrator中的特定迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经使用FluentMigrator创建了一个三表,并分别给出了它们的版本号1,2,3。现在有什么办法可以回滚到版本2.我的意思是回滚后,我应该有表1和2,但不是3。

解决方案

这里是一个批处理文件,我使用的命令行亚军工具

  @echo off 
如果%1 ==rollbackgoto rollback
if%1==goto migrate
if%1==versiongoto version
if%1== downgoto down
goto error

:migrate
migrate -db SqlServer2014 -connectionServer = [YOUR CONNECT STRING]-assembly[Your MigRATION ASSEMBLY]
goto done
$ b $:rollback
migrate -db SqlServer2014 -connectionServer = [YOUR CONNECT STRING]-assembly[YOUR MIGRATION ASSEMBLY]-task rollback:all
转到完成
$ b:版本
迁移-db SqlServer2014 -version%2-connection服务器= [您的连接字符串]-assembly[您的移植汇编]
goto done

:down
migrate -db SqlServer2014 -version%2 -connectionServer = [YOUR CONNEC TTION STRING]-assembly[您的移植汇编]-task rollback:toversion

:error
echo无效命令

:done
echoCompleted

然后您将使用第四个选项:down如下


$ b $ ol
  • 在批处理文件所在的目录中打开一个Cmd,命令行运行程序dll和迁移程序集dll需要存在于该目录中

  • 运行以下[批处理文件名称] .bat [版本您想要回滚到:即,您希望作为最后一个的迁移]

    所以在你的例子中,这将是下降2,这将回滚3,你会保持1和2.



    更多关于< a href =https://github.com/schambers/fluentmigrator/wiki/Command-Line-Runner-Options =nofollow>命令行亚军


    Suppose I have crated a three Table using FluentMigrator and gave them version Number 1, 2, 3 respectively. Now Is there any way to rollback till version 2. I mean After rollback I should have Table 1 and 2 but not 3.

    解决方案

    Here is a batch file I use with the command line runner tool

    @echo off
    if "%1" == "rollback" goto rollback
    if "%1" == "" goto migrate
    if "%1" == "version" goto version
    if "%1" == "down" goto down
    goto error
    
    :migrate
    migrate -db SqlServer2014 -connection "Server=[YOUR CONNECTTION STRING]" -assembly "[YOUR MIGRATION ASSEMBLY]"
    goto done
    
    :rollback
    migrate -db SqlServer2014 -connection "Server=[YOUR CONNECTTION STRING]" -assembly "[YOUR MIGRATION ASSEMBLY]" -task rollback:all
    goto done
    
    :version
    migrate -db SqlServer2014 -version "%2" -connection "Server=[YOUR CONNECTTION STRING]" -assembly "[YOUR MIGRATION ASSEMBLY]"
    goto done
    
    :down
    migrate -db SqlServer2014 -version %2 -connection "Server=[YOUR CONNECTTION STRING]" -assembly "[YOUR MIGRATION ASSEMBLY]" -task rollback:toversion
    
    :error
    echo "No valid command"
    
    :done
    echo "Completed"
    

    Then you would use the forth option: down as follows

    1. Open a Cmd in the directory the batch file exists, the command line runner dlls and the migration assembly dll need to exist in that directory
    2. Run the following [Batch File Name].bat down [Version YOU WANT TO ROLLBACK TO: i.e., Migration you want as your last one]

    So in your example that would be "down 2", which will rollback 3 and you would keep 1 and 2.

    More about Command Line Runner

    这篇关于回滚到FluentMigrator中的特定迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆