You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

# Database Migration Script
$ErrorActionPreference = "Stop"
function Write-Status {
param(
[string]$Message,
[string]$Status = "Info"
)
$color = switch ($Status) {
"Success" { "Green" }
"Error" { "Red" }
"Warning" { "Yellow" }
default { "White" }
}
Write-Host "[$Status] $Message" -ForegroundColor $color
}
try {
# Check if projects exist
if (-not (Test-Path "src/X1.Infrastructure")) {
throw "Infrastructure project not found"
}
if (-not (Test-Path "src/X1.WebAPI")) {
throw "WebAPI project not found"
}
# Build project
Write-Status "Building project..." "Info"
dotnet build "src/X1.Infrastructure" -c Release
if ($LASTEXITCODE -ne 0) {
throw "Project build failed"
}
Write-Status "Project built successfully" "Success"
# Add migration
Write-Status "Adding database migration..." "Info"
$migrationName = "AddRealNameToAppUser"
dotnet ef migrations add $migrationName --project src/X1.Infrastructure --startup-project src/X1.WebAPI
if ($LASTEXITCODE -ne 0) {
throw "Failed to add migration"
}
Write-Status "Migration added successfully" "Success"
# Update database
Write-Status "Updating database..." "Info"
dotnet ef database update --project src/X1.Infrastructure --startup-project src/X1.WebAPI
if ($LASTEXITCODE -ne 0) {
throw "Database update failed"
}
Write-Status "Database updated successfully" "Success"
} catch {
Write-Status "Error occurred: $_" "Error"
exit 1
}