Finished Settings page
This commit is contained in:
23
WorkTime.Database/DatabaseContext.cs
Normal file
23
WorkTime.Database/DatabaseContext.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using WorkTime.Models;
|
||||
|
||||
namespace WorkTime.Database;
|
||||
|
||||
internal sealed class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbContext(options) {
|
||||
|
||||
public DbSet<TimeEntry> 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<DatabaseContext>();
|
||||
|
||||
await context.Database.MigrateAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
Reference in New Issue
Block a user