# 设置错误时停止执行 $ErrorActionPreference = "Stop" # 设置项目路径 $projectPath = "src/CellularManagement.Infrastructure" $startupProjectPath = "src/CellularManagement.WebAPI" # 设置迁移名称 $migrationName = "AddLoginLogs" # 检查是否已存在迁移 $migrations = dotnet ef migrations list --project $projectPath --startup-project $startupProjectPath if ($migrations -match $migrationName) { Write-Host "迁移 '$migrationName' 已存在,跳过创建迁移步骤" } else { # 创建迁移 Write-Host "正在创建迁移 '$migrationName'..." dotnet ef migrations add $migrationName --project $projectPath --startup-project $startupProjectPath } # 更新数据库 Write-Host "正在更新数据库..." dotnet ef database update --project $projectPath --startup-project $startupProjectPath Write-Host "数据库更新完成!"