campus-errand/server/Migrations/20260312091300_InitialCreate.cs
2026-03-12 18:12:10 +08:00

628 lines
29 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CampusErrand.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Banners",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ImageUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
LinkType = table.Column<string>(type: "nvarchar(max)", nullable: false),
LinkUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
SortOrder = table.Column<int>(type: "int", nullable: false),
IsEnabled = table.Column<bool>(type: "bit", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Banners", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CommissionRules",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MinAmount = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
MaxAmount = table.Column<decimal>(type: "decimal(10,2)", nullable: true),
RateType = table.Column<string>(type: "nvarchar(max)", nullable: false),
Rate = table.Column<decimal>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
IconUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
PagePath = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
SortOrder = table.Column<int>(type: "int", nullable: false),
IsEnabled = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ServiceEntries", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
Photo = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
Location = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
Notice = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
PackingFeeType = table.Column<string>(type: "nvarchar(max)", nullable: false),
PackingFeeAmount = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
IsEnabled = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SystemConfigs",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Key = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
Value = table.Column<string>(type: "nvarchar(max)", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SystemConfigs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SystemMessages",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
Content = table.Column<string>(type: "nvarchar(max)", nullable: false),
ThumbnailUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
TargetType = table.Column<string>(type: "nvarchar(max)", nullable: false),
TargetUserIds = table.Column<string>(type: "nvarchar(max)", nullable: true),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SystemMessages", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OpenId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
Phone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
Nickname = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
AvatarUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
Role = table.Column<string>(type: "nvarchar(max)", nullable: false),
RunnerScore = table.Column<int>(type: "int", nullable: false),
IsBanned = table.Column<bool>(type: "bit", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Dishes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ShopId = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
Photo = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
Price = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
IsEnabled = table.Column<bool>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ShopId = table.Column<int>(type: "int", nullable: false),
ImageUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
SortOrder = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
MessageType = table.Column<string>(type: "nvarchar(450)", nullable: false),
MessageId = table.Column<int>(type: "int", nullable: false),
ReadAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderNo = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
OwnerId = table.Column<int>(type: "int", nullable: false),
RunnerId = table.Column<int>(type: "int", nullable: true),
OrderType = table.Column<string>(type: "nvarchar(max)", nullable: false),
Status = table.Column<string>(type: "nvarchar(450)", nullable: false),
ItemName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
PickupLocation = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
DeliveryLocation = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
Remark = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
Phone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
Commission = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
GoodsAmount = table.Column<decimal>(type: "decimal(10,2)", nullable: true),
TotalAmount = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
CompletionProof = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
IsReviewed = table.Column<bool>(type: "bit", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
AcceptedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CompletedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
RealName = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
Phone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
Status = table.Column<string>(type: "nvarchar(max)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
ReviewedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
Amount = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
PaymentMethod = table.Column<string>(type: "nvarchar(max)", nullable: false),
QrCodeImage = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
Status = table.Column<string>(type: "nvarchar(max)", nullable: false),
CreatedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderId = table.Column<int>(type: "int", nullable: false),
Result = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
CreatedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
OrderId = table.Column<int>(type: "int", nullable: false),
GoodsAmount = table.Column<decimal>(type: "decimal(10,2)", nullable: true),
Commission = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
PlatformFee = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
NetEarning = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
Status = table.Column<string>(type: "nvarchar(max)", nullable: false),
FrozenUntil = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderId = table.Column<int>(type: "int", nullable: false),
ShopId = table.Column<int>(type: "int", nullable: false),
DishId = table.Column<int>(type: "int", nullable: false),
Quantity = table.Column<int>(type: "int", nullable: false),
UnitPrice = table.Column<decimal>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderId = table.Column<int>(type: "int", nullable: false),
InitiatorId = table.Column<int>(type: "int", nullable: false),
ChangeType = table.Column<string>(type: "nvarchar(max)", nullable: false),
OriginalPrice = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
NewPrice = table.Column<decimal>(type: "decimal(10,2)", nullable: false),
Status = table.Column<string>(type: "nvarchar(max)", nullable: false),
CreatedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderId = table.Column<int>(type: "int", nullable: false),
RunnerId = table.Column<int>(type: "int", nullable: false),
Rating = table.Column<int>(type: "int", nullable: false),
Content = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
ScoreChange = table.Column<int>(type: "int", nullable: false),
IsDisabled = table.Column<bool>(type: "bit", nullable: false),
CreatedAt = table.Column<DateTime>(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");
}
/// <inheritdoc />
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");
}
}
}