using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using WorkTime.Models; namespace WorkTime.Database; internal sealed class DatabaseContext(DbContextOptions options) : DbContext(options) { public DbSet Entries { get; set; } } internal sealed class DbMigrationService(IServiceProvider provider) : IHostedService { public async Task StartAsync(CancellationToken cancellationToken) { await using var scope = provider.CreateAsyncScope(); var context = scope.ServiceProvider.GetRequiredService(); await context.Database.MigrateAsync(cancellationToken); } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }