Skip to content

Add AuditLog entity, AuditAction enum, DbSet and AddAuditLog migration #2

@duchacekjan

Description

@duchacekjan

Description

Add the AuditLog entity and AuditAction enum to the persistence layer, register DbSet on AppDbContext, and create the EF Core migration AddAuditLog.

New file src/UCK26.Api/Persistence/AuditLog.cs:

public enum AuditAction { Create, Update, Delete }

public class AuditLog
{
    public int Id { get; set; }
    public string EntityType { get; set; } = "WorkEntry";
    public int EntityId { get; set; }
    public AuditAction Action { get; set; }
    public string PerformedBy { get; set; } = "";
    public DateTime PerformedAt { get; set; }
    public string? ChangedFields { get; set; }   // JSON: [{field, oldValue, newValue}]
    public string? EntryDate { get; set; }        // denormalized WorkEntry.Date
    public string? EntryType { get; set; }        // denormalized WorkEntry.Type (work/holiday/doctor)
    public int? WorksheetId { get; set; }         // denormalized WorkEntry.WorksheetId
}

public record AuditChangedField(string Field, string? OldValue, string? NewValue);

Add to src/UCK26.Api/Persistence/AppDbContext.cs:

public DbSet<AuditLog> AuditLogs => Set<AuditLog>();

No FK from AuditLog to WorkEntry — intentional so logs survive entry deletion.

Run migration:

cd src/UCK26.Api
dotnet ef migrations add AddAuditLog

Reference: documents/work-entry-audit-log/work-entry-audit-log.handover.md

Acceptance Criteria

  • Test coverage — run dotnet ef database update and confirm it applies without errors. Verify via EF model snapshot that AuditLogs table has all expected columns (EntryType included) and no FK to WorkEntry. No separate test file needed — downstream integration tests in TestWebApplicationFactory confirm the table is queryable; those must pass.
  • Update README.md — in the Database section, add AuditLog to the entities list and note there is no FK to WorkEntry by design.
  • Update CLAUDE.md — in the Solution Structure map under Persistence/, add AuditLog.cs with a short comment.
  • AuditLog entity and AuditAction enum exist in src/UCK26.Api/Persistence/AuditLog.cs
  • EntryType field present on AuditLog (nullable string, stores "work" / "holiday" / "doctor")
  • AppDbContext.AuditLogs DbSet registered
  • Migration AddAuditLog created and applies cleanly (dotnet ef database update)
  • No FK constraint from AuditLog to WorkEntry

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions