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.

191 lines
8.7 KiB

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CellularManagement.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
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),
Description = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
CreatedAt = table.Column<DateTime>(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<string>(type: "text", nullable: false, comment: "角色ID,主键"),
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, 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,主键"),
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: "登录失败次数")
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
},
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: "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.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);
}
/// <inheritdoc />
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");
}
}
}