diff --git a/src/Heimdall.Infrastructure/Data/AppDbContext.cs b/src/Heimdall.Infrastructure/Data/AppDbContext.cs index 7b2442a..4b67cbb 100644 --- a/src/Heimdall.Infrastructure/Data/AppDbContext.cs +++ b/src/Heimdall.Infrastructure/Data/AppDbContext.cs @@ -72,6 +72,7 @@ public class AppDbContext : IdentityDbContext builder.Entity().HasQueryFilter(e => e.Agent == null || !e.Agent.IsDeleted); builder.Entity().HasQueryFilter(e => e.Site == null || !e.Site.IsDeleted); builder.Entity().HasQueryFilter(e => e.Camera == null || !e.Camera.IsDeleted); + builder.Entity().HasQueryFilter(e => e.DiscoveryResult == null || e.DiscoveryResult.Site == null || !e.DiscoveryResult.Site.IsDeleted); // Group soft-delete filters builder.Entity().HasQueryFilter(e => !e.IsDeleted); diff --git a/src/Heimdall.Infrastructure/DependencyInjection.cs b/src/Heimdall.Infrastructure/DependencyInjection.cs index 8c007d5..1ece446 100644 --- a/src/Heimdall.Infrastructure/DependencyInjection.cs +++ b/src/Heimdall.Infrastructure/DependencyInjection.cs @@ -106,7 +106,7 @@ public static class DependencyInjection } #pragma warning disable SYSLIB0057 // X509Certificate2(string, string) is obsolete — X509CertificateLoader not available in this SDK - using var dpCert = new X509Certificate2(certFile.FullName, ""); + var dpCert = new X509Certificate2(certFile.FullName, ""); #pragma warning restore SYSLIB0057 dpBuilder.ProtectKeysWithCertificate(dpCert); } diff --git a/src/Heimdall.Web/Program.cs b/src/Heimdall.Web/Program.cs index 88d323a..bcf2ad4 100644 --- a/src/Heimdall.Web/Program.cs +++ b/src/Heimdall.Web/Program.cs @@ -277,31 +277,28 @@ using (var scope = app.Services.CreateScope()) var retryDelay = TimeSpan.FromSeconds(2); for (var attempt = 1; attempt <= maxRetries; attempt++) - { - try { - if (db.Database.GetPendingMigrations().Any()) + try { - logger.LogInformation("Applying pending database migrations (attempt {Attempt}/{MaxRetries})...", attempt, maxRetries); + logger.LogInformation("Applying database migrations (attempt {Attempt}/{MaxRetries})...", attempt, maxRetries); db.Database.Migrate(); logger.LogInformation("Database migrations applied successfully"); + break; + } + catch (Exception ex) when (attempt < maxRetries) + { + logger.LogWarning(ex, + "Database migration attempt {Attempt}/{MaxRetries} failed. Retrying in {Delay}s...", + attempt, maxRetries, retryDelay.TotalSeconds); + await Task.Delay(retryDelay); + retryDelay = TimeSpan.FromSeconds(retryDelay.TotalSeconds * 2); + } + catch (Exception ex) + { + logger.LogCritical(ex, "Failed to apply database migrations after {MaxRetries} attempts.", maxRetries); + throw; } - break; } - catch (Exception ex) when (attempt < maxRetries) - { - logger.LogWarning(ex, - "Database migration attempt {Attempt}/{MaxRetries} failed. Retrying in {Delay}s...", - attempt, maxRetries, retryDelay.TotalSeconds); - await Task.Delay(retryDelay); - retryDelay = TimeSpan.FromSeconds(retryDelay.TotalSeconds * 2); - } - catch (Exception ex) - { - logger.LogCritical(ex, "Failed to apply database migrations after {MaxRetries} attempts.", maxRetries); - throw; - } - } } // ── Register recurring Hangfire jobs ─────────────────────────────────