git-subtree-dir: backend git-subtree-mainline:ab911955edgit-subtree-split:040cfd7a75
33 lines
819 B
C#
33 lines
819 B
C#
namespace Hutopy.Web.Features.Contents.Data;
|
|
|
|
public static class InitializerExtensions
|
|
{
|
|
public static async Task InitialiseContentDbContextAsync(this WebApplication app)
|
|
{
|
|
using var scope = app.Services.CreateScope();
|
|
|
|
var initializer = scope.ServiceProvider.GetRequiredService<ContentDbContextInitializer>();
|
|
|
|
await initializer.InitialiseAsync();
|
|
}
|
|
}
|
|
|
|
public class ContentDbContextInitializer(
|
|
ILogger<ContentDbContextInitializer> logger,
|
|
ContentDbContext context
|
|
)
|
|
{
|
|
public async Task InitialiseAsync()
|
|
{
|
|
try
|
|
{
|
|
await context.Database.MigrateAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "An error occurred while initialising the content database.");
|
|
throw;
|
|
}
|
|
}
|
|
}
|