using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace MiaoJiZhang.Infrastructure.Persistence.Migrations { /// public partial class InitialBaseline : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "AiAvatars", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Key = table.Column(type: "varchar(255)", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), DefaultName = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), SpeechTic = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ImageUrl = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), IsEnabled = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AiAvatars", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "AiPersonas", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Key = table.Column(type: "varchar(255)", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Name = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Description = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), SampleLine = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), PromptTemplate = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Version = table.Column(type: "int", nullable: false), IsEnabled = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AiPersonas", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "AppConfigs", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Key = table.Column(type: "varchar(255)", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Value = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Version = table.Column(type: "int", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AppConfigs", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Categories", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "bigint", nullable: true), Type = table.Column(type: "int", nullable: false), Name = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), IconKey = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), SortOrder = table.Column(type: "int", nullable: false), IsDeleted = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "ChatMessages", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "bigint", nullable: false), Role = table.Column(type: "int", nullable: false), Type = table.Column(type: "int", nullable: false), Content = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), TransactionId = table.Column(type: "bigint", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ChatMessages", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Stickers", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Key = table.Column(type: "varchar(255)", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Label = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ImageUrl = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), GroupKey = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), TriggerTags = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), IsEnabled = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Stickers", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Username = table.Column(type: "varchar(32)", maxLength: 32, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), PasswordHash = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Nickname = table.Column(type: "varchar(32)", maxLength: 32, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), AvatarUrl = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), Email = table.Column(type: "varchar(255)", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), EmailVerified = table.Column(type: "tinyint(1)", nullable: false), Phone = table.Column(type: "varchar(255)", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), PhoneVerified = table.Column(type: "tinyint(1)", nullable: false), WeChatOpenId = table.Column(type: "varchar(255)", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), WeChatUnionId = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), AppleUserId = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), AppMode = table.Column(type: "int", nullable: false), IsBanned = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), LastLoginAt = table.Column(type: "datetime(6)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "AiCompanionSettings", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "bigint", nullable: false), AvatarKey = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), CustomName = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), PersonaKey = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), RoastLevel = table.Column(type: "int", nullable: false), StickerFrequency = table.Column(type: "int", nullable: false), ProactiveLevel = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AiCompanionSettings", x => x.Id); table.ForeignKey( name: "FK_AiCompanionSettings_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Ledgers", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), OwnerId = table.Column(type: "bigint", nullable: false), Name = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), IconKey = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), IsDefault = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Ledgers", x => x.Id); table.ForeignKey( name: "FK_Ledgers_Users_OwnerId", column: x => x.OwnerId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Budgets", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), LedgerId = table.Column(type: "bigint", nullable: false), UserId = table.Column(type: "bigint", nullable: false), CategoryId = table.Column(type: "bigint", nullable: true), Period = table.Column(type: "int", nullable: false), Amount = table.Column(type: "decimal(12,2)", precision: 12, scale: 2, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Budgets", x => x.Id); table.ForeignKey( name: "FK_Budgets_Ledgers_LedgerId", column: x => x.LedgerId, principalTable: "Ledgers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Transactions", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), LedgerId = table.Column(type: "bigint", nullable: false), UserId = table.Column(type: "bigint", nullable: false), CategoryId = table.Column(type: "bigint", nullable: false), Type = table.Column(type: "int", nullable: false), Amount = table.Column(type: "decimal(12,2)", precision: 12, scale: 2, nullable: false), Note = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), PaymentMethod = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), OccurredAt = table.Column(type: "datetime(6)", nullable: false), Source = table.Column(type: "int", nullable: false), SourceText = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), SourceChatMessageId = table.Column(type: "bigint", nullable: true), IsDeleted = table.Column(type: "tinyint(1)", nullable: false), DeletedAt = table.Column(type: "datetime(6)", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Transactions", x => x.Id); table.ForeignKey( name: "FK_Transactions_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Transactions_Ledgers_LedgerId", column: x => x.LedgerId, principalTable: "Ledgers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_AiAvatars_Key", table: "AiAvatars", column: "Key", unique: true); migrationBuilder.CreateIndex( name: "IX_AiCompanionSettings_UserId", table: "AiCompanionSettings", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_AiPersonas_Key", table: "AiPersonas", column: "Key", unique: true); migrationBuilder.CreateIndex( name: "IX_AppConfigs_Key", table: "AppConfigs", column: "Key", unique: true); migrationBuilder.CreateIndex( name: "IX_Budgets_LedgerId_Period_CategoryId", table: "Budgets", columns: new[] { "LedgerId", "Period", "CategoryId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_ChatMessages_UserId_CreatedAt", table: "ChatMessages", columns: new[] { "UserId", "CreatedAt" }); migrationBuilder.CreateIndex( name: "IX_Ledgers_OwnerId", table: "Ledgers", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_Stickers_Key", table: "Stickers", column: "Key", unique: true); migrationBuilder.CreateIndex( name: "IX_Transactions_CategoryId", table: "Transactions", column: "CategoryId"); migrationBuilder.CreateIndex( name: "IX_Transactions_LedgerId_OccurredAt", table: "Transactions", columns: new[] { "LedgerId", "OccurredAt" }); migrationBuilder.CreateIndex( name: "IX_Transactions_UserId_IsDeleted", table: "Transactions", columns: new[] { "UserId", "IsDeleted" }); migrationBuilder.CreateIndex( name: "IX_Users_Email", table: "Users", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Phone", table: "Users", column: "Phone", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Username", table: "Users", column: "Username", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_WeChatOpenId", table: "Users", column: "WeChatOpenId", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AiAvatars"); migrationBuilder.DropTable( name: "AiCompanionSettings"); migrationBuilder.DropTable( name: "AiPersonas"); migrationBuilder.DropTable( name: "AppConfigs"); migrationBuilder.DropTable( name: "Budgets"); migrationBuilder.DropTable( name: "ChatMessages"); migrationBuilder.DropTable( name: "Stickers"); migrationBuilder.DropTable( name: "Transactions"); migrationBuilder.DropTable( name: "Categories"); migrationBuilder.DropTable( name: "Ledgers"); migrationBuilder.DropTable( name: "Users"); } } }