Files
groundsforsupport.stevanfre…/src/GroundsForSupport.Server/Data/MigrationService.cs
T

27 lines
771 B
C#
Raw Normal View History

using Microsoft.EntityFrameworkCore;
namespace GroundsForSupport.Server.Data;
internal sealed class MigrationService(
IServiceProvider serviceProvider,
ILogger<MigrationService> logger
) : IHostedService
{
private readonly IServiceProvider _serviceProvider = serviceProvider;
public async Task StartAsync(CancellationToken cancellationToken)
{
logger.LogInformation("Applying database migrations...");
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<Context>();
await context.Database.MigrateAsync(cancellationToken);
logger.LogInformation("Database migrations applied.");
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}