feat(configdb): map SiteCall to SiteCalls table (#22, #23 M3)

Bundle B1 of Audit Log #23 M3: introduces the SiteCall entity + EF mapping
for the central SiteCalls operational-state table. One row per
TrackedOperationId, mirrored from sites via best-effort telemetry then
periodic reconciliation; eventually-consistent mirror, not a dispatcher.

- src/ScadaLink.Commons/Entities/Audit/SiteCall.cs: append-once record
  with required TrackedOperationId/Channel/Target/SourceSite/Status,
  monotonic status update at the repo layer.
- src/ScadaLink.ConfigurationDatabase/Configurations/SiteCallEntityTypeConfiguration.cs:
  table SiteCalls, PK on TrackedOperationId (stored as varchar(36) via
  value conversion through the canonical 'D'-format GUID string —
  matches the wire shape used by gRPC + SQLite columns), two named
  indexes (IX_SiteCalls_Source_Created, IX_SiteCalls_Status_Updated).
- ScadaLinkDbContext: DbSet<SiteCall> SiteCalls in the existing Audit
  section, after AuditLogs.
- Tests in tests/ScadaLink.ConfigurationDatabase.Tests/Configurations/:
  table name, PK, value-conversion shape, index presence + ordering.
This commit is contained in:
Joseph Doherty
2026-05-20 14:04:17 -04:00
parent e416b21dad
commit 3162286ade
4 changed files with 245 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
using ScadaLink.Commons.Types;
namespace ScadaLink.Commons.Entities.Audit;
/// <summary>
/// Central operational state row for a cached call (Site Call Audit #22, Audit Log #23 M3).
/// One row per <see cref="TrackedOperationId"/> in the <c>SiteCalls</c> table — append-once
/// then monotonic status update. Status transitions are forward-only
/// (<c>Submitted → Forwarded → Attempted → Delivered|Failed|Parked|Discarded</c>); an
/// out-of-order or duplicate upsert is a silent no-op so duplicate gRPC packets and
/// reconciliation pulls can both feed the same writer without rolling state back.
/// </summary>
/// <remarks>
/// Sites remain the source of truth — this row is the eventually-consistent mirror the
/// Central UI's Site Calls page reads. Unlike the partitioned <c>AuditLog</c> table this
/// entity backs operational (mutable) state on a standard non-partitioned table on
/// <c>[PRIMARY]</c>; no DB-role restriction applies.
/// </remarks>
public sealed record SiteCall
{
/// <summary>Strong-typed idempotency key shared with every audit row for the operation.</summary>
public required TrackedOperationId TrackedOperationId { get; init; }
/// <summary>Trust-boundary channel — <c>"ApiOutbound"</c> or <c>"DbOutbound"</c>.</summary>
public required string Channel { get; init; }
/// <summary>Human-readable target (e.g. <c>"ERP.GetOrder"</c>).</summary>
public required string Target { get; init; }
/// <summary>Site id that submitted the cached call.</summary>
public required string SourceSite { get; init; }
/// <summary>
/// Lifecycle status — string form of
/// <see cref="ScadaLink.Commons.Types.Enums.AuditStatus"/>. Monotonic: later rank
/// wins, earlier rank is a no-op.
/// </summary>
public required string Status { get; init; }
/// <summary>Number of dispatch attempts so far; 0 prior to first attempt.</summary>
public required int RetryCount { get; init; }
/// <summary>Most recent error message; null when no failures have occurred.</summary>
public string? LastError { get; init; }
/// <summary>Most recent HTTP status code (API calls only); null otherwise.</summary>
public int? HttpStatus { get; init; }
/// <summary>UTC timestamp the cached call was first submitted at the site.</summary>
public required DateTime CreatedAtUtc { get; init; }
/// <summary>UTC timestamp of the latest status mutation at the site.</summary>
public required DateTime UpdatedAtUtc { get; init; }
/// <summary>UTC timestamp the row reached a terminal status; null while still active.</summary>
public DateTime? TerminalAtUtc { get; init; }
/// <summary>UTC timestamp central ingested (or last refreshed) this row.</summary>
public required DateTime IngestedAtUtc { get; init; }
}