using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Hua.Todo.Application.Migrations { /// public partial class AddCloudSyncCoreEntities : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "UserId", table: "Tasks", type: "TEXT", nullable: false, defaultValue: new Guid("00000000-0000-0000-0000-000000000001")); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), UserName = table.Column(type: "TEXT", maxLength: 64, nullable: false), PasswordHash = table.Column(type: "TEXT", nullable: false), Role = table.Column(type: "TEXT", maxLength: 32, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.InsertData( table: "Users", columns: new[] { "Id", "UserName", "PasswordHash", "Role" }, values: new object[] { new Guid("00000000-0000-0000-0000-000000000001"), "local", "", "local" }); migrationBuilder.CreateTable( name: "SecurityPolicies", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), UserId = table.Column(type: "TEXT", nullable: false), AllowPersist = table.Column(type: "INTEGER", nullable: false, defaultValue: true) }, constraints: table => { table.PrimaryKey("PK_SecurityPolicies", x => x.Id); table.ForeignKey( name: "FK_SecurityPolicies_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserSessions", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), UserId = table.Column(type: "TEXT", nullable: false), CreatedAtUtc = table.Column(type: "TEXT", nullable: false), ExpiresAtUtc = table.Column(type: "TEXT", nullable: false), StepUpExpiresAtUtc = table.Column(type: "TEXT", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserSessions", x => x.Id); table.ForeignKey( name: "FK_UserSessions_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Tasks_UserId", table: "Tasks", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_SecurityPolicies_UserId", table: "SecurityPolicies", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_UserName", table: "Users", column: "UserName", unique: true); migrationBuilder.CreateIndex( name: "IX_UserSessions_UserId", table: "UserSessions", column: "UserId"); migrationBuilder.AddForeignKey( name: "FK_Tasks_Users_UserId", table: "Tasks", column: "UserId", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Tasks_Users_UserId", table: "Tasks"); migrationBuilder.DropTable( name: "SecurityPolicies"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropIndex( name: "IX_Tasks_UserId", table: "Tasks"); migrationBuilder.DropColumn( name: "UserId", table: "Tasks"); } } }