migrate.bat
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@echo off
setlocal enabledelayedexpansion
set STARTUP=src\Rcs.Api\Rcs.Api.csproj
set PROJECT=src\Rcs.Infrastructure\Rcs.Infrastructure.csproj
set CONTEXT=AppDbContext
set CONFIGURATION=Release
set TIMESTAMP=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
set TIMESTAMP=%TIMESTAMP: =0%
set MIGRATION_NAME=Migration_%TIMESTAMP%
echo ========================================
echo HaHRCS Database Migration Tool
echo ========================================
if "%1"=="-apply" goto apply
if "%1"=="-script" goto script
:create
echo [INFO] Creating migration: %MIGRATION_NAME%
call :build
dotnet ef migrations add %MIGRATION_NAME% --startup-project %STARTUP% --project %PROJECT% --context %CONTEXT% --configuration %CONFIGURATION% --no-build
if errorlevel 1 (
echo [ERROR] Failed to create migration
exit /b 1
)
echo [SUCCESS] Migration created
echo [INFO] Applying database migration...
call :build
dotnet ef database update --startup-project %STARTUP% --project %PROJECT% --context %CONTEXT% --configuration %CONFIGURATION% --no-build
if errorlevel 1 (
echo [ERROR] Failed to update database
exit /b 1
)
echo [SUCCESS] Database updated
goto end
:apply
echo [INFO] Applying database migration...
call :build
dotnet ef database update --startup-project %STARTUP% --project %PROJECT% --context %CONTEXT% --configuration %CONFIGURATION% --no-build
if errorlevel 1 (
echo [ERROR] Migration failed
exit /b 1
)
echo [SUCCESS] Migration applied
goto end
:script
echo [INFO] Generating SQL migration script...
call :build
if not exist ".specstory\history\sql" mkdir ".specstory\history\sql"
dotnet ef migrations script --startup-project %STARTUP% --project %PROJECT% --context %CONTEXT% --output ".specstory\history\sql\%TIMESTAMP%_migration.sql" --idempotent --configuration %CONFIGURATION% --no-build
if errorlevel 1 (
echo [ERROR] Failed to generate SQL script
exit /b 1
)
echo [SUCCESS] SQL script generated
goto end
:build
echo [INFO] Building project (%CONFIGURATION%)...
dotnet build %STARTUP% --configuration %CONFIGURATION% -m:1
if errorlevel 1 (
echo [ERROR] Build failed. Please stop running Rcs.Api or other dotnet processes that may lock dll files, then retry.
exit /b 1
)
goto :eof
:end
echo ========================================
echo Done
echo ========================================