Migrate the db at startup
This commit is contained in:
@ -355,7 +355,7 @@ public static class HostingExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static WebApplication ConfigurePipeline(this WebApplication app)
|
internal async static Task<WebApplication> ConfigurePipeline(this WebApplication app)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
@ -365,6 +365,11 @@ public static class HostingExtensions
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||||
|
await db.Database.MigrateAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
@ -6,7 +6,7 @@ namespace Yavsc
|
|||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ namespace Yavsc
|
|||||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
||||||
.AddEnvironmentVariables()
|
.AddEnvironmentVariables()
|
||||||
.Build();
|
.Build();
|
||||||
var app = builder.ConfigureWebAppServices().ConfigurePipeline();
|
var app = await builder.ConfigureWebAppServices().ConfigurePipeline();
|
||||||
app.UseSession();
|
app.UseSession();
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user