From 915736c4e2ed92aa7cac7b84dff22d682e785b13 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 8 May 2021 23:51:40 +0100 Subject: [PATCH] migrate database --- Startup.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Startup.cs b/Startup.cs index a8a9209..4196cc1 100644 --- a/Startup.cs +++ b/Startup.cs @@ -18,6 +18,7 @@ using nuget_host.Interfaces; using nuget_host.Services; using nuget_host.Entities; using nuget_host.Models; +using System.Reflection; namespace nuget_host { @@ -70,6 +71,25 @@ namespace nuget_host { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); + try + { + using (var serviceScope = app.ApplicationServices.GetRequiredService() + .CreateScope()) + { + serviceScope.ServiceProvider.GetService() + .Database.Migrate(); + } + } + catch (TargetInvocationException ex) + { + if (ex.InnerException is InvalidOperationException) + // nothing to do ? + { + // TODO (or not) Hit the developper + } + else throw ex; + } + } app.UseStaticFiles();