Browse Source

log database migration

pull/31/head
Jason Dove 6 years ago
parent
commit
298ed5d2fa
  1. 7
      ErsatzTV/Extensions/HostExtensions.cs

7
ErsatzTV/Extensions/HostExtensions.cs

@ -30,7 +30,7 @@ namespace ErsatzTV.Extensions @@ -30,7 +30,7 @@ namespace ErsatzTV.Extensions
private static Unit Seed(IServiceScope scope) =>
Try(() => scope.ServiceProvider)
.Bind(services => Try(GetDbContext(services)))
.Bind(ctx => Try(Migrate(ctx)))
.Bind(ctx => Try(Migrate(ctx, scope.ServiceProvider)))
.Bind(ctx => Try(InitializeDb(ctx)))
.IfFail(ex => LogException(ex, "Error occured while seeding database", scope.ServiceProvider));
@ -43,9 +43,12 @@ namespace ErsatzTV.Extensions @@ -43,9 +43,12 @@ namespace ErsatzTV.Extensions
private static TvContext GetDbContext(IServiceProvider provider) =>
provider.GetRequiredService<TvContext>();
private static TvContext Migrate(TvContext context)
private static TvContext Migrate(TvContext context, IServiceProvider provider)
{
ILogger<Program> logger = provider.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Applying database migrations");
context.Database.Migrate();
logger.LogInformation("Done applying database migrations");
return context;
}

Loading…
Cancel
Save