From 70e933ecbbbfb8f445652dcc3dece76ada3f9eef Mon Sep 17 00:00:00 2001 From: Patrick Klaeren Date: Sat, 11 Nov 2023 20:30:03 +0000 Subject: [PATCH] Fix startup migration --- src/Accord.Domain/Accord.Domain.csproj | 1 + src/Accord.Domain/AccordContextExtensions.cs | 8 +++++++- src/Accord.Web/Accord.Web.csproj | 1 - src/Accord.Web/Program.cs | 10 +--------- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Accord.Domain/Accord.Domain.csproj b/src/Accord.Domain/Accord.Domain.csproj index 54af8f7..4c6e61f 100644 --- a/src/Accord.Domain/Accord.Domain.csproj +++ b/src/Accord.Domain/Accord.Domain.csproj @@ -5,6 +5,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/Accord.Domain/AccordContextExtensions.cs b/src/Accord.Domain/AccordContextExtensions.cs index e4aa3a3..72d0288 100644 --- a/src/Accord.Domain/AccordContextExtensions.cs +++ b/src/Accord.Domain/AccordContextExtensions.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; namespace Accord.Domain; @@ -9,4 +10,9 @@ public static IServiceCollection AddDatabase(this IServiceCollection collection, { return collection.AddDbContext(x => x.UseNpgsql(connectionString)); } + + public static async Task Migrate(AccordContext context) + { + await context.Database.MigrateAsync(); + } } \ No newline at end of file diff --git a/src/Accord.Web/Accord.Web.csproj b/src/Accord.Web/Accord.Web.csproj index 393241e..2ac05d5 100644 --- a/src/Accord.Web/Accord.Web.csproj +++ b/src/Accord.Web/Accord.Web.csproj @@ -15,7 +15,6 @@ - diff --git a/src/Accord.Web/Program.cs b/src/Accord.Web/Program.cs index e5d95da..f9f9957 100644 --- a/src/Accord.Web/Program.cs +++ b/src/Accord.Web/Program.cs @@ -101,15 +101,7 @@ using (var scope = app.Services.CreateScope()) { Log.Information("Scope created..."); - - var services = scope.ServiceProvider; - - await using var db = services.GetRequiredService(); - - Log.Information("Got Db context"); - - await db.Database.MigrateAsync(); - + await AccordContextExtensions.Migrate(scope.ServiceProvider.GetRequiredService()); Log.Information("Migrated!"); }