feat(db): add SourceNode column to SiteCalls
This commit is contained in:
@@ -59,10 +59,14 @@ public class SiteCallEntityTypeConfiguration : IEntityTypeConfiguration<SiteCall
|
|||||||
builder.Property(s => s.LastError)
|
builder.Property(s => s.LastError)
|
||||||
.HasMaxLength(1024);
|
.HasMaxLength(1024);
|
||||||
|
|
||||||
// SourceNode (Audit Log #23, SourceNode-stamping): mapped in a follow-on migration
|
// SourceNode (Audit Log #23, SourceNode-stamping): node-local identifier of the
|
||||||
// (AddSiteCallSourceNode). Ignored here for now so the AddAuditLogSourceNode
|
// cluster member that produced the call (e.g. "node-a", "central-a"). NULL is
|
||||||
// migration only touches AuditLog. Removed in the AddSiteCallSourceNode commit.
|
// valid for rows that pre-date this feature and for reconciled rows from a
|
||||||
builder.Ignore(s => s.SourceNode);
|
// retired node. ASCII — varchar(64). No index — Site Call Audit KPIs are
|
||||||
|
// per-site, not per-node, on this table.
|
||||||
|
builder.Property(s => s.SourceNode)
|
||||||
|
.HasColumnType("varchar(64)")
|
||||||
|
.HasMaxLength(64);
|
||||||
|
|
||||||
// Indexes — names locked for reconciliation/migration discoverability.
|
// Indexes — names locked for reconciliation/migration discoverability.
|
||||||
// Source_Created backs "calls from this site" (Central UI Site Calls page,
|
// Source_Created backs "calls from this site" (Central UI Site Calls page,
|
||||||
|
|||||||
1654
src/ScadaLink.ConfigurationDatabase/Migrations/20260523202131_AddSiteCallSourceNode.Designer.cs
generated
Normal file
1654
src/ScadaLink.ConfigurationDatabase/Migrations/20260523202131_AddSiteCallSourceNode.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ScadaLink.ConfigurationDatabase.Migrations
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the <c>SourceNode</c> column to the central <c>SiteCalls</c> table (#22,
|
||||||
|
/// SourceNode-stamping). <c>SourceNode</c> identifies the cluster node that produced the
|
||||||
|
/// row (e.g. <c>node-a</c>, <c>central-a</c>) — ASCII-only, so <c>varchar(64)</c> not
|
||||||
|
/// <c>nvarchar</c>. <c>NULL</c> is valid for rows that pre-date this feature and for
|
||||||
|
/// reconciled rows from a retired node.
|
||||||
|
///
|
||||||
|
/// The change is purely additive: <c>SourceNode varchar(64) NULL</c> is added with no
|
||||||
|
/// default, so the operation is a metadata-only <c>ALTER TABLE … ADD</c>. The
|
||||||
|
/// <c>SiteCalls</c> table is NOT partitioned (operational state, not audit), so a plain
|
||||||
|
/// <c>ADD</c> is fine. No index — Site Call Audit KPIs are per-site, not per-node, on
|
||||||
|
/// this table; <c>SourceNode</c> is operational metadata, never a query predicate here.
|
||||||
|
/// Historical rows stay <c>NULL</c>.
|
||||||
|
/// </summary>
|
||||||
|
public partial class AddSiteCallSourceNode : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "SourceNode",
|
||||||
|
table: "SiteCalls",
|
||||||
|
type: "varchar(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "SourceNode",
|
||||||
|
table: "SiteCalls");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -262,6 +262,10 @@ namespace ScadaLink.ConfigurationDatabase.Migrations
|
|||||||
b.Property<int>("RetryCount")
|
b.Property<int>("RetryCount")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("SourceNode")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("varchar(64)");
|
||||||
|
|
||||||
b.Property<string>("SourceSite")
|
b.Property<string>("SourceSite")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ WHERE TrackedOperationId = {idText}
|
|||||||
// NotificationOutboxRepository.QueryAsync applies NotificationOutboxFilter.StuckCutoff.
|
// NotificationOutboxRepository.QueryAsync applies NotificationOutboxFilter.StuckCutoff.
|
||||||
FormattableString sql = $@"
|
FormattableString sql = $@"
|
||||||
SELECT TOP ({paging.PageSize})
|
SELECT TOP ({paging.PageSize})
|
||||||
TrackedOperationId, Channel, Target, SourceSite, Status, RetryCount,
|
TrackedOperationId, Channel, Target, SourceSite, SourceNode, Status, RetryCount,
|
||||||
LastError, HttpStatus, CreatedAtUtc, UpdatedAtUtc, TerminalAtUtc, IngestedAtUtc
|
LastError, HttpStatus, CreatedAtUtc, UpdatedAtUtc, TerminalAtUtc, IngestedAtUtc
|
||||||
FROM dbo.SiteCalls
|
FROM dbo.SiteCalls
|
||||||
WHERE ({filter.Channel} IS NULL OR Channel = {filter.Channel})
|
WHERE ({filter.Channel} IS NULL OR Channel = {filter.Channel})
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace ScadaLink.ConfigurationDatabase.Tests.Migrations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SourceNode-stamping (#23) integration tests for the
|
||||||
|
/// <c>AddSiteCallSourceNode</c> migration: applies the EF migrations to a
|
||||||
|
/// freshly-created MSSQL test database on the running infra/mssql container and
|
||||||
|
/// asserts that the central <c>SiteCalls</c> table carries the new
|
||||||
|
/// <c>SourceNode varchar(64) NULL</c> column. No index — Site Call Audit KPIs
|
||||||
|
/// are per-site, not per-node, on this table; <c>SourceNode</c> is operational
|
||||||
|
/// metadata, not a query predicate here.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <c>SiteCalls</c> is non-partitioned (operational state, not audit), so this
|
||||||
|
/// is a plain metadata-only <c>ALTER TABLE … ADD</c> with no index.
|
||||||
|
/// </remarks>
|
||||||
|
public class AddSiteCallSourceNodeMigrationTests : IClassFixture<MsSqlMigrationFixture>
|
||||||
|
{
|
||||||
|
private readonly MsSqlMigrationFixture _fixture;
|
||||||
|
|
||||||
|
public AddSiteCallSourceNodeMigrationTests(MsSqlMigrationFixture fixture)
|
||||||
|
{
|
||||||
|
_fixture = fixture;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public async Task AppliesMigration_AddsSourceNodeColumn_ToSiteCalls()
|
||||||
|
{
|
||||||
|
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||||
|
|
||||||
|
var present = await ScalarAsync<int>(
|
||||||
|
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||||
|
"WHERE TABLE_NAME = 'SiteCalls' AND COLUMN_NAME = 'SourceNode' " +
|
||||||
|
"AND TABLE_SCHEMA = 'dbo';");
|
||||||
|
Assert.Equal(1, present);
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public async Task SourceNodeColumn_IsNullableVarchar64()
|
||||||
|
{
|
||||||
|
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||||
|
|
||||||
|
// varchar(64), not nvarchar — SourceNode is ASCII (`node-a`, `central-a` etc.).
|
||||||
|
var dataType = await ScalarAsync<string?>(
|
||||||
|
"SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||||
|
"WHERE TABLE_NAME = 'SiteCalls' AND COLUMN_NAME = 'SourceNode';");
|
||||||
|
Assert.Equal("varchar", dataType);
|
||||||
|
|
||||||
|
var maxLength = await ScalarAsync<int>(
|
||||||
|
"SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||||
|
"WHERE TABLE_NAME = 'SiteCalls' AND COLUMN_NAME = 'SourceNode';");
|
||||||
|
Assert.Equal(64, maxLength);
|
||||||
|
|
||||||
|
var isNullable = await ScalarAsync<string?>(
|
||||||
|
"SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||||
|
"WHERE TABLE_NAME = 'SiteCalls' AND COLUMN_NAME = 'SourceNode';");
|
||||||
|
Assert.Equal("YES", isNullable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- helpers ------------------------------------------------------------
|
||||||
|
|
||||||
|
private async Task<T> ScalarAsync<T>(string sql)
|
||||||
|
{
|
||||||
|
await using var conn = _fixture.OpenConnection();
|
||||||
|
await using var cmd = conn.CreateCommand();
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
var result = await cmd.ExecuteScalarAsync();
|
||||||
|
if (result is null || result is DBNull)
|
||||||
|
{
|
||||||
|
return default!;
|
||||||
|
}
|
||||||
|
return (T)Convert.ChangeType(result, typeof(T) == typeof(string) ? typeof(string) : Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T))!;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user