366991046a
地址已绑定编译结果,支持历史记录切换功能 Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Reviewed-on: PostGuard/Canon#51 Co-authored-by: Ichirinko <1621543655@qq.com> Co-committed-by: Ichirinko <1621543655@qq.com>
21 lines
727 B
C#
21 lines
727 B
C#
namespace Canon.Server.Services;
|
|
|
|
public class DatabaseSetupService(IServiceProvider serviceProvider, ILogger<DatabaseSetupService> logger)
|
|
: IHostedService
|
|
{
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
using IServiceScope scope = serviceProvider.CreateScope();
|
|
CompileDbContext dbContext = scope.ServiceProvider.GetRequiredService<CompileDbContext>();
|
|
|
|
logger.LogInformation("Clear old entities in database.");
|
|
dbContext.CompileResults.RemoveRange(dbContext.CompileResults);
|
|
await dbContext.SaveChangesAsync(cancellationToken);
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|