-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathadd-migration-windows.bat
More file actions
136 lines (114 loc) · 3.09 KB
/
Copy pathadd-migration-windows.bat
File metadata and controls
136 lines (114 loc) · 3.09 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
REM Store the script directory
set "SCRIPT_DIR=%~dp0"
:main_menu
cls
echo.
echo ==== Select a service ====
echo 1. Inventory
echo 2. Order
echo 0. Exit
echo.
set /p choice="Enter your choice (1-2, 0 to exit): "
if "%choice%"=="1" goto inventory
if "%choice%"=="2" goto order
if "%choice%"=="0" goto exit
echo.
echo [ERROR] Invalid choice '%choice%'. Please select 1, 2, or 0.
echo.
pause
goto main_menu
:inventory
cd /d "%SCRIPT_DIR%"
call :process_migration "Inventory" "Inventory.Infrastructure" "Inventory.Api" "src\Services\Inventory\Core"
if errorlevel 1 goto main_menu
set /p continue="Do you want to create another migration? (y/n): "
if /i not "%continue%"=="y" goto exit
goto main_menu
:order
cd /d "%SCRIPT_DIR%"
call :process_migration "Order" "Order.Infrastructure" "Order.Api" "src\Services\Order\Core"
if errorlevel 1 goto main_menu
set /p continue="Do you want to create another migration? (y/n): "
if /i not "%continue%"=="y" goto exit
goto main_menu
:process_migration
set "ServiceName=%~1"
set "InfrastructureProject=%~2"
set "ApiProject=%~3"
set "ServiceDir=%~4"
echo.
echo Your service: %ServiceName%
echo Infrastructure project: %InfrastructureProject%
echo API project: %ApiProject%
echo Service directory: %ServiceDir%
echo.
set /p migrationName="Enter migration name: "
if "%migrationName%"=="" (
echo.
echo [ERROR] Migration name cannot be empty.
echo.
pause
exit /b 1
)
REM Navigate to service directory
echo.
echo -- Navigating to %ServiceDir% --
cd /d "%SCRIPT_DIR%%ServiceDir%"
echo Current directory: %CD%
REM Check if infrastructure project exists
if not exist "%InfrastructureProject%" (
echo.
echo [ERROR] Infrastructure project '%InfrastructureProject%' not found in current directory.
echo Expected directory: %CD%\%InfrastructureProject%
echo.
echo Contents of current directory:
dir /b
echo.
pause
exit /b 1
)
REM Ensure dotnet-ef is installed
echo.
echo -- Ensure dotnet-ef is installed --
echo.
dotnet tool install --global dotnet-ef --version 8.0.6 >nul 2>&1
REM Create migration
echo.
echo -- Creating migration '%migrationName%' for %ServiceName% service --
echo.
dotnet ef migrations add %migrationName% --project %InfrastructureProject% --startup-project ..\Api\%ApiProject% --output-dir Data\Migrations
if errorlevel 1 (
echo.
echo [ERROR] Failed to create migration. Please check the error messages above.
echo.
pause
exit /b 1
)
REM Update database
echo.
echo -- Updating database for %ServiceName% service --
echo.
dotnet ef database update --project %InfrastructureProject% --startup-project ..\Api\%ApiProject%
if errorlevel 1 (
echo.
echo [ERROR] Failed to update database. Please check the error messages above.
echo.
pause
exit /b 1
)
REM Success
echo.
echo [SUCCESS] Migration completed successfully for %ServiceName% service!
echo.
exit /b 0
:exit
cd /d "%SCRIPT_DIR%"
echo.
echo -- Returning to script directory: %SCRIPT_DIR% --
echo Thank you for using the migration script!
echo.
echo Press any key to continue...
pause >nul