feat(server): add database context and migrations

This commit is contained in:
Stevan Freeborn
2026-01-04 21:10:44 -06:00
parent 18b8dec374
commit 7ba17ea0e3
12 changed files with 383 additions and 0 deletions
@@ -0,0 +1,27 @@
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;
}
}