using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace HHWMS.Web.Migrations { public partial class device_data_tables : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "DeviceAlarmRecord", columns: table => new { ID = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), DeviceId = table.Column(type: "varchar(100)", maxLength: 100, nullable: false, comment: "设备唯一标识") .Annotation("MySql:CharSet", "utf8mb4"), AlarmCode = table.Column(type: "varchar(100)", maxLength: 100, nullable: true, comment: "告警代码") .Annotation("MySql:CharSet", "utf8mb4"), AlarmMessage = table.Column(type: "varchar(500)", maxLength: 500, nullable: true, comment: "告警内容") .Annotation("MySql:CharSet", "utf8mb4"), StartTime = table.Column(type: "datetime(6)", nullable: false, comment: "告警开始时间"), EndTime = table.Column(type: "datetime(6)", nullable: true, comment: "告警恢复时间"), IsActive = table.Column(type: "tinyint(1)", nullable: false, comment: "是否仍在告警"), LastSeenTime = table.Column(type: "datetime(6)", nullable: true, comment: "最后出现时间"), RepeatCount = table.Column(type: "int", nullable: false, comment: "重复出现次数"), CreateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), CreateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4"), UpdateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), UpdateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_DeviceAlarmRecord", x => x.ID); }, comment: "设备告警记录") .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "DeviceCurrentState", columns: table => new { ID = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), DeviceId = table.Column(type: "varchar(100)", maxLength: 100, nullable: false, comment: "设备唯一标识") .Annotation("MySql:CharSet", "utf8mb4"), DeviceName = table.Column(type: "varchar(100)", maxLength: 100, nullable: true, comment: "设备显示名称") .Annotation("MySql:CharSet", "utf8mb4"), DeviceType = table.Column(type: "varchar(30)", maxLength: 30, nullable: true, comment: "设备类型") .Annotation("MySql:CharSet", "utf8mb4"), Status = table.Column(type: "varchar(30)", maxLength: 30, nullable: true, comment: "当前状态") .Annotation("MySql:CharSet", "utf8mb4"), LastPayloadTime = table.Column(type: "datetime(6)", nullable: true, comment: "最后设备数据时间"), LastUpdateTime = table.Column(type: "datetime(6)", nullable: true, comment: "最后状态更新时间"), AlarmSummary = table.Column(type: "varchar(500)", maxLength: 500, nullable: true, comment: "当前告警摘要") .Annotation("MySql:CharSet", "utf8mb4"), RealtimeJson = table.Column(type: "longtext", nullable: true, comment: "清洗后的实时数据") .Annotation("MySql:CharSet", "utf8mb4"), CreateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), CreateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4"), UpdateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), UpdateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_DeviceCurrentState", x => x.ID); }, comment: "设备当前状态") .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "DeviceMetricTrendPoint", columns: table => new { ID = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), DeviceId = table.Column(type: "varchar(100)", maxLength: 100, nullable: false, comment: "设备唯一标识") .Annotation("MySql:CharSet", "utf8mb4"), MetricName = table.Column(type: "varchar(60)", maxLength: 60, nullable: false, comment: "指标名称") .Annotation("MySql:CharSet", "utf8mb4"), BucketTime = table.Column(type: "datetime(6)", nullable: false, comment: "聚合时间桶"), AvgValue = table.Column(type: "decimal(18,4)", nullable: false, comment: "平均值"), MaxValue = table.Column(type: "decimal(18,4)", nullable: false, comment: "最大值"), MinValue = table.Column(type: "decimal(18,4)", nullable: false, comment: "最小值"), SampleCount = table.Column(type: "int", nullable: false, comment: "样本数"), CreateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), CreateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4"), UpdateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), UpdateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_DeviceMetricTrendPoint", x => x.ID); }, comment: "设备指标趋势聚合点") .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "DeviceProductionDaily", columns: table => new { ID = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), DeviceId = table.Column(type: "varchar(100)", maxLength: 100, nullable: false, comment: "设备唯一标识") .Annotation("MySql:CharSet", "utf8mb4"), ProductionDate = table.Column(type: "datetime(6)", nullable: false, comment: "生产日期"), StartCounter = table.Column(type: "int", nullable: false, comment: "当日开始累计值"), EndCounter = table.Column(type: "int", nullable: false, comment: "当日结束累计值"), ProduceCount = table.Column(type: "int", nullable: false, comment: "当日产量"), RuntimeMinutes = table.Column(type: "int", nullable: false, comment: "运行分钟数"), CuttimeMinutes = table.Column(type: "int", nullable: false, comment: "加工分钟数"), AlarmMinutes = table.Column(type: "int", nullable: false, comment: "报警分钟数"), OfflineMinutes = table.Column(type: "int", nullable: false, comment: "离线分钟数"), CreateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), CreateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4"), UpdateTime = table.Column(type: "datetime(6)", nullable: true, comment: ""), UpdateBy = table.Column(type: "varchar(50)", maxLength: 50, nullable: true, comment: "") .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_DeviceProductionDaily", x => x.ID); }, comment: "设备日产能汇总") .Annotation("MySql:CharSet", "utf8mb4"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "DeviceAlarmRecord"); migrationBuilder.DropTable( name: "DeviceCurrentState"); migrationBuilder.DropTable( name: "DeviceMetricTrendPoint"); migrationBuilder.DropTable( name: "DeviceProductionDaily"); } } }