考试排考
This commit is contained in:
+158
@@ -0,0 +1,158 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ExamSchedulingOptimization : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Drop old FK/index on ClassroomId
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ExamSessions_Classrooms_ClassroomId",
|
||||
table: "ExamSessions");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ExamSessions_ClassroomId",
|
||||
table: "ExamSessions");
|
||||
|
||||
// Make ClassroomId nullable
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "ClassroomId",
|
||||
table: "ExamSessions",
|
||||
type: "char(36)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "char(36)");
|
||||
|
||||
// Add new columns
|
||||
migrationBuilder.AddColumn<DateOnly>(
|
||||
name: "ExamDate",
|
||||
table: "ExamSessions",
|
||||
type: "date",
|
||||
nullable: false,
|
||||
defaultValue: new DateOnly(2027, 1, 1));
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "StartPeriod",
|
||||
table: "ExamSessions",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 1);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PeriodCount",
|
||||
table: "ExamSessions",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 2);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "RequiredBuildingId",
|
||||
table: "ExamSessions",
|
||||
type: "char(36)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "RequiredInvigilatorCount",
|
||||
table: "ExamSessions",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 2);
|
||||
|
||||
// Re-add FK/index on ClassroomId (nullable, SetNull)
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ExamSessions_ClassroomId",
|
||||
table: "ExamSessions",
|
||||
column: "ClassroomId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ExamSessions_Classrooms_ClassroomId",
|
||||
table: "ExamSessions",
|
||||
column: "ClassroomId",
|
||||
principalTable: "Classrooms",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
// New indices
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ExamSessions_ExamPlanId_ExamDate",
|
||||
table: "ExamSessions",
|
||||
columns: new[] { "ExamPlanId", "ExamDate" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ExamSessions_RequiredBuildingId",
|
||||
table: "ExamSessions",
|
||||
column: "RequiredBuildingId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ExamSessions_Buildings_RequiredBuildingId",
|
||||
table: "ExamSessions",
|
||||
column: "RequiredBuildingId",
|
||||
principalTable: "Buildings",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Remove new FK/index
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ExamSessions_Buildings_RequiredBuildingId",
|
||||
table: "ExamSessions");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ExamSessions_Classrooms_ClassroomId",
|
||||
table: "ExamSessions");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ExamSessions_ClassroomId",
|
||||
table: "ExamSessions");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ExamSessions_ExamPlanId_ExamDate",
|
||||
table: "ExamSessions");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_ExamSessions_RequiredBuildingId",
|
||||
table: "ExamSessions");
|
||||
|
||||
// Drop new columns
|
||||
migrationBuilder.DropColumn(name: "RequiredInvigilatorCount", table: "ExamSessions");
|
||||
migrationBuilder.DropColumn(name: "RequiredBuildingId", table: "ExamSessions");
|
||||
migrationBuilder.DropColumn(name: "PeriodCount", table: "ExamSessions");
|
||||
migrationBuilder.DropColumn(name: "StartPeriod", table: "ExamSessions");
|
||||
migrationBuilder.DropColumn(name: "ExamDate", table: "ExamSessions");
|
||||
|
||||
// Restore ClassroomId to non-nullable
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "ClassroomId",
|
||||
table: "ExamSessions",
|
||||
type: "char(36)",
|
||||
nullable: false,
|
||||
defaultValue: Guid.Empty,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "char(36)",
|
||||
oldNullable: true);
|
||||
|
||||
// Restore original FK/index
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ExamSessions_ClassroomId",
|
||||
table: "ExamSessions",
|
||||
column: "ClassroomId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ExamSessions_Classrooms_ClassroomId",
|
||||
table: "ExamSessions",
|
||||
column: "ClassroomId",
|
||||
principalTable: "Classrooms",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user