93 lines
4.1 KiB
C#
93 lines
4.1 KiB
C#
|
|
using System;
|
|||
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|||
|
|
|
|||
|
|
#nullable disable
|
|||
|
|
|
|||
|
|
namespace LingAdmin.IdentityService.Migrations
|
|||
|
|
{
|
|||
|
|
/// <inheritdoc />
|
|||
|
|
public partial class InitialCreate : Migration
|
|||
|
|
{
|
|||
|
|
/// <inheritdoc />
|
|||
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|||
|
|
{
|
|||
|
|
migrationBuilder.CreateTable(
|
|||
|
|
name: "Users",
|
|||
|
|
columns: table => new
|
|||
|
|
{
|
|||
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
|
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
|||
|
|
Email = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
|
|||
|
|
PasswordHash = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
|
|||
|
|
Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
|||
|
|
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|||
|
|
LastLoginAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
|||
|
|
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
|
|||
|
|
},
|
|||
|
|
constraints: table =>
|
|||
|
|
{
|
|||
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
migrationBuilder.CreateTable(
|
|||
|
|
name: "RefreshTokens",
|
|||
|
|
columns: table => new
|
|||
|
|
{
|
|||
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|||
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|||
|
|
UserId = table.Column<int>(type: "int", nullable: false),
|
|||
|
|
Token = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
|||
|
|
ExpiresAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|||
|
|
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|||
|
|
CreatedByIp = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
|||
|
|
RevokedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
|||
|
|
RevokedByIp = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
|||
|
|
ReplacedByToken = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true)
|
|||
|
|
},
|
|||
|
|
constraints: table =>
|
|||
|
|
{
|
|||
|
|
table.PrimaryKey("PK_RefreshTokens", x => x.Id);
|
|||
|
|
table.ForeignKey(
|
|||
|
|
name: "FK_RefreshTokens_Users_UserId",
|
|||
|
|
column: x => x.UserId,
|
|||
|
|
principalTable: "Users",
|
|||
|
|
principalColumn: "Id",
|
|||
|
|
onDelete: ReferentialAction.Cascade);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
migrationBuilder.InsertData(
|
|||
|
|
table: "Users",
|
|||
|
|
columns: new[] { "Id", "CreatedAt", "Email", "LastLoginAt", "Name", "PasswordHash", "Status", "UpdatedAt" },
|
|||
|
|
values: new object[] { 1, new DateTime(2024, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "admin@lingadmin.com", null, "System Admin", "$2a$11$K7VJyGqVhWD0VvHK8YxGOOQkJvYQJLHN7O0zLPqL4gFx5lK3qR8sC", "Active", null });
|
|||
|
|
|
|||
|
|
migrationBuilder.CreateIndex(
|
|||
|
|
name: "IX_RefreshTokens_Token",
|
|||
|
|
table: "RefreshTokens",
|
|||
|
|
column: "Token",
|
|||
|
|
unique: true);
|
|||
|
|
|
|||
|
|
migrationBuilder.CreateIndex(
|
|||
|
|
name: "IX_RefreshTokens_UserId",
|
|||
|
|
table: "RefreshTokens",
|
|||
|
|
column: "UserId");
|
|||
|
|
|
|||
|
|
migrationBuilder.CreateIndex(
|
|||
|
|
name: "IX_Users_Email",
|
|||
|
|
table: "Users",
|
|||
|
|
column: "Email",
|
|||
|
|
unique: true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <inheritdoc />
|
|||
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|||
|
|
{
|
|||
|
|
migrationBuilder.DropTable(
|
|||
|
|
name: "RefreshTokens");
|
|||
|
|
|
|||
|
|
migrationBuilder.DropTable(
|
|||
|
|
name: "Users");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|