From 5201e6e4748e965cc9f6f55f058800f990bf2c20 Mon Sep 17 00:00:00 2001 From: Reimar Date: Wed, 19 Mar 2025 13:19:14 +0100 Subject: [PATCH] Run migrations on startup --- backend/Api/Program.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/Api/Program.cs b/backend/Api/Program.cs index de998ca..5490e59 100644 --- a/backend/Api/Program.cs +++ b/backend/Api/Program.cs @@ -2,14 +2,14 @@ using Api; using Microsoft.AspNetCore; using Microsoft.EntityFrameworkCore; -public class Program -{ - private static void Main(string[] args) - { - CreateWebHostBuilder(args).Build().Run(); - } - // Calls the startup class and creates the webinterface - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); -} \ No newline at end of file +var app = WebHost.CreateDefaultBuilder(args) + .UseUrls("http://0.0.0.0:5000") + .UseStartup() + .Build(); + +await using var scope = app.Services.CreateAsyncScope(); +await using var db = scope.ServiceProvider.GetService(); +await db.Database.MigrateAsync(); + +app.Run(); +