feat(kpihistory): add KpiRollupHourly table + EF config + migration (plan #22 T1)
New KpiRollupHourly entity is the hourly pre-aggregated series backbone folded from raw KpiSample rows, letting long-range (30d/90d) trend reads scan ~60x fewer rows. Same (Source, Metric, Scope, ScopeKey) series key as KpiSample plus HourStartUtc bucket, folded Value, and MinValue/MaxValue/SampleCount fidelity columns. UNIQUE IX_KpiRollupHourly_Series (upsert key + range-read cover, with the default [ScopeKey] IS NOT NULL filter suppressed so Global rows participate) and IX_KpiRollupHourly_Hour for purge. Non-partitioned, [PRIMARY], no DB-role restriction. Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
+2086
File diff suppressed because it is too large
Load Diff
+54
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddKpiRollupHourlyTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "KpiRollupHourly",
|
||||
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),
|
||||
HourStartUtc = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Value = table.Column<double>(type: "float", nullable: false),
|
||||
MinValue = table.Column<double>(type: "float", nullable: false),
|
||||
MaxValue = table.Column<double>(type: "float", nullable: false),
|
||||
SampleCount = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_KpiRollupHourly", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_KpiRollupHourly_Hour",
|
||||
table: "KpiRollupHourly",
|
||||
column: "HourStartUtc");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_KpiRollupHourly_Series",
|
||||
table: "KpiRollupHourly",
|
||||
columns: new[] { "Source", "Metric", "Scope", "ScopeKey", "HourStartUtc" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "KpiRollupHourly");
|
||||
}
|
||||
}
|
||||
}
|
||||
+58
@@ -709,6 +709,64 @@ namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
|
||||
b.ToTable("InstanceNativeAlarmSourceOverrides");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ZB.MOM.WW.ScadaBridge.Commons.Entities.Kpi.KpiRollupHourly", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTime>("HourStartUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<double>("MaxValue")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("Metric")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("varchar(64)");
|
||||
|
||||
b.Property<double>("MinValue")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<int>("SampleCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
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("HourStartUtc")
|
||||
.HasDatabaseName("IX_KpiRollupHourly_Hour");
|
||||
|
||||
b.HasIndex("Source", "Metric", "Scope", "ScopeKey", "HourStartUtc")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_KpiRollupHourly_Series");
|
||||
|
||||
b.ToTable("KpiRollupHourly", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ZB.MOM.WW.ScadaBridge.Commons.Entities.Kpi.KpiSample", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
|
||||
Reference in New Issue
Block a user