using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace LingAdmin.IdentityService.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Email = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), PasswordHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), Status = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), LastLoginAt = table.Column(type: "datetime2", nullable: true), UpdatedAt = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "RefreshTokens", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), Token = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), ExpiresAt = table.Column(type: "datetime2", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), CreatedByIp = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true), RevokedAt = table.Column(type: "datetime2", nullable: true), RevokedByIp = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true), ReplacedByToken = table.Column(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); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "RefreshTokens"); migrationBuilder.DropTable( name: "Users"); } } }