| | | 1 | | using ArturRios.Heimdall.Domain.Entities; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Data.EntityMaps; |
| | | 6 | | |
| | | 7 | | internal static class AuditLogDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<AuditLog> auditLog) |
| | | 10 | | { |
| | 3 | 11 | | auditLog.ToTable("audit_log"); |
| | 3 | 12 | | auditLog.HasKey(x => x.Id); |
| | | 13 | | |
| | 3 | 14 | | auditLog.Property(x => x.PublicId).IsRequired(); |
| | 3 | 15 | | auditLog.HasIndex(x => x.PublicId).IsUnique(); |
| | 3 | 16 | | auditLog.HasIndex(x => x.CreatedAt); |
| | 3 | 17 | | auditLog.HasIndex(x => x.ActorPersonId); |
| | | 18 | | |
| | | 19 | | // UC-48 filters by target ("what happened to this entity?"); without this that is a scan of |
| | | 20 | | // a table that only grows. |
| | 3 | 21 | | auditLog.HasIndex(x => x.TargetId); |
| | | 22 | | |
| | 3 | 23 | | auditLog.Property(x => x.Action).IsRequired(); |
| | 3 | 24 | | auditLog.Property(x => x.CreatedAt).HasDefaultValueSql("now()"); |
| | | 25 | | |
| | | 26 | | // ActorPersonId/ActorRole/TargetId are plain nullable columns — no FK, no required navigation. |
| | 3 | 27 | | } |
| | | 28 | | } |