Created
July 19, 2017 10:33
-
-
Save goforgold/c7ea6da0a5f13784007b36c66ec94666 to your computer and use it in GitHub Desktop.
Create Migration Script (Windows Bash)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
if /i not [%1] == [] ( | |
set migrationname=%1 | |
goto Begin | |
) | |
for /f "delims=" %%i in ('dotnet ef migrations list') do ( | |
set migrationname=%%i | |
) | |
:Begin | |
for /f "delims=:" %%i in ('dotnet ef migrations list ^| findstr /N %migrationname%') do ( | |
set /A before=%%i-1 | |
) | |
if %before% == 1 ( | |
set migrationfrom=0 | |
goto Ok | |
) | |
for /f "tokens=1* delims=:" %%i in ('dotnet ef migrations list ^| findstr /N "^" ^| findstr /B %before%') do ( | |
set migrationfrom=%%j | |
goto Ok | |
) | |
:Ok | |
echo Migration from: %migrationfrom% | |
echo Migration to: %migrationname% | |
dotnet ef migrations script %migrationfrom% %migrationname% -o Migrations/Scripts/%migrationname%.sql | |
echo Script file generated in Migrations/Scripts/%migrationname%.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment