using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace CellularManagement.Infrastructure.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Permissions", columns: table => new { Id = table.Column(type: "text", nullable: false), Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Permissions", x => x.Id); }); migrationBuilder.CreateTable( name: "Roles", columns: table => new { Id = table.Column(type: "text", nullable: false, comment: "角色ID,主键"), Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true, comment: "角色描述"), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false, comment: "角色名称"), NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: false, comment: "标准化角色名称(大写)"), ConcurrencyStamp = table.Column(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(type: "text", nullable: false, comment: "用户ID,主键"), UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: false, comment: "用户名"), NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "标准化用户名(大写)"), Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: false, comment: "电子邮箱"), NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "标准化电子邮箱(大写)"), EmailConfirmed = table.Column(type: "boolean", nullable: false, comment: "邮箱是否已验证"), PasswordHash = table.Column(type: "text", nullable: true, comment: "密码哈希值"), SecurityStamp = table.Column(type: "text", nullable: true, comment: "安全戳,用于并发控制"), ConcurrencyStamp = table.Column(type: "text", nullable: true, comment: "并发控制戳"), PhoneNumber = table.Column(type: "text", nullable: false, comment: "电话号码"), PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false, comment: "电话号码是否已验证"), TwoFactorEnabled = table.Column(type: "boolean", nullable: false, comment: "是否启用双因素认证"), LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true, comment: "账户锁定结束时间"), LockoutEnabled = table.Column(type: "boolean", nullable: false, comment: "是否启用账户锁定"), AccessFailedCount = table.Column(type: "integer", nullable: false, comment: "登录失败次数") }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }, comment: "用户表"); migrationBuilder.CreateTable( name: "RolePermissions", columns: table => new { RoleId = table.Column(type: "text", nullable: false), PermissionId = table.Column(type: "text", nullable: false), CreatedAt = table.Column(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: "UserRoles", columns: table => new { UserId = table.Column(type: "text", nullable: false), RoleId = table.Column(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.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_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); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "RolePermissions"); migrationBuilder.DropTable( name: "UserRoles"); migrationBuilder.DropTable( name: "Permissions"); migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "Users"); } } }