apply pending migrations each start

This commit is contained in:
Alan Moon 2025-03-18 16:33:55 -07:00
parent 625af3af7d
commit aee7f7ff15

View File

@ -7,6 +7,7 @@ using sodoff.Services;
using sodoff.Utils; using sodoff.Utils;
using System.Xml; using System.Xml;
using System.Net; using System.Net;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -64,6 +65,13 @@ using var scope = app.Services.CreateScope();
scope.ServiceProvider.GetRequiredService<DBContext>().Database.EnsureCreated(); scope.ServiceProvider.GetRequiredService<DBContext>().Database.EnsureCreated();
// ensure any new migrations are applied
var migrations = scope.ServiceProvider.GetRequiredService<DBContext>().Database.GetPendingMigrations();
if (migrations != null)
// apply them
await scope.ServiceProvider.GetRequiredService<DBContext>().Database.MigrateAsync();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (assetServer) if (assetServer)