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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
- 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
- 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