修复数据库迁移

This commit is contained in:
biss committed 2026-08-22 20:18:56 +08:00
1 parent b1075acf8f
commit a9e10de2c4
7 files changed
+9657 -9

No files matched your search

@@ -285,7 +285,9 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
builder.Entity<Classroom>(entity =>
{
entity.Property(x => x.Floor).HasDefaultValue(1);
entity.Property(x => x.AvailabilityStatus).HasDefaultValue(ClassroomAvailabilityStatus.Normal);
entity.Property(x => x.AvailabilityStatus)
.HasDefaultValue(ClassroomAvailabilityStatus.Normal)
.HasSentinel((ClassroomAvailabilityStatus)0);
entity.HasOne(x => x.Building)
.WithMany()
.HasForeignKey(x => x.BuildingId)
@@ -904,7 +906,9 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
{
entity.Property(x => x.Name).HasMaxLength(120);
entity.Property(x => x.MaxCredits).HasPrecision(6, 1);
entity.Property(x => x.Scope).HasDefaultValue(CourseSelectionScope.All);
entity.Property(x => x.Scope)
.HasDefaultValue(CourseSelectionScope.All)
.HasSentinel((CourseSelectionScope)0);
entity.Property(x => x.Notes).HasMaxLength(500);
entity.HasIndex(x => new { x.AcademicTermId, x.Status });
entity.HasOne(x => x.AcademicTerm)
@@ -9,18 +9,30 @@ public partial class CampusRegistrationPayments : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(name: "CampusRegistrationProjects", columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false), Code = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false), Name = table.Column<string>(type: "varchar(120)", maxLength: 120, nullable: false), Description = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: true), CollegeId = table.Column<Guid>(type: "char(36)", nullable: true), RegistrationStartsAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), RegistrationEndsAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), Capacity = table.Column<int>(type: "int", nullable: false), FeeAmount = table.Column<decimal>(type: "decimal(10,2)", nullable: false), RequiresReview = table.Column<bool>(type: "tinyint(1)", nullable: false), Status = table.Column<int>(type: "int", nullable: false), ContactName = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true), ContactPhone = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true), Notes = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true), CreatedByUserId = table.Column<Guid>(type: "char(36)", nullable: false), CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
}, constraints: table => { table.PrimaryKey("PK_CampusRegistrationProjects", x => x.Id); table.ForeignKey("FK_CampusRegistrationProjects_Colleges_CollegeId", x => x.CollegeId, "Colleges", "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey("FK_CampusRegistrationProjects_AspNetUsers_CreatedByUserId", x => x.CreatedByUserId, "AspNetUsers", "Id", onDelete: ReferentialAction.Restrict); }).Annotation("MySQL:Charset", "utf8mb4");
// MySQL DDL is not transactional. IF NOT EXISTS makes a retry safe when
// an earlier attempt created this first table but failed later in the migration.
migrationBuilder.Sql("""
CREATE TABLE IF NOT EXISTS `CampusRegistrationProjects` (
`Id` char(36) NOT NULL, `Code` varchar(40) NOT NULL, `Name` varchar(120) NOT NULL,
`Description` varchar(2000) NULL, `CollegeId` char(36) NULL,
`RegistrationStartsAt` datetime(6) NOT NULL, `RegistrationEndsAt` datetime(6) NOT NULL,
`Capacity` int NOT NULL, `FeeAmount` decimal(10,2) NOT NULL, `RequiresReview` tinyint(1) NOT NULL,
`Status` int NOT NULL, `ContactName` varchar(50) NULL, `ContactPhone` varchar(30) NULL,
`Notes` varchar(500) NULL, `CreatedByUserId` char(36) NOT NULL,
`CreatedAt` datetime(6) NOT NULL, `UpdatedAt` datetime(6) NOT NULL,
PRIMARY KEY (`Id`),
CONSTRAINT `FK_CRP_College` FOREIGN KEY (`CollegeId`) REFERENCES `Colleges` (`Id`) ON DELETE SET NULL,
CONSTRAINT `FK_CRP_Creator` FOREIGN KEY (`CreatedByUserId`) REFERENCES `AspNetUsers` (`Id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
""");
migrationBuilder.CreateTable(name: "CampusRegistrationApplications", columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false), ProjectId = table.Column<Guid>(type: "char(36)", nullable: false), StudentId = table.Column<Guid>(type: "char(36)", nullable: false), Status = table.Column<int>(type: "int", nullable: false), ApplicantNote = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: true), ReviewedByUserId = table.Column<Guid>(type: "char(36)", nullable: true), ReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true), ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true), ConfirmedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true), CancelledAt = table.Column<DateTime>(type: "datetime(6)", nullable: true), CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
}, constraints: table => { table.PrimaryKey("PK_CampusRegistrationApplications", x => x.Id); table.ForeignKey("FK_CampusRegistrationApplications_CampusRegistrationProjects_ProjectId", x => x.ProjectId, "CampusRegistrationProjects", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_CampusRegistrationApplications_Students_StudentId", x => x.StudentId, "Students", "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey("FK_CampusRegistrationApplications_AspNetUsers_ReviewedByUserId", x => x.ReviewedByUserId, "AspNetUsers", "Id", onDelete: ReferentialAction.SetNull); }).Annotation("MySQL:Charset", "utf8mb4");
}, constraints: table => { table.PrimaryKey("PK_CampusRegistrationApplications", x => x.Id); table.ForeignKey("FK_CRA_Project", x => x.ProjectId, "CampusRegistrationProjects", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_CRA_Student", x => x.StudentId, "Students", "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey("FK_CRA_Reviewer", x => x.ReviewedByUserId, "AspNetUsers", "Id", onDelete: ReferentialAction.SetNull); }).Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateTable(name: "CampusPaymentOrders", columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false), ApplicationId = table.Column<Guid>(type: "char(36)", nullable: false), OrderNumber = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false), Amount = table.Column<decimal>(type: "decimal(10,2)", nullable: false), PaymentMethod = table.Column<int>(type: "int", nullable: false), Status = table.Column<int>(type: "int", nullable: false), ConfirmedByUserId = table.Column<Guid>(type: "char(36)", nullable: true), ConfirmedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true), ReferenceNumber = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true), Note = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true), CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
}, constraints: table => { table.PrimaryKey("PK_CampusPaymentOrders", x => x.Id); table.ForeignKey("FK_CampusPaymentOrders_CampusRegistrationApplications_ApplicationId", x => x.ApplicationId, "CampusRegistrationApplications", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_CampusPaymentOrders_AspNetUsers_ConfirmedByUserId", x => x.ConfirmedByUserId, "AspNetUsers", "Id", onDelete: ReferentialAction.SetNull); }).Annotation("MySQL:Charset", "utf8mb4");
}, constraints: table => { table.PrimaryKey("PK_CampusPaymentOrders", x => x.Id); table.ForeignKey("FK_CPO_Application", x => x.ApplicationId, "CampusRegistrationApplications", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_CPO_Confirmer", x => x.ConfirmedByUserId, "AspNetUsers", "Id", onDelete: ReferentialAction.SetNull); }).Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateIndex(name: "IX_CampusRegistrationProjects_Code", table: "CampusRegistrationProjects", column: "Code", unique: true); migrationBuilder.CreateIndex(name: "IX_CampusRegistrationProjects_CollegeId_Status_RegistrationEndsAt", table: "CampusRegistrationProjects", columns: new[] { "CollegeId", "Status", "RegistrationEndsAt" }); migrationBuilder.CreateIndex(name: "IX_CampusRegistrationProjects_CreatedByUserId", table: "CampusRegistrationProjects", column: "CreatedByUserId"); migrationBuilder.CreateIndex(name: "IX_CampusRegistrationApplications_ProjectId_StudentId", table: "CampusRegistrationApplications", columns: new[] { "ProjectId", "StudentId" }, unique: true); migrationBuilder.CreateIndex(name: "IX_CampusRegistrationApplications_ProjectId_Status_CreatedAt", table: "CampusRegistrationApplications", columns: new[] { "ProjectId", "Status", "CreatedAt" }); migrationBuilder.CreateIndex(name: "IX_CampusRegistrationApplications_StudentId", table: "CampusRegistrationApplications", column: "StudentId"); migrationBuilder.CreateIndex(name: "IX_CampusRegistrationApplications_ReviewedByUserId", table: "CampusRegistrationApplications", column: "ReviewedByUserId"); migrationBuilder.CreateIndex(name: "IX_CampusPaymentOrders_ApplicationId", table: "CampusPaymentOrders", column: "ApplicationId", unique: true); migrationBuilder.CreateIndex(name: "IX_CampusPaymentOrders_OrderNumber", table: "CampusPaymentOrders", column: "OrderNumber", unique: true); migrationBuilder.CreateIndex(name: "IX_CampusPaymentOrders_Status_CreatedAt", table: "CampusPaymentOrders", columns: new[] { "Status", "CreatedAt" }); migrationBuilder.CreateIndex(name: "IX_CampusPaymentOrders_ConfirmedByUserId", table: "CampusPaymentOrders", column: "ConfirmedByUserId");
}
protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable(name: "CampusPaymentOrders"); migrationBuilder.DropTable(name: "CampusRegistrationApplications"); migrationBuilder.DropTable(name: "CampusRegistrationProjects"); }
@@ -10,7 +10,7 @@ public partial class CampusWalletBalances : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(name: "CampusWalletAccounts", columns: table => new { Id = table.Column<Guid>(type: "char(36)", nullable: false), StudentId = table.Column<Guid>(type: "char(36)", nullable: false), Balance = table.Column<decimal>(type: "decimal(10,2)", nullable: false), CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CampusWalletAccounts", x => x.Id); table.ForeignKey("FK_CampusWalletAccounts_Students_StudentId", x => x.StudentId, "Students", "Id", onDelete: ReferentialAction.Restrict); }).Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateTable(name: "CampusWalletTransactions", columns: table => new { Id = table.Column<Guid>(type: "char(36)", nullable: false), WalletAccountId = table.Column<Guid>(type: "char(36)", nullable: false), Amount = table.Column<decimal>(type: "decimal(10,2)", nullable: false), BalanceAfter = table.Column<decimal>(type: "decimal(10,2)", nullable: false), Type = table.Column<int>(type: "int", nullable: false), Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false), PaymentOrderId = table.Column<Guid>(type: "char(36)", nullable: true), OperatedByUserId = table.Column<Guid>(type: "char(36)", nullable: true), CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CampusWalletTransactions", x => x.Id); table.ForeignKey("FK_CampusWalletTransactions_CampusWalletAccounts_WalletAccountId", x => x.WalletAccountId, "CampusWalletAccounts", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_CampusWalletTransactions_CampusPaymentOrders_PaymentOrderId", x => x.PaymentOrderId, "CampusPaymentOrders", "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey("FK_CampusWalletTransactions_AspNetUsers_OperatedByUserId", x => x.OperatedByUserId, "AspNetUsers", "Id", onDelete: ReferentialAction.SetNull); }).Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateTable(name: "CampusWalletTransactions", columns: table => new { Id = table.Column<Guid>(type: "char(36)", nullable: false), WalletAccountId = table.Column<Guid>(type: "char(36)", nullable: false), Amount = table.Column<decimal>(type: "decimal(10,2)", nullable: false), BalanceAfter = table.Column<decimal>(type: "decimal(10,2)", nullable: false), Type = table.Column<int>(type: "int", nullable: false), Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false), PaymentOrderId = table.Column<Guid>(type: "char(36)", nullable: true), OperatedByUserId = table.Column<Guid>(type: "char(36)", nullable: true), CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false), UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CampusWalletTransactions", x => x.Id); table.ForeignKey("FK_CWT_Account", x => x.WalletAccountId, "CampusWalletAccounts", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_CWT_PaymentOrder", x => x.PaymentOrderId, "CampusPaymentOrders", "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey("FK_CWT_Operator", x => x.OperatedByUserId, "AspNetUsers", "Id", onDelete: ReferentialAction.SetNull); }).Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateIndex(name: "IX_CampusWalletAccounts_StudentId", table: "CampusWalletAccounts", column: "StudentId", unique: true); migrationBuilder.CreateIndex(name: "IX_CampusWalletTransactions_WalletAccountId_CreatedAt", table: "CampusWalletTransactions", columns: new[] { "WalletAccountId", "CreatedAt" }); migrationBuilder.CreateIndex(name: "IX_CampusWalletTransactions_PaymentOrderId", table: "CampusWalletTransactions", column: "PaymentOrderId", unique: true); migrationBuilder.CreateIndex(name: "IX_CampusWalletTransactions_OperatedByUserId", table: "CampusWalletTransactions", column: "OperatedByUserId");
}
protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable(name: "CampusWalletTransactions"); migrationBuilder.DropTable(name: "CampusWalletAccounts"); }
Loaded 3 of 7 files, more files were not shown because too many files have changed in this diff. Show more