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