fix(perf): eliminate N+1 in AuditLogService by adding User navigation property

Added AppUser navigation property to AuditLog entity with EF Core
configuration (FK -> UserId, SetNull on delete). Replaced the sub-query
in AuditLogService ListAsync with a direct navigation property access,
enabling EF Core to generate a single LEFT JOIN instead of N sub-queries.

Migration: AddAuditLogUserRelation
This commit is contained in:
Arnaud Dartois committed 2026-07-17 19:24:07 +00:00
1 parent 015711e156
commit ec45fa3c87
6 files changed
+906 -1

No files matched your search

+3
View File
@@ -16,6 +16,9 @@ public class AuditLog
public string? IpAddress { get; private set; }
public DateTime Timestamp { get; private set; } = DateTime.UtcNow;
// Navigation
public AppUser? User { get; set; }
private AuditLog() { } // EF Core
public AuditLog(
@@ -29,6 +29,12 @@ public class AuditLogConfiguration : IEntityTypeConfiguration<AuditLog>
builder.Property(al => al.Timestamp)
.HasDefaultValueSql("NOW()");
// Relationships
builder.HasOne(al => al.User)
.WithMany()
.HasForeignKey(al => al.UserId)
.OnDelete(DeleteBehavior.SetNull);
// Indexes
builder.HasIndex(al => al.Timestamp)
.IsDescending();
@@ -0,0 +1,856 @@
// <auto-generated />
using System;
using Heimdall.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Heimdall.Infrastructure.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20260717192341_AddAuditLogUserRelation")]
partial class AddAuditLogUserRelation
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ApiKeyHash")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("ApiKeyPrefix")
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<int>("CpuCores")
.HasColumnType("integer");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("GpuType")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<bool>("HasGpu")
.HasColumnType("boolean");
b.Property<string>("Hostname")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<DateTime?>("LastHeartbeat")
.HasColumnType("timestamp with time zone");
b.Property<long>("MemoryMb")
.HasColumnType("bigint");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("PublicIp")
.HasMaxLength(45)
.HasColumnType("character varying(45)");
b.Property<Guid>("SiteId")
.HasColumnType("uuid");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<DateTime>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<string>("Version")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.HasKey("Id");
b.HasIndex("LastHeartbeat")
.HasFilter("\"status\" = 'Online'");
b.HasIndex("SiteId");
b.ToTable("agents", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<Guid?>("CreatedByUserId")
.HasColumnType("uuid");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<DateTime?>("ExpiresAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("KeyHash")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("KeyPrefix")
.IsRequired()
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<DateTime?>("LastUsedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("SiteId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("KeyHash");
b.HasIndex("KeyPrefix");
b.HasIndex("SiteId");
b.ToTable("api_keys", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("roles", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Language")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasDefaultValue("fr");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<bool>("MustChangePassword")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<string>("Theme")
.ValueGeneratedOnAdd()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasDefaultValue("Auto");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("users", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Action")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("IpAddress")
.HasMaxLength(45)
.HasColumnType("character varying(45)");
b.Property<string>("NewValue")
.HasColumnType("text");
b.Property<string>("OldValue")
.HasColumnType("text");
b.Property<string>("ResourceId")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("ResourceType")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<DateTime>("Timestamp")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("Timestamp")
.IsDescending();
b.HasIndex("UserId");
b.HasIndex("ResourceType", "ResourceId", "Timestamp")
.IsDescending(false, false, true);
b.ToTable("audit_logs", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid?>("AgentId")
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool>("HasAudio")
.HasColumnType("boolean");
b.Property<bool>("HasMotionDetection")
.HasColumnType("boolean");
b.Property<bool>("HasPtz")
.HasColumnType("boolean");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<string>("Manufacturer")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("Model")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("RtspUrl")
.HasMaxLength(1000)
.HasColumnType("character varying(1000)");
b.Property<Guid>("SiteId")
.HasColumnType("uuid");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<DateTime>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("AgentId");
b.HasIndex("SiteId");
b.ToTable("cameras", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b =>
{
b.Property<Guid>("CameraId")
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<string>("OnvifPassword")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<string>("OnvifUsername")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasDefaultValue("admin");
b.Property<string>("RtspPassword")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<string>("RtspUsername")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<DateTime>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.HasKey("CameraId");
b.ToTable("camera_credentials", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b =>
{
b.Property<Guid>("CameraId")
.HasColumnType("uuid");
b.Property<int>("ActiveIntervalMs")
.HasColumnType("integer");
b.Property<int>("AnimalCooldownSec")
.HasColumnType("integer");
b.Property<bool>("DetectAnimal")
.HasColumnType("boolean");
b.Property<bool>("DetectMotion")
.HasColumnType("boolean");
b.Property<bool>("DetectPackage")
.HasColumnType("boolean");
b.Property<bool>("DetectPerson")
.HasColumnType("boolean");
b.Property<bool>("DetectVehicle")
.HasColumnType("boolean");
b.Property<bool>("FaceRecognition")
.HasColumnType("boolean");
b.Property<int>("IdleIntervalMs")
.HasColumnType("integer");
b.Property<double>("IoUThreshold")
.HasColumnType("double precision");
b.Property<bool>("LicensePlateRecognition")
.HasColumnType("boolean");
b.Property<int>("MaxEventsPerMinute")
.HasColumnType("integer");
b.Property<double>("MinConfidence")
.ValueGeneratedOnAdd()
.HasColumnType("double precision")
.HasDefaultValue(0.40000000000000002);
b.Property<int>("MotionIntervalMs")
.HasColumnType("integer");
b.Property<double>("MotionThreshold")
.HasColumnType("double precision");
b.Property<int>("PersonCooldownSec")
.HasColumnType("integer");
b.Property<bool>("RequireMotionForAI")
.HasColumnType("boolean");
b.Property<int>("VehicleCooldownSec")
.HasColumnType("integer");
b.Property<string>("YoloModel")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasDefaultValue("yolov8n");
b.HasKey("CameraId");
b.ToTable("camera_detection_profiles", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.Site", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Address")
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("RegistrationTokenHash")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Timezone")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasDefaultValue("UTC");
b.Property<DateTime?>("TokenExpiresAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("IsDeleted")
.HasFilter("\"is_deleted\" = false");
b.HasIndex("Name");
b.ToTable("sites", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<Guid>("SiteId")
.HasColumnType("uuid");
b.HasKey("UserId", "SiteId");
b.HasIndex("SiteId");
b.ToTable("user_sites", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<Guid>("RoleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("role_claims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("user_claims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("user_logins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<Guid>("RoleId")
.HasColumnType("uuid");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("user_roles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("user_tokens", (string)null);
});
modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b =>
{
b.HasOne("Heimdall.Domain.Entities.Site", "Site")
.WithMany("Agents")
.HasForeignKey("SiteId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Site");
});
modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b =>
{
b.HasOne("Heimdall.Domain.Entities.Site", "Site")
.WithMany()
.HasForeignKey("SiteId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Site");
});
modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b =>
{
b.HasOne("Heimdall.Domain.Entities.AppUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("User");
});
modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b =>
{
b.HasOne("Heimdall.Domain.Entities.Agent", "Agent")
.WithMany("Cameras")
.HasForeignKey("AgentId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("Heimdall.Domain.Entities.Site", "Site")
.WithMany("Cameras")
.HasForeignKey("SiteId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Agent");
b.Navigation("Site");
});
modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b =>
{
b.HasOne("Heimdall.Domain.Entities.Camera", "Camera")
.WithOne("Credentials")
.HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Camera");
});
modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b =>
{
b.HasOne("Heimdall.Domain.Entities.Camera", "Camera")
.WithOne("DetectionProfile")
.HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Camera");
});
modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b =>
{
b.HasOne("Heimdall.Domain.Entities.Site", "Site")
.WithMany()
.HasForeignKey("SiteId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Heimdall.Domain.Entities.AppUser", "User")
.WithMany("UserSites")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Site");
b.Navigation("User");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
{
b.HasOne("Heimdall.Domain.Entities.AppRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
{
b.HasOne("Heimdall.Domain.Entities.AppUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
{
b.HasOne("Heimdall.Domain.Entities.AppUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
{
b.HasOne("Heimdall.Domain.Entities.AppRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Heimdall.Domain.Entities.AppUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
{
b.HasOne("Heimdall.Domain.Entities.AppUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b =>
{
b.Navigation("Cameras");
});
modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b =>
{
b.Navigation("UserSites");
});
modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b =>
{
b.Navigation("Credentials");
b.Navigation("DetectionProfile");
});
modelBuilder.Entity("Heimdall.Domain.Entities.Site", b =>
{
b.Navigation("Agents");
b.Navigation("Cameras");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Heimdall.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddAuditLogUserRelation : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddForeignKey(
name: "FK_audit_logs_users_UserId",
table: "audit_logs",
column: "UserId",
principalTable: "users",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_audit_logs_users_UserId",
table: "audit_logs");
}
}
}
@@ -704,6 +704,16 @@ namespace Heimdall.Infrastructure.Migrations
b.Navigation("Site");
});
modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b =>
{
b.HasOne("Heimdall.Domain.Entities.AppUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("User");
});
modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b =>
{
b.HasOne("Heimdall.Domain.Entities.Agent", "Agent")
@@ -35,7 +35,7 @@ public class AuditLogService : IAuditLogService
.Select(al => new AuditLogResponse(
al.Id,
al.UserId,
al.UserId != null ? _db.Users.Where(u => u.Id == al.UserId).Select(u => u.Email).FirstOrDefault() : null,
al.User != null ? al.User.Email : null,
al.Action,
al.ResourceType,
al.ResourceId,