using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.EntityFrameworkCore; namespace IM.InitCommon.Management; public static class DeploymentCommands { public static bool ApplyMigrationsIfRequested(this WebApplication app, string[] args) { if (!args.Contains("--migrate")) return false; using var scope = app.Services.CreateScope(); foreach (var probe in scope.ServiceProvider.GetServices().Where(x => x.Context.Database.GetMigrations().Any())) probe.Context.Database.Migrate(); Console.WriteLine("服务数据库迁移完成"); return true; } }