using System.Reflection; using Data; using Microsoft.EntityFrameworkCore; namespace Executable; public static class HostExtensions { public static async Task Init(this IHost host) { ILogger logger = host.Services.GetRequiredService>(); Version? version = Assembly.GetExecutingAssembly().GetName().Version; logger.LogInformation( version is null ? "Cleanuparr version not detected" : $"Cleanuparr v{version.Major}.{version.Minor}.{version.Build}" ); logger.LogInformation("timezone: {tz}", TimeZoneInfo.Local.DisplayName); // Apply db migrations var eventsContext = host.Services.GetRequiredService(); if ((await eventsContext.Database.GetPendingMigrationsAsync()).Any()) { await eventsContext.Database.MigrateAsync(); } var configContext = host.Services.GetRequiredService(); if ((await configContext.Database.GetPendingMigrationsAsync()).Any()) { await configContext.Database.MigrateAsync(); } return host; } }