17 lines
668 B
C#
17 lines
668 B
C#
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<ManagementDbProbe>().Where(x => x.Context.Database.GetMigrations().Any()))
|
|
probe.Context.Database.Migrate();
|
|
Console.WriteLine("服务数据库迁移完成"); return true;
|
|
}
|
|
}
|