feat(db): add SourceNode column to Notifications
This commit is contained in:
@@ -47,10 +47,14 @@ public class NotificationOutboxConfiguration : IEntityTypeConfiguration<Notifica
|
||||
|
||||
builder.Property(n => n.SourceScript).HasMaxLength(200);
|
||||
|
||||
// SourceNode (Audit Log #23, SourceNode-stamping): mapped in a follow-on migration
|
||||
// (AddNotificationSourceNode). Ignored here for now so the AddAuditLogSourceNode
|
||||
// migration only touches AuditLog. Removed in the AddNotificationSourceNode commit.
|
||||
builder.Ignore(n => n.SourceNode);
|
||||
// SourceNode (Audit Log #23, SourceNode-stamping): node-local identifier of the
|
||||
// cluster member that produced the notification (e.g. "node-a", "central-a").
|
||||
// NULL is valid for rows that pre-date this feature. ASCII — varchar(64).
|
||||
// No index — KPIs are per-site on this table, not per-node; SourceNode is only
|
||||
// echoed onto NotifyDeliver audit rows (#23) for cross-row correlation.
|
||||
builder.Property(n => n.SourceNode)
|
||||
.HasColumnType("varchar(64)")
|
||||
.HasMaxLength(64);
|
||||
|
||||
// OriginExecutionId (Audit Log #23): nullable uniqueidentifier carried from the
|
||||
// site so the dispatcher can echo it onto NotifyDeliver audit rows. No index —
|
||||
|
||||
1650
src/ScadaLink.ConfigurationDatabase/Migrations/20260523201950_AddNotificationSourceNode.Designer.cs
generated
Normal file
1650
src/ScadaLink.ConfigurationDatabase/Migrations/20260523201950_AddNotificationSourceNode.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ScadaLink.ConfigurationDatabase.Migrations
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the <c>SourceNode</c> column to the central <c>Notifications</c> table (#21,
|
||||
/// SourceNode-stamping). <c>SourceNode</c> identifies the cluster node that produced the
|
||||
/// notification (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.
|
||||
///
|
||||
/// 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>. Unlike
|
||||
/// <c>AuditLog</c>, the <c>Notifications</c> table is NOT partitioned, so a plain
|
||||
/// <c>ADD</c> is fine. No index — Notification Outbox KPIs are per-site, not per-node,
|
||||
/// on this table; <c>SourceNode</c> is only echoed onto <c>NotifyDeliver</c> audit rows
|
||||
/// (#23) for cross-row correlation. Historical rows stay <c>NULL</c>.
|
||||
/// </summary>
|
||||
public partial class AddNotificationSourceNode : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "SourceNode",
|
||||
table: "Notifications",
|
||||
type: "varchar(64)",
|
||||
maxLength: 64,
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "SourceNode",
|
||||
table: "Notifications");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -820,6 +820,10 @@ namespace ScadaLink.ConfigurationDatabase.Migrations
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("SourceNode")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("varchar(64)");
|
||||
|
||||
b.Property<string>("SourceScript")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
using Xunit;
|
||||
|
||||
namespace ScadaLink.ConfigurationDatabase.Tests.Migrations;
|
||||
|
||||
/// <summary>
|
||||
/// SourceNode-stamping (#23) integration tests for the
|
||||
/// <c>AddNotificationSourceNode</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>Notifications</c> table carries the new
|
||||
/// <c>SourceNode varchar(64) NULL</c> column. No index — Notification Outbox KPIs
|
||||
/// are per-site, not per-node, so the column is never a query predicate on this
|
||||
/// table; it's only echoed onto NotifyDeliver audit rows (#23) for cross-row
|
||||
/// correlation.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <c>Notifications</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 AddNotificationSourceNodeMigrationTests : IClassFixture<MsSqlMigrationFixture>
|
||||
{
|
||||
private readonly MsSqlMigrationFixture _fixture;
|
||||
|
||||
public AddNotificationSourceNodeMigrationTests(MsSqlMigrationFixture fixture)
|
||||
{
|
||||
_fixture = fixture;
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public async Task AppliesMigration_AddsSourceNodeColumn_ToNotifications()
|
||||
{
|
||||
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||
|
||||
var present = await ScalarAsync<int>(
|
||||
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||
"WHERE TABLE_NAME = 'Notifications' 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 = 'Notifications' AND COLUMN_NAME = 'SourceNode';");
|
||||
Assert.Equal("varchar", dataType);
|
||||
|
||||
var maxLength = await ScalarAsync<int>(
|
||||
"SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||
"WHERE TABLE_NAME = 'Notifications' AND COLUMN_NAME = 'SourceNode';");
|
||||
Assert.Equal(64, maxLength);
|
||||
|
||||
var isNullable = await ScalarAsync<string?>(
|
||||
"SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS " +
|
||||
"WHERE TABLE_NAME = 'Notifications' 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