serverRoom/backend-csharp/AmtScanner.Api/Migrations/20260121062236_AddOsDeviceAndSystemUuid.cs
lvfengfree eebbacafde feat: 实现OS设备扫描和UUID绑定功能
- 添加OsDevice模型和OsDevicesController
- 实现WindowsScannerService用于网络扫描和WMI查询
- 添加AMT设备UUID查询功能(从CIM_ComputerSystemPackage获取PlatformGUID)
- 实现PlatformGUID到标准UUID格式的转换(字节序转换)
- 修复HardwareInfoRepository保存UUID的问题
- 前端添加OS设备管理页面和UUID获取/刷新按钮
- 添加数据库迁移脚本
2026-01-21 16:16:48 +08:00

103 lines
4.5 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AmtScanner.Api.Migrations
{
/// <inheritdoc />
public partial class AddOsDeviceAndSystemUuid : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "SystemUuid",
table: "AmtDevices",
type: "varchar(50)",
maxLength: 50,
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "OsDevices",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
IpAddress = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
SystemUuid = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Hostname = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
OsType = table.Column<int>(type: "int", nullable: false),
OsVersion = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Architecture = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LoggedInUser = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LastBootTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
MacAddress = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
IsOnline = table.Column<bool>(type: "tinyint(1)", nullable: false),
LastOnlineAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
DiscoveredAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
LastUpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
Description = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
AmtDeviceId = table.Column<long>(type: "bigint", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OsDevices", x => x.Id);
table.ForeignKey(
name: "FK_OsDevices_AmtDevices_AmtDeviceId",
column: x => x.AmtDeviceId,
principalTable: "AmtDevices",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_AmtDevices_SystemUuid",
table: "AmtDevices",
column: "SystemUuid");
migrationBuilder.CreateIndex(
name: "IX_OsDevices_AmtDeviceId",
table: "OsDevices",
column: "AmtDeviceId");
migrationBuilder.CreateIndex(
name: "IX_OsDevices_IpAddress",
table: "OsDevices",
column: "IpAddress",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_OsDevices_SystemUuid",
table: "OsDevices",
column: "SystemUuid");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OsDevices");
migrationBuilder.DropIndex(
name: "IX_AmtDevices_SystemUuid",
table: "AmtDevices");
migrationBuilder.DropColumn(
name: "SystemUuid",
table: "AmtDevices");
}
}
}