2026-07-16 20:53:56 +00:00
|
|
|
using Heimdall.Domain.Entities;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Infrastructure.Data.Configurations;
|
|
|
|
|
|
|
|
|
|
public class AuditLogConfiguration : IEntityTypeConfiguration<AuditLog>
|
|
|
|
|
{
|
|
|
|
|
public void Configure(EntityTypeBuilder<AuditLog> builder)
|
|
|
|
|
{
|
|
|
|
|
builder.ToTable("audit_logs");
|
|
|
|
|
|
|
|
|
|
builder.HasKey(al => al.Id);
|
|
|
|
|
|
|
|
|
|
builder.Property(al => al.Action)
|
|
|
|
|
.HasMaxLength(100)
|
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
builder.Property(al => al.ResourceType)
|
|
|
|
|
.HasMaxLength(100)
|
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
builder.Property(al => al.ResourceId)
|
|
|
|
|
.HasMaxLength(100);
|
|
|
|
|
|
|
|
|
|
builder.Property(al => al.IpAddress)
|
|
|
|
|
.HasMaxLength(45);
|
|
|
|
|
|
|
|
|
|
builder.Property(al => al.Timestamp)
|
|
|
|
|
.HasDefaultValueSql("NOW()");
|
|
|
|
|
|
2026-07-17 19:24:07 +00:00
|
|
|
// Relationships
|
|
|
|
|
builder.HasOne(al => al.User)
|
|
|
|
|
.WithMany()
|
|
|
|
|
.HasForeignKey(al => al.UserId)
|
|
|
|
|
.OnDelete(DeleteBehavior.SetNull);
|
|
|
|
|
|
2026-07-16 20:53:56 +00:00
|
|
|
// Indexes
|
|
|
|
|
builder.HasIndex(al => al.Timestamp)
|
|
|
|
|
.IsDescending();
|
|
|
|
|
|
|
|
|
|
builder.HasIndex(al => new { al.ResourceType, al.ResourceId, al.Timestamp })
|
|
|
|
|
.IsDescending(false, false, true);
|
|
|
|
|
|
|
|
|
|
builder.HasIndex(al => al.UserId);
|
|
|
|
|
}
|
|
|
|
|
}
|