fix(db): correct Site index filter column casing ("is_deleted" → "IsDeleted")
The filtered index IX_sites_IsDeleted uses a WHERE clause referencing "is_deleted" (lowercase underscore) but the column is "IsDeleted" (PascalCase). PostgreSQL quoted identifiers are case-sensitive, causing Npgsql.PostgresException on migration. Fixes remaining HEIMDALL issues on GlitchTip.
This commit is contained in:
1 parent
f43297bf08
commit
0f22a60fbc
4 files changed
+19
-9
No files matched your search
@@ -36,9 +36,11 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.AddInterceptors(
|
||||
new AuditInterceptor(),
|
||||
new SoftDeleteInterceptor());
|
||||
optionsBuilder
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
||||
.AddInterceptors(
|
||||
new AuditInterceptor(),
|
||||
new SoftDeleteInterceptor());
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ public class SiteConfiguration : IEntityTypeConfiguration<Site>
|
||||
// Indexes
|
||||
builder.HasIndex(s => s.Name);
|
||||
builder.HasIndex(s => s.IsDeleted)
|
||||
.HasFilter("\"is_deleted\" = false");
|
||||
.HasFilter("\"IsDeleted\" = false");
|
||||
}
|
||||
}
|
||||
@@ -29,12 +29,17 @@ public static class DependencyInjection
|
||||
var dbName = configuration.GetValue<string>("InMemoryDbName") ?? "HeimdallTestDb";
|
||||
services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseInMemoryDatabase(dbName));
|
||||
services.AddDbContextFactory<AppDbContext>(options =>
|
||||
options.UseInMemoryDatabase(dbName));
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(connectionString, npgsql =>
|
||||
npgsql.MigrationsHistoryTable("__EFMigrationsHistory", "public")));
|
||||
services.AddDbContextFactory<AppDbContext>(options =>
|
||||
options.UseNpgsql(connectionString, npgsql =>
|
||||
npgsql.MigrationsHistoryTable("__EFMigrationsHistory", "public")));
|
||||
}
|
||||
|
||||
// Identity
|
||||
|
||||
@@ -7,23 +7,26 @@ namespace Heimdall.Workers.Jobs;
|
||||
/// <summary>
|
||||
/// Marks agents as Offline if no heartbeat received for 90+ seconds.
|
||||
/// Runs every minute via Hangfire recurring job.
|
||||
/// Uses IDbContextFactory to avoid sharing a DbContext across Hangfire worker threads.
|
||||
/// </summary>
|
||||
public class HeartbeatMonitorJob
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
private readonly IDbContextFactory<AppDbContext> _dbFactory;
|
||||
private readonly ILogger<HeartbeatMonitorJob> _logger;
|
||||
|
||||
public HeartbeatMonitorJob(AppDbContext db, ILogger<HeartbeatMonitorJob> logger)
|
||||
public HeartbeatMonitorJob(IDbContextFactory<AppDbContext> dbFactory, ILogger<HeartbeatMonitorJob> logger)
|
||||
{
|
||||
_db = db;
|
||||
_dbFactory = dbFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync(CancellationToken ct)
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync(ct);
|
||||
|
||||
var timeoutThreshold = DateTime.UtcNow.AddSeconds(-90);
|
||||
|
||||
var staleAgents = await _db.Agents
|
||||
var staleAgents = await db.Agents
|
||||
.Where(a => a.Status == AgentStatus.Online
|
||||
&& a.LastHeartbeat != null
|
||||
&& a.LastHeartbeat < timeoutThreshold)
|
||||
@@ -39,6 +42,6 @@ public class HeartbeatMonitorJob
|
||||
agent.MarkOffline();
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync(ct);
|
||||
await db.SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user