From cd70f54266d708867a1eb35870bc755bc5b2df32 Mon Sep 17 00:00:00 2001 From: ivar Date: Wed, 3 Dec 2025 21:49:20 +0100 Subject: Refactor db --- api/WhatApi/Database/Tables/AuditTrail.cs | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 api/WhatApi/Database/Tables/AuditTrail.cs (limited to 'api/WhatApi/Database/Tables/AuditTrail.cs') diff --git a/api/WhatApi/Database/Tables/AuditTrail.cs b/api/WhatApi/Database/Tables/AuditTrail.cs new file mode 100644 index 0000000..4ded46c --- /dev/null +++ b/api/WhatApi/Database/Tables/AuditTrail.cs @@ -0,0 +1,39 @@ +namespace WhatApi.Database.Tables; + +public class AuditTrail +{ + public Guid Id { get; init; } + public Guid? UserId { get; init; } + public required string EntityName { get; init; } + public string? PrimaryKey { get; set; } + public TrailType TrailType { get; set; } + public DateTimeOffset DateUtc { get; init; } + + public Dictionary OldValues { get; init; } = []; + public Dictionary NewValues { get; init; } = []; + public List ChangedColumns { get; init; } = []; +} + +public class AuditTrailConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("audit_trails"); + builder.HasIndex(e => e.EntityName); + builder.Property(e => e.EntityName).HasMaxLength(100).IsRequired(); + builder.Property(e => e.PrimaryKey).HasMaxLength(100); + builder.Property(e => e.DateUtc).IsRequired(); + builder.Property(e => e.TrailType).HasConversion(); + builder.Property(e => e.OldValues).HasColumnType("jsonb"); + builder.Property(e => e.NewValues).HasColumnType("jsonb"); + builder.Property(e => e.ChangedColumns).HasColumnType("jsonb"); + } +} + +public enum TrailType : byte +{ + None = 0, + Create = 1, + Update = 2, + Delete = 3 +} \ No newline at end of file -- cgit v1.3