using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace CampusErrand.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Banners", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ImageUrl = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), LinkType = table.Column(type: "nvarchar(max)", nullable: false), LinkUrl = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), SortOrder = table.Column(type: "int", nullable: false), IsEnabled = table.Column(type: "bit", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Banners", x => x.Id); }); migrationBuilder.CreateTable( name: "CommissionRules", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), MinAmount = table.Column(type: "decimal(10,2)", nullable: false), MaxAmount = table.Column(type: "decimal(10,2)", nullable: true), RateType = table.Column(type: "nvarchar(max)", nullable: false), Rate = table.Column(type: "decimal(10,4)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CommissionRules", x => x.Id); }); migrationBuilder.CreateTable( name: "ServiceEntries", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), IconUrl = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), PagePath = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), SortOrder = table.Column(type: "int", nullable: false), IsEnabled = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ServiceEntries", x => x.Id); }); migrationBuilder.CreateTable( name: "Shops", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Photo = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), Location = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), Notice = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: true), PackingFeeType = table.Column(type: "nvarchar(max)", nullable: false), PackingFeeAmount = table.Column(type: "decimal(10,2)", nullable: false), IsEnabled = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Shops", x => x.Id); }); migrationBuilder.CreateTable( name: "SystemConfigs", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Key = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Value = table.Column(type: "nvarchar(max)", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SystemConfigs", x => x.Id); }); migrationBuilder.CreateTable( name: "SystemMessages", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Title = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), Content = table.Column(type: "nvarchar(max)", nullable: false), ThumbnailUrl = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), TargetType = table.Column(type: "nvarchar(max)", nullable: false), TargetUserIds = table.Column(type: "nvarchar(max)", nullable: true), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SystemMessages", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OpenId = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), Phone = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), Nickname = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), AvatarUrl = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), Role = table.Column(type: "nvarchar(max)", nullable: false), RunnerScore = table.Column(type: "int", nullable: false), IsBanned = table.Column(type: "bit", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Dishes", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ShopId = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Photo = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), Price = table.Column(type: "decimal(10,2)", nullable: false), IsEnabled = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Dishes", x => x.Id); table.ForeignKey( name: "FK_Dishes_Shops_ShopId", column: x => x.ShopId, principalTable: "Shops", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ShopBanners", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ShopId = table.Column(type: "int", nullable: false), ImageUrl = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), SortOrder = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ShopBanners", x => x.Id); table.ForeignKey( name: "FK_ShopBanners_Shops_ShopId", column: x => x.ShopId, principalTable: "Shops", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MessageReads", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), MessageType = table.Column(type: "nvarchar(450)", nullable: false), MessageId = table.Column(type: "int", nullable: false), ReadAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MessageReads", x => x.Id); table.ForeignKey( name: "FK_MessageReads_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Orders", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OrderNo = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), OwnerId = table.Column(type: "int", nullable: false), RunnerId = table.Column(type: "int", nullable: true), OrderType = table.Column(type: "nvarchar(max)", nullable: false), Status = table.Column(type: "nvarchar(450)", nullable: false), ItemName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), PickupLocation = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), DeliveryLocation = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), Remark = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), Phone = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), Commission = table.Column(type: "decimal(10,2)", nullable: false), GoodsAmount = table.Column(type: "decimal(10,2)", nullable: true), TotalAmount = table.Column(type: "decimal(10,2)", nullable: false), CompletionProof = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), IsReviewed = table.Column(type: "bit", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), AcceptedAt = table.Column(type: "datetime2", nullable: true), CompletedAt = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); table.ForeignKey( name: "FK_Orders_Users_OwnerId", column: x => x.OwnerId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Orders_Users_RunnerId", column: x => x.RunnerId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "RunnerCertifications", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), RealName = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: false), Phone = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), Status = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), ReviewedAt = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RunnerCertifications", x => x.Id); table.ForeignKey( name: "FK_RunnerCertifications_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Withdrawals", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), Amount = table.Column(type: "decimal(10,2)", nullable: false), PaymentMethod = table.Column(type: "nvarchar(max)", nullable: false), QrCodeImage = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: false), Status = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Withdrawals", x => x.Id); table.ForeignKey( name: "FK_Withdrawals_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Appeals", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OrderId = table.Column(type: "int", nullable: false), Result = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Appeals", x => x.Id); table.ForeignKey( name: "FK_Appeals_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Earnings", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), OrderId = table.Column(type: "int", nullable: false), GoodsAmount = table.Column(type: "decimal(10,2)", nullable: true), Commission = table.Column(type: "decimal(10,2)", nullable: false), PlatformFee = table.Column(type: "decimal(10,2)", nullable: false), NetEarning = table.Column(type: "decimal(10,2)", nullable: false), Status = table.Column(type: "nvarchar(max)", nullable: false), FrozenUntil = table.Column(type: "datetime2", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Earnings", x => x.Id); table.ForeignKey( name: "FK_Earnings_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Earnings_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "FoodOrderItems", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OrderId = table.Column(type: "int", nullable: false), ShopId = table.Column(type: "int", nullable: false), DishId = table.Column(type: "int", nullable: false), Quantity = table.Column(type: "int", nullable: false), UnitPrice = table.Column(type: "decimal(10,2)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_FoodOrderItems", x => x.Id); table.ForeignKey( name: "FK_FoodOrderItems_Dishes_DishId", column: x => x.DishId, principalTable: "Dishes", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_FoodOrderItems_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_FoodOrderItems_Shops_ShopId", column: x => x.ShopId, principalTable: "Shops", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "PriceChanges", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OrderId = table.Column(type: "int", nullable: false), InitiatorId = table.Column(type: "int", nullable: false), ChangeType = table.Column(type: "nvarchar(max)", nullable: false), OriginalPrice = table.Column(type: "decimal(10,2)", nullable: false), NewPrice = table.Column(type: "decimal(10,2)", nullable: false), Status = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PriceChanges", x => x.Id); table.ForeignKey( name: "FK_PriceChanges_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PriceChanges_Users_InitiatorId", column: x => x.InitiatorId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Reviews", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OrderId = table.Column(type: "int", nullable: false), RunnerId = table.Column(type: "int", nullable: false), Rating = table.Column(type: "int", nullable: false), Content = table.Column(type: "nvarchar(512)", maxLength: 512, nullable: true), ScoreChange = table.Column(type: "int", nullable: false), IsDisabled = table.Column(type: "bit", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Reviews", x => x.Id); table.ForeignKey( name: "FK_Reviews_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Reviews_Users_RunnerId", column: x => x.RunnerId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Appeals_OrderId", table: "Appeals", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_Banners_SortOrder", table: "Banners", column: "SortOrder"); migrationBuilder.CreateIndex( name: "IX_Dishes_ShopId", table: "Dishes", column: "ShopId"); migrationBuilder.CreateIndex( name: "IX_Earnings_OrderId", table: "Earnings", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_Earnings_UserId", table: "Earnings", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_FoodOrderItems_DishId", table: "FoodOrderItems", column: "DishId"); migrationBuilder.CreateIndex( name: "IX_FoodOrderItems_OrderId", table: "FoodOrderItems", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_FoodOrderItems_ShopId", table: "FoodOrderItems", column: "ShopId"); migrationBuilder.CreateIndex( name: "IX_MessageReads_UserId_MessageType_MessageId", table: "MessageReads", columns: new[] { "UserId", "MessageType", "MessageId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Orders_OrderNo", table: "Orders", column: "OrderNo", unique: true); migrationBuilder.CreateIndex( name: "IX_Orders_OwnerId", table: "Orders", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_Orders_RunnerId", table: "Orders", column: "RunnerId"); migrationBuilder.CreateIndex( name: "IX_Orders_Status", table: "Orders", column: "Status"); migrationBuilder.CreateIndex( name: "IX_PriceChanges_InitiatorId", table: "PriceChanges", column: "InitiatorId"); migrationBuilder.CreateIndex( name: "IX_PriceChanges_OrderId", table: "PriceChanges", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_Reviews_OrderId", table: "Reviews", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_Reviews_RunnerId", table: "Reviews", column: "RunnerId"); migrationBuilder.CreateIndex( name: "IX_RunnerCertifications_UserId", table: "RunnerCertifications", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_ServiceEntries_SortOrder", table: "ServiceEntries", column: "SortOrder"); migrationBuilder.CreateIndex( name: "IX_ShopBanners_ShopId", table: "ShopBanners", column: "ShopId"); migrationBuilder.CreateIndex( name: "IX_SystemConfigs_Key", table: "SystemConfigs", column: "Key", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_OpenId", table: "Users", column: "OpenId", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Phone", table: "Users", column: "Phone"); migrationBuilder.CreateIndex( name: "IX_Withdrawals_UserId", table: "Withdrawals", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Appeals"); migrationBuilder.DropTable( name: "Banners"); migrationBuilder.DropTable( name: "CommissionRules"); migrationBuilder.DropTable( name: "Earnings"); migrationBuilder.DropTable( name: "FoodOrderItems"); migrationBuilder.DropTable( name: "MessageReads"); migrationBuilder.DropTable( name: "PriceChanges"); migrationBuilder.DropTable( name: "Reviews"); migrationBuilder.DropTable( name: "RunnerCertifications"); migrationBuilder.DropTable( name: "ServiceEntries"); migrationBuilder.DropTable( name: "ShopBanners"); migrationBuilder.DropTable( name: "SystemConfigs"); migrationBuilder.DropTable( name: "SystemMessages"); migrationBuilder.DropTable( name: "Withdrawals"); migrationBuilder.DropTable( name: "Dishes"); migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "Shops"); migrationBuilder.DropTable( name: "Users"); } } }