feat(sites): record the artifact revision last deployed to a site
Site.ArtifactRevisionHash / ArtifactsDeployedAt (nullable, migration AddSiteArtifactRevision) so the Sites page can tell whether a site's system-wide artifacts are current. Not transported. Adds the GetDeployedRevisionHashesAsync projection for the fleet-wide staleness batch. Claude-Session: https://claude.ai/code/session_01Y5ef34iUUMjmwnMpL9xgmB
This commit is contained in:
@@ -18,6 +18,18 @@ public class Site
|
||||
public string? GrpcNodeAAddress { get; set; }
|
||||
/// <summary>gRPC endpoint for site node B used by the central SiteStreamGrpcClient.</summary>
|
||||
public string? GrpcNodeBAddress { get; set; }
|
||||
/// <summary>
|
||||
/// Revision hash (<c>ArtifactRevisionHashService</c>) of the per-site artifact set last
|
||||
/// deployed to this site successfully; null = artifacts never deployed. Environment-specific
|
||||
/// deploy state — deliberately NOT carried by Transport bundles (like <c>Instance.State</c>).
|
||||
/// </summary>
|
||||
public string? ArtifactRevisionHash { get; set; }
|
||||
/// <summary>
|
||||
/// UTC instant at which the artifact set identified by <see cref="ArtifactRevisionHash"/> was
|
||||
/// last deployed to this site successfully; null = artifacts never deployed. Environment-specific
|
||||
/// deploy state — deliberately NOT carried by Transport bundles (like <c>Instance.State</c>).
|
||||
/// </summary>
|
||||
public DateTimeOffset? ArtifactsDeployedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new site with the required name and identifier.
|
||||
|
||||
+8
@@ -204,6 +204,14 @@ public interface IDeploymentManagerRepository
|
||||
/// <returns>The deployed config snapshot, or null if not found.</returns>
|
||||
Task<DeployedConfigSnapshot?> GetDeployedSnapshotByInstanceIdAsync(int instanceId, CancellationToken cancellationToken = default);
|
||||
/// <summary>
|
||||
/// InstanceId → RevisionHash for every <c>DeployedConfigSnapshot</c>. A projection read — never
|
||||
/// materialises <c>ConfigurationJson</c>, so it is safe to call for the whole fleet (the
|
||||
/// pending-updates aggregate does, once per cache TTL).
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
|
||||
/// <returns>A dictionary keyed by instance ID; instances with no snapshot are absent.</returns>
|
||||
Task<IReadOnlyDictionary<int, string>> GetDeployedRevisionHashesAsync(CancellationToken cancellationToken = default);
|
||||
/// <summary>
|
||||
/// Adds a new deployed config snapshot.
|
||||
/// </summary>
|
||||
/// <param name="snapshot">The deployed config snapshot to add.</param>
|
||||
|
||||
@@ -27,6 +27,7 @@ public class SiteConfiguration : IEntityTypeConfiguration<Site>
|
||||
builder.Property(s => s.NodeBAddress).HasMaxLength(500);
|
||||
builder.Property(s => s.GrpcNodeAAddress).HasMaxLength(500);
|
||||
builder.Property(s => s.GrpcNodeBAddress).HasMaxLength(500);
|
||||
builder.Property(s => s.ArtifactRevisionHash).HasMaxLength(100);
|
||||
|
||||
builder.HasIndex(s => s.Name).IsUnique();
|
||||
builder.HasIndex(s => s.SiteIdentifier).IsUnique();
|
||||
|
||||
+2149
File diff suppressed because it is too large
Load Diff
+40
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddSiteArtifactRevision : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "ArtifactRevisionHash",
|
||||
table: "Sites",
|
||||
type: "nvarchar(100)",
|
||||
maxLength: 100,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||
name: "ArtifactsDeployedAt",
|
||||
table: "Sites",
|
||||
type: "datetimeoffset",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ArtifactRevisionHash",
|
||||
table: "Sites");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ArtifactsDeployedAt",
|
||||
table: "Sites");
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -1379,6 +1379,13 @@ namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ArtifactRevisionHash")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTimeOffset?>("ArtifactsDeployedAt")
|
||||
.HasColumnType("datetimeoffset");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("nvarchar(2000)");
|
||||
|
||||
+11
@@ -294,6 +294,17 @@ public class DeploymentManagerRepository : IDeploymentManagerRepository
|
||||
.FirstOrDefaultAsync(s => s.InstanceId == instanceId, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyDictionary<int, string>> GetDeployedRevisionHashesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Projection only: ConfigurationJson is never materialised, so this stays cheap enough to
|
||||
// read for the whole fleet in one round trip.
|
||||
return await _dbContext.Set<DeployedConfigSnapshot>()
|
||||
.AsNoTracking()
|
||||
.Select(s => new { s.InstanceId, s.RevisionHash })
|
||||
.ToDictionaryAsync(s => s.InstanceId, s => s.RevisionHash, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task AddDeployedSnapshotAsync(DeployedConfigSnapshot snapshot, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user