-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathConfigureDatabase.bat
69 lines (53 loc) · 2.58 KB
/
ConfigureDatabase.bat
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
@echo off
setlocal enabledelayedexpansion
:: Prompt for database type and class library name
set /p userInput=Enter the type of database you want to use (SqlServer, PostgreSQL, Oracle, MySql, Sqlite):
set /p classLib=Enter the name of the ClassLibrary you want to configure (Identity, Persistence, FileManager):
:: Set the directory where .sln files are located
set "directory=../"
:: Loop through each .sln file in the directory and set slnName variable
for /f "delims=" %%a in ('dir /b "%directory%\*.sln"') do (
set "slnName=%%~na"
)
echo Solution name detected: !slnName!
:: Function to add package and update ServiceRegistration.cs
if /i "%userInput%"=="PostgreSQL" (
echo Configuring for PostgreSQL...
call :AddPackageAndUpdate "UseNpgsql" "Npgsql.EntityFrameworkCore.PostgreSQL"
)
if /i "%userInput%"=="SqlServer" (
echo Configuring for SQL Server...
call :AddPackageAndUpdate "UseSqlServer" "Microsoft.EntityFrameworkCore.SqlServer"
)
if /i "%userInput%"=="Oracle" (
echo Configuring for Oracle...
call :AddPackageAndUpdate "UseOracle" "Oracle.EntityFrameworkCore"
)
if /i "%userInput%"=="MySql" (
echo Configuring for Oracle...
call :AddPackageAndUpdate "UseMySql" "Pomelo.EntityFrameworkCore.MySql"
)
if /i "%userInput%"=="Sqlite" (
echo Configuring for Oracle...
call :AddPackageAndUpdate "UseSqlite" "Microsoft.EntityFrameworkCore.Sqlite"
)
echo Configuration complete. Please perform the following steps:
echo 1. Set the connection string in appsettings.json.
echo 2. Delete existing migrations.
echo 3. Create new migrations.
echo 4. Run Project.
goto :EOF
:AddPackageAndUpdate
echo Changing directory to: ..\Src\Infrastructure\!slnName!.Infrastructure.%classLib%
pushd ..\Src\Infrastructure\!slnName!.Infrastructure.%classLib%
echo Adding package %2...
dotnet add package %2
echo Updating ServiceRegistration.cs to use %1...
powershell -Command "(Get-Content 'ServiceRegistration.cs') -replace 'UseSqlServer', '%1' | Set-Content 'ServiceRegistration.cs'"
powershell -Command "(Get-Content 'ServiceRegistration.cs') -replace 'UseNpgsql', '%1' | Set-Content 'ServiceRegistration.cs'"
powershell -Command "(Get-Content 'ServiceRegistration.cs') -replace 'UseOracle', '%1' | Set-Content 'ServiceRegistration.cs'"
powershell -Command "(Get-Content 'ServiceRegistration.cs') -replace 'UseMySql', '%1' | Set-Content 'ServiceRegistration.cs'"
powershell -Command "(Get-Content 'ServiceRegistration.cs') -replace 'UseSqlite', '%1' | Set-Content 'ServiceRegistration.cs'"
echo Configuration for %1 complete.
popd
goto :EOF