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.
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using Heimdall.Domain.Entities;
|
|
using Heimdall.Infrastructure.Data.Interceptors;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Heimdall.Infrastructure.Data;
|
|
|
|
public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>
|
|
{
|
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
|
|
|
// Domain entities
|
|
public DbSet<Site> Sites => Set<Site>();
|
|
public DbSet<Agent> Agents => Set<Agent>();
|
|
public DbSet<Camera> Cameras => Set<Camera>();
|
|
public DbSet<CameraCredentials> CameraCredentials => Set<CameraCredentials>();
|
|
public DbSet<CameraDetectionProfile> CameraDetectionProfiles => Set<CameraDetectionProfile>();
|
|
public DbSet<UserSite> UserSites => Set<UserSite>();
|
|
public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
|
|
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
|
public DbSet<AppSetting> AppSettings => Set<AppSetting>();
|
|
public DbSet<AgentSetting> AgentSettings => Set<AgentSetting>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
|
|
builder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
|
|
|
|
// Global soft-delete filter
|
|
builder.Entity<Site>().HasQueryFilter(e => !e.IsDeleted);
|
|
builder.Entity<Agent>().HasQueryFilter(e => !e.IsDeleted);
|
|
builder.Entity<Camera>().HasQueryFilter(e => !e.IsDeleted);
|
|
}
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
optionsBuilder
|
|
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
|
.AddInterceptors(
|
|
new AuditInterceptor(),
|
|
new SoftDeleteInterceptor());
|
|
|
|
base.OnConfiguring(optionsBuilder);
|
|
}
|
|
}
|