feat(kpi): K2 — KpiSample EF mapping + KpiHistoryRepository + AddKpiSampleTable migration

This commit is contained in:
Joseph Doherty
2026-06-17 19:44:51 -04:00
parent 460777bffa
commit cabc557629
8 changed files with 2151 additions and 0 deletions
@@ -0,0 +1,50 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
{
/// <inheritdoc />
public partial class AddKpiSampleTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "KpiSample",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Source = table.Column<string>(type: "varchar(64)", unicode: false, maxLength: 64, nullable: false),
Metric = table.Column<string>(type: "varchar(64)", unicode: false, maxLength: 64, nullable: false),
Scope = table.Column<string>(type: "varchar(16)", unicode: false, maxLength: 16, nullable: false),
ScopeKey = table.Column<string>(type: "varchar(64)", unicode: false, maxLength: 64, nullable: true),
Value = table.Column<double>(type: "float", nullable: false),
CapturedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_KpiSample", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_KpiSample_Captured",
table: "KpiSample",
column: "CapturedAtUtc");
migrationBuilder.CreateIndex(
name: "IX_KpiSample_Series",
table: "KpiSample",
columns: new[] { "Source", "Metric", "Scope", "ScopeKey", "CapturedAtUtc" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "KpiSample");
}
}
}
@@ -650,6 +650,54 @@ namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
b.ToTable("InstanceNativeAlarmSourceOverrides");
});
modelBuilder.Entity("ZB.MOM.WW.ScadaBridge.Commons.Entities.Kpi.KpiSample", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<DateTime>("CapturedAtUtc")
.HasColumnType("datetime2");
b.Property<string>("Metric")
.IsRequired()
.HasMaxLength(64)
.IsUnicode(false)
.HasColumnType("varchar(64)");
b.Property<string>("Scope")
.IsRequired()
.HasMaxLength(16)
.IsUnicode(false)
.HasColumnType("varchar(16)");
b.Property<string>("ScopeKey")
.HasMaxLength(64)
.IsUnicode(false)
.HasColumnType("varchar(64)");
b.Property<string>("Source")
.IsRequired()
.HasMaxLength(64)
.IsUnicode(false)
.HasColumnType("varchar(64)");
b.Property<double>("Value")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("CapturedAtUtc")
.HasDatabaseName("IX_KpiSample_Captured");
b.HasIndex("Source", "Metric", "Scope", "ScopeKey", "CapturedAtUtc")
.HasDatabaseName("IX_KpiSample_Series");
b.ToTable("KpiSample", (string)null);
});
modelBuilder.Entity("ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications.Notification", b =>
{
b.Property<string>("NotificationId")