You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

531 lines
29 KiB

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace X1.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "CellularDevices",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "设备ID"),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false, comment: "设备名称"),
SerialNumber = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "序列号"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false, comment: "设备描述"),
AgentPort = table.Column<int>(type: "integer", nullable: false, comment: "Agent端口"),
IpAddress = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: false, comment: "IP地址"),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用"),
IsRunning = table.Column<bool>(type: "boolean", nullable: false, comment: "设备状态(启动/未启动)"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CellularDevices", x => x.Id);
table.UniqueConstraint("AK_CellularDevices_SerialNumber", x => x.SerialNumber);
},
comment: "蜂窝设备表");
migrationBuilder.CreateTable(
name: "CoreNetworkConfigs",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "配置ID"),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false, comment: "配置名称"),
ConfigContent = table.Column<string>(type: "text", nullable: false, comment: "配置内容(JSON格式)"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false, comment: "配置描述"),
IsDisabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否禁用"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CoreNetworkConfigs", x => x.Id);
},
comment: "核心网配置表");
migrationBuilder.CreateTable(
name: "IMS_Configurations",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "配置ID"),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false, comment: "配置名称"),
ConfigContent = table.Column<string>(type: "text", nullable: false, comment: "配置内容(JSON格式)"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false, comment: "配置描述"),
IsDisabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否禁用"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_IMS_Configurations", x => x.Id);
},
comment: "IMS配置表");
migrationBuilder.CreateTable(
name: "Permissions",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Description = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
Type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Permissions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "RAN_Configurations",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "配置ID"),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false, comment: "配置名称"),
ConfigContent = table.Column<string>(type: "text", nullable: false, comment: "配置内容(JSON格式)"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false, comment: "配置描述"),
IsDisabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否禁用"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RAN_Configurations", x => x.Id);
},
comment: "RAN配置表");
migrationBuilder.CreateTable(
name: "Roles",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "角色ID,主键"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, comment: "角色描述"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "角色名称"),
NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "标准化角色名称(大写)"),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true, comment: "并发控制戳")
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
},
comment: "角色表");
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "用户ID,主键"),
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true, comment: "用户状态(true: 启用, false: 禁用)"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否已删除"),
LastLoginTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "最后登录时间"),
RealName = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true, comment: "用户名"),
UserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "账号"),
NormalizedUserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "标准化账号(大写)"),
Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "电子邮箱"),
NormalizedEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "标准化电子邮箱(大写)"),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false, comment: "邮箱是否已验证"),
PasswordHash = table.Column<string>(type: "text", nullable: true, comment: "密码哈希值"),
SecurityStamp = table.Column<string>(type: "text", nullable: true, comment: "安全戳,用于并发控制"),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true, comment: "并发控制戳"),
PhoneNumber = table.Column<string>(type: "text", nullable: false, comment: "电话号码"),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false, comment: "电话号码是否已验证"),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用双因素认证"),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "账户锁定结束时间"),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用账户锁定"),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false, comment: "登录失败次数"),
CreatedTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
ModifiedTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "修改时间")
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
},
comment: "用户表");
migrationBuilder.CreateTable(
name: "ProtocolVersions",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "版本ID"),
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "版本名称"),
Version = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false, comment: "版本号"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, comment: "版本描述"),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用"),
ReleaseDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "发布日期"),
MinimumSupportedVersion = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "最低支持版本"),
SerialNumber = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "设备序列号"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ProtocolVersions", x => x.Id);
table.ForeignKey(
name: "FK_ProtocolVersions_CellularDevices_SerialNumber",
column: x => x.SerialNumber,
principalTable: "CellularDevices",
principalColumn: "SerialNumber",
onDelete: ReferentialAction.Cascade);
},
comment: "协议版本表");
migrationBuilder.CreateTable(
name: "NetworkStackConfigs",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "配置ID"),
StackId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "栈ID"),
RanId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true, comment: "RAN配置ID"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, comment: "描述"),
IsActive = table.Column<bool>(type: "boolean", nullable: false, comment: "是否激活"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_NetworkStackConfigs", x => x.Id);
table.UniqueConstraint("AK_NetworkStackConfigs_StackId", x => x.StackId);
table.ForeignKey(
name: "FK_NetworkStackConfigs_RAN_Configurations_RanId",
column: x => x.RanId,
principalTable: "RAN_Configurations",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
},
comment: "网络栈配置表");
migrationBuilder.CreateTable(
name: "RolePermissions",
columns: table => new
{
RoleId = table.Column<string>(type: "text", nullable: false),
PermissionId = table.Column<string>(type: "text", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RolePermissions", x => new { x.RoleId, x.PermissionId });
table.ForeignKey(
name: "FK_RolePermissions_Permissions_PermissionId",
column: x => x.PermissionId,
principalTable: "Permissions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RolePermissions_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "LoginLogs",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "日志ID"),
UserId = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false, comment: "用户ID"),
LoginTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "登录时间"),
IpAddress = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "登录IP"),
UserAgent = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false, comment: "设备信息"),
IsSuccess = table.Column<bool>(type: "boolean", nullable: false, comment: "登录状态(成功/失败)"),
FailureReason = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true, comment: "失败原因"),
Location = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true, comment: "登录位置"),
Browser = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "浏览器信息"),
OperatingSystem = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "操作系统信息"),
LoginType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
LoginSource = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
SessionId = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LoginLogs", x => x.Id);
table.ForeignKey(
name: "FK_LoginLogs_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
},
comment: "用户登录日志表");
migrationBuilder.CreateTable(
name: "UserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
RoleId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_UserRoles_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_UserRoles_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
},
comment: "用户角色关系表");
migrationBuilder.CreateTable(
name: "Stack_CoreIMS_Bindings",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false, comment: "绑定关系ID"),
StackId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "栈ID"),
Index = table.Column<int>(type: "integer", nullable: false, comment: "索引"),
CnId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "核心网配置ID"),
ImsId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, comment: "IMS配置ID"),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "更新时间"),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
CreatedBy = table.Column<string>(type: "text", nullable: false),
UpdatedBy = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Stack_CoreIMS_Bindings", x => x.Id);
table.ForeignKey(
name: "FK_Stack_CoreIMS_Bindings_CoreNetworkConfigs_CnId",
column: x => x.CnId,
principalTable: "CoreNetworkConfigs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Stack_CoreIMS_Bindings_IMS_Configurations_ImsId",
column: x => x.ImsId,
principalTable: "IMS_Configurations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Stack_CoreIMS_Bindings_NetworkStackConfigs_StackId",
column: x => x.StackId,
principalTable: "NetworkStackConfigs",
principalColumn: "StackId",
onDelete: ReferentialAction.Cascade);
},
comment: "栈与核心网/IMS绑定关系表");
migrationBuilder.CreateIndex(
name: "IX_CellularDevices_SerialNumber",
table: "CellularDevices",
column: "SerialNumber",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_CoreNetworkConfigs_Name",
table: "CoreNetworkConfigs",
column: "Name");
migrationBuilder.CreateIndex(
name: "IX_IMS_Configurations_Name",
table: "IMS_Configurations",
column: "Name");
migrationBuilder.CreateIndex(
name: "IX_LoginLogs_IpAddress",
table: "LoginLogs",
column: "IpAddress");
migrationBuilder.CreateIndex(
name: "IX_LoginLogs_LoginTime",
table: "LoginLogs",
column: "LoginTime");
migrationBuilder.CreateIndex(
name: "IX_LoginLogs_UserId",
table: "LoginLogs",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_LoginLogs_UserId_LoginTime",
table: "LoginLogs",
columns: new[] { "UserId", "LoginTime" });
migrationBuilder.CreateIndex(
name: "IX_NetworkStackConfigs_IsActive",
table: "NetworkStackConfigs",
column: "IsActive");
migrationBuilder.CreateIndex(
name: "IX_NetworkStackConfigs_RanId",
table: "NetworkStackConfigs",
column: "RanId");
migrationBuilder.CreateIndex(
name: "IX_NetworkStackConfigs_StackId",
table: "NetworkStackConfigs",
column: "StackId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ProtocolVersions_SerialNumber",
table: "ProtocolVersions",
column: "SerialNumber");
migrationBuilder.CreateIndex(
name: "IX_ProtocolVersions_Version",
table: "ProtocolVersions",
column: "Version");
migrationBuilder.CreateIndex(
name: "IX_RAN_Configurations_Name",
table: "RAN_Configurations",
column: "Name");
migrationBuilder.CreateIndex(
name: "IX_RolePermissions_PermissionId",
table: "RolePermissions",
column: "PermissionId");
migrationBuilder.CreateIndex(
name: "IX_Roles_Name",
table: "Roles",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "Roles",
column: "NormalizedName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Stack_CoreIMS_Bindings_CnId",
table: "Stack_CoreIMS_Bindings",
column: "CnId");
migrationBuilder.CreateIndex(
name: "IX_Stack_CoreIMS_Bindings_ImsId",
table: "Stack_CoreIMS_Bindings",
column: "ImsId");
migrationBuilder.CreateIndex(
name: "IX_Stack_CoreIMS_Bindings_StackId",
table: "Stack_CoreIMS_Bindings",
column: "StackId");
migrationBuilder.CreateIndex(
name: "IX_Stack_CoreIMS_Bindings_StackId_Index",
table: "Stack_CoreIMS_Bindings",
columns: new[] { "StackId", "Index" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UserRoles_RoleId",
table: "UserRoles",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "EmailIndex",
table: "Users",
column: "NormalizedEmail");
migrationBuilder.CreateIndex(
name: "IX_Users_Email",
table: "Users",
column: "Email",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_PhoneNumber",
table: "Users",
column: "PhoneNumber",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_UserName",
table: "Users",
column: "UserName",
unique: true);
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "Users",
column: "NormalizedUserName",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LoginLogs");
migrationBuilder.DropTable(
name: "ProtocolVersions");
migrationBuilder.DropTable(
name: "RolePermissions");
migrationBuilder.DropTable(
name: "Stack_CoreIMS_Bindings");
migrationBuilder.DropTable(
name: "UserRoles");
migrationBuilder.DropTable(
name: "CellularDevices");
migrationBuilder.DropTable(
name: "Permissions");
migrationBuilder.DropTable(
name: "CoreNetworkConfigs");
migrationBuilder.DropTable(
name: "IMS_Configurations");
migrationBuilder.DropTable(
name: "NetworkStackConfigs");
migrationBuilder.DropTable(
name: "Roles");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "RAN_Configurations");
}
}
}