feat(commons): add IAuditLogRepository + AuditLogQueryFilter + AuditLogPaging (#23)

Append-only data-access surface for the central AuditLog table — three
methods: InsertIfNotExistsAsync (first-write-wins on EventId), QueryAsync
(filter + keyset paging on (OccurredAtUtc desc, EventId desc)), and
SwitchOutPartitionAsync (M1 honest contract — throws NotSupported until
M6 lands the non-aligned-index drop/rebuild dance for the partition
switch). No Update, no row-delete; bulk purge is partition-only.

Bundle D of the Audit Log #23 M1 Foundation plan.
This commit is contained in:
Joseph Doherty
2026-05-20 11:04:59 -04:00
parent ce9d6301e3
commit db32a149d3
3 changed files with 90 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
namespace ScadaLink.Commons.Types.Audit;
/// <summary>
/// Keyset paging cursor for <see cref="ScadaLink.Commons.Interfaces.Repositories.IAuditLogRepository.QueryAsync"/>.
/// The repository orders by <c>(OccurredAtUtc DESC, EventId DESC)</c>; callers pass
/// the last row of the previous page back as <see cref="AfterOccurredAtUtc"/> +
/// <see cref="AfterEventId"/> to fetch the next page. Both must be non-null together,
/// or both null (first page).
/// </summary>
public sealed record AuditLogPaging(
int PageSize,
DateTime? AfterOccurredAtUtc = null,
Guid? AfterEventId = null);

View File

@@ -0,0 +1,21 @@
using ScadaLink.Commons.Types.Enums;
namespace ScadaLink.Commons.Types.Audit;
/// <summary>
/// Filter predicate for <see cref="ScadaLink.Commons.Interfaces.Repositories.IAuditLogRepository.QueryAsync"/>.
/// Any field left <c>null</c> means "do not constrain on that column". Time bounds
/// are half-open in the spec sense — <see cref="FromUtc"/> is inclusive and
/// <see cref="ToUtc"/> is inclusive of the upper bound; the repository SQL uses
/// <c>&gt;=</c> / <c>&lt;=</c> respectively. All filter fields are AND-combined.
/// </summary>
public sealed record AuditLogQueryFilter(
AuditChannel? Channel = null,
AuditKind? Kind = null,
AuditStatus? Status = null,
string? SourceSiteId = null,
string? Target = null,
string? Actor = null,
Guid? CorrelationId = null,
DateTime? FromUtc = null,
DateTime? ToUtc = null);