Files
Academic-Affairs-System/src/Jiaowu.Api/Infrastructure/Persistence/Migrations/MySql/20260724111113_SchedulingOptimization.cs
T
biss 6538b6080a 自动排课:保留手工安排,按教师、行政班、周次、节次、容量和场地约束补排。
课程约束:可限定校区、教学楼、指定教室、允许上课日、最早/最晚节次。
无教室课程:教室可为空,但仍校验教师和班级冲突。
作息维护:按学期维护节次、上下课时间和启用状态。
发布保护:发布前重新检查全部约束,并阻止学时未排满的课表发布。
工作台升级:增加“排课规则与作息”“自动排课”入口,自动生成后仍支持手工微调。
同时兼容 SQLite 和 MySQL,已生成正式迁移。
2026-07-24 19:19:18 +08:00

188 lines
8.6 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
/// <inheritdoc />
public partial class SchedulingOptimization : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ScheduleEntries_Classrooms_ClassroomId",
table: "ScheduleEntries");
migrationBuilder.AlterColumn<Guid>(
name: "ClassroomId",
table: "ScheduleEntries",
type: "char(36)",
nullable: true,
oldClrType: typeof(Guid),
oldType: "char(36)");
migrationBuilder.CreateTable(
name: "ScheduleTimeSlots",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
AcademicTermId = table.Column<Guid>(type: "char(36)", nullable: false),
PeriodNumber = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false),
StartsAt = table.Column<TimeOnly>(type: "time", nullable: false),
EndsAt = table.Column<TimeOnly>(type: "time", nullable: false),
IsEnabled = table.Column<bool>(type: "tinyint(1)", 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_ScheduleTimeSlots", x => x.Id);
table.ForeignKey(
name: "FK_ScheduleTimeSlots_AcademicTerms_AcademicTermId",
column: x => x.AcademicTermId,
principalTable: "AcademicTerms",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateTable(
name: "TeachingTaskScheduleConstraints",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
RequiresClassroom = table.Column<bool>(type: "tinyint(1)", nullable: false),
RequiredCampusId = table.Column<Guid>(type: "char(36)", nullable: true),
RequiredBuildingId = table.Column<Guid>(type: "char(36)", nullable: true),
AllowedDayOfWeeks = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true),
EarliestPeriod = table.Column<int>(type: "int", nullable: true),
LatestPeriod = table.Column<int>(type: "int", 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_TeachingTaskScheduleConstraints", x => x.Id);
table.ForeignKey(
name: "FK_TeachingTaskScheduleConstraints_Buildings_RequiredBuildingId",
column: x => x.RequiredBuildingId,
principalTable: "Buildings",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_TeachingTaskScheduleConstraints_Campuses_RequiredCampusId",
column: x => x.RequiredCampusId,
principalTable: "Campuses",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_TeachingTaskScheduleConstraints_TeachingTasks_TeachingTaskId",
column: x => x.TeachingTaskId,
principalTable: "TeachingTasks",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateTable(
name: "TeachingTaskAllowedClassrooms",
columns: table => new
{
TeachingTaskScheduleConstraintId = table.Column<Guid>(type: "char(36)", nullable: false),
ClassroomId = table.Column<Guid>(type: "char(36)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TeachingTaskAllowedClassrooms", x => new { x.TeachingTaskScheduleConstraintId, x.ClassroomId });
table.ForeignKey(
name: "FK_TeachingTaskAllowedClassrooms_Classrooms_ClassroomId",
column: x => x.ClassroomId,
principalTable: "Classrooms",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_TeachingTaskAllowedClassrooms_TeachingTaskScheduleConstraint~",
column: x => x.TeachingTaskScheduleConstraintId,
principalTable: "TeachingTaskScheduleConstraints",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_ScheduleTimeSlots_AcademicTermId_PeriodNumber",
table: "ScheduleTimeSlots",
columns: new[] { "AcademicTermId", "PeriodNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_TeachingTaskAllowedClassrooms_ClassroomId",
table: "TeachingTaskAllowedClassrooms",
column: "ClassroomId");
migrationBuilder.CreateIndex(
name: "IX_TeachingTaskScheduleConstraints_RequiredBuildingId",
table: "TeachingTaskScheduleConstraints",
column: "RequiredBuildingId");
migrationBuilder.CreateIndex(
name: "IX_TeachingTaskScheduleConstraints_RequiredCampusId",
table: "TeachingTaskScheduleConstraints",
column: "RequiredCampusId");
migrationBuilder.CreateIndex(
name: "IX_TeachingTaskScheduleConstraints_TeachingTaskId",
table: "TeachingTaskScheduleConstraints",
column: "TeachingTaskId",
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_ScheduleEntries_Classrooms_ClassroomId",
table: "ScheduleEntries",
column: "ClassroomId",
principalTable: "Classrooms",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ScheduleEntries_Classrooms_ClassroomId",
table: "ScheduleEntries");
migrationBuilder.DropTable(
name: "ScheduleTimeSlots");
migrationBuilder.DropTable(
name: "TeachingTaskAllowedClassrooms");
migrationBuilder.DropTable(
name: "TeachingTaskScheduleConstraints");
migrationBuilder.AlterColumn<Guid>(
name: "ClassroomId",
table: "ScheduleEntries",
type: "char(36)",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
oldClrType: typeof(Guid),
oldType: "char(36)",
oldNullable: true);
migrationBuilder.AddForeignKey(
name: "FK_ScheduleEntries_Classrooms_ClassroomId",
table: "ScheduleEntries",
column: "ClassroomId",
principalTable: "Classrooms",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
}
}