using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class ProductionSchemaCompletion : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ExamSessions_Classrooms_ClassroomId",
                table: "ExamSessions");

            migrationBuilder.AlterColumn<Guid>(
                name: "ClassroomId",
                table: "ExamSessions",
                type: "char(36)",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "char(36)");

            migrationBuilder.AddColumn<DateOnly>(
                name: "ExamDate",
                table: "ExamSessions",
                type: "date",
                nullable: true);

            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);

            migrationBuilder.AddColumn<int>(
                name: "StartPeriod",
                table: "ExamSessions",
                type: "int",
                nullable: false,
                defaultValue: 1);

            migrationBuilder.AddColumn<int>(
                name: "EnrollmentType",
                table: "CourseEnrollments",
                type: "int",
                nullable: false,
                defaultValue: 1);

            migrationBuilder.CreateTable(
                name: "AttendanceSheets",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "varchar(120)", maxLength: 120, nullable: false),
                    AttendanceDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    Notes = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    SubmittedAt = 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_AttendanceSheets", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AttendanceSheets_TeachingTasks_TeachingTaskId",
                        column: x => x.TeachingTaskId,
                        principalTable: "TeachingTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "CourseAdjustments",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ApplicantUserId = table.Column<Guid>(type: "char(36)", nullable: false),
                    TargetDate = table.Column<DateOnly>(type: "date", nullable: true),
                    DayOfWeek = table.Column<int>(type: "int", nullable: true),
                    StartPeriod = table.Column<int>(type: "int", nullable: true),
                    PeriodCount = table.Column<int>(type: "int", nullable: true),
                    ClassroomId = table.Column<Guid>(type: "char(36)", nullable: true),
                    SubstituteTeacherId = table.Column<Guid>(type: "char(36)", nullable: true),
                    CancelWeek = table.Column<int>(type: "int", nullable: true),
                    CancelDate = table.Column<DateOnly>(type: "date", nullable: true),
                    Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false),
                    ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    SubmittedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ReviewedByUserId = 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_CourseAdjustments", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CourseAdjustments_Classrooms_ClassroomId",
                        column: x => x.ClassroomId,
                        principalTable: "Classrooms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_CourseAdjustments_Teachers_SubstituteTeacherId",
                        column: x => x.SubstituteTeacherId,
                        principalTable: "Teachers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_CourseAdjustments_TeachingTasks_TeachingTaskId",
                        column: x => x.TeachingTaskId,
                        principalTable: "TeachingTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "CourseExemptions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    SubmittedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ReviewedByUserId = 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_CourseExemptions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CourseExemptions_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_CourseExemptions_TeachingTasks_TeachingTaskId",
                        column: x => x.TeachingTaskId,
                        principalTable: "TeachingTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "CourseSubstitutions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    OriginalCourseId = table.Column<Guid>(type: "char(36)", nullable: false),
                    SubstituteCourseId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    SubmittedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ReviewedByUserId = 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_CourseSubstitutions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CourseSubstitutions_Courses_OriginalCourseId",
                        column: x => x.OriginalCourseId,
                        principalTable: "Courses",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_CourseSubstitutions_Courses_SubstituteCourseId",
                        column: x => x.SubstituteCourseId,
                        principalTable: "Courses",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_CourseSubstitutions_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "DeferredExams",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    SubmittedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ReviewedByUserId = 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_DeferredExams", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DeferredExams_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DeferredExams_TeachingTasks_TeachingTaskId",
                        column: x => x.TeachingTaskId,
                        principalTable: "TeachingTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "EvaluationSetups",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    AcademicTermId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "varchar(120)", maxLength: 120, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    StartsAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    EndsAt = 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_EvaluationSetups", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EvaluationSetups_AcademicTerms_AcademicTermId",
                        column: x => x.AcademicTermId,
                        principalTable: "AcademicTerms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "GradeItems",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    GradeSheetId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "varchar(60)", maxLength: 60, nullable: false),
                    Weight = table.Column<decimal>(type: "decimal(5,1)", precision: 5, scale: 1, nullable: false),
                    SortOrder = table.Column<int>(type: "int", 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_GradeItems", x => x.Id);
                    table.ForeignKey(
                        name: "FK_GradeItems_GradeSheets_GradeSheetId",
                        column: x => x.GradeSheetId,
                        principalTable: "GradeSheets",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "GradeModifications",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    GradeRecordId = table.Column<Guid>(type: "char(36)", nullable: false),
                    CurrentScore = table.Column<decimal>(type: "decimal(5,1)", precision: 5, scale: 1, nullable: false),
                    RequestedScore = table.Column<decimal>(type: "decimal(5,1)", precision: 5, scale: 1, nullable: false),
                    Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    ApplicantUserId = table.Column<Guid>(type: "char(36)", nullable: false),
                    SubmittedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CollegeReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    CollegeReviewedByUserId = table.Column<Guid>(type: "char(36)", nullable: true),
                    FinalReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    FinalReviewedByUserId = 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_GradeModifications", x => x.Id);
                    table.ForeignKey(
                        name: "FK_GradeModifications_GradeRecords_GradeRecordId",
                        column: x => x.GradeRecordId,
                        principalTable: "GradeRecords",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MakeupExamPlans",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    AcademicTermId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "varchar(120)", maxLength: 120, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    Notes = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    PublishedAt = 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_MakeupExamPlans", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MakeupExamPlans_AcademicTerms_AcademicTermId",
                        column: x => x.AcademicTermId,
                        principalTable: "AcademicTerms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Notifications",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    UserId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Title = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false),
                    Content = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: false),
                    IsRead = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    LinkUrl = table.Column<string>(type: "varchar(300)", maxLength: 300, 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_Notifications", x => x.Id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "WarningRecords",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    TriggerValue = table.Column<decimal>(type: "decimal(7,2)", precision: 7, scale: 2, nullable: false),
                    Detail = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: false),
                    AcknowledgedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    AcknowledgeComment = table.Column<string>(type: "varchar(300)", maxLength: 300, nullable: true),
                    AcademicTermId = 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_WarningRecords", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WarningRecords_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "WarningRules",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Name = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false),
                    Threshold = table.Column<decimal>(type: "decimal(7,2)", precision: 7, scale: 2, nullable: false),
                    IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    NotifyStudent = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    NotifyCounselor = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    AcademicTermId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Description = table.Column<string>(type: "varchar(300)", maxLength: 300, nullable: true),
                    AutoCheckEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    CheckDayOfWeek = table.Column<int>(type: "int", nullable: true),
                    CheckHour = table.Column<int>(type: "int", nullable: false),
                    CheckMinute = table.Column<int>(type: "int", nullable: false),
                    LastCheckAt = 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_WarningRules", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WarningRules_AcademicTerms_AcademicTermId",
                        column: x => x.AcademicTermId,
                        principalTable: "AcademicTerms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AttendanceRecords",
                columns: table => new
                {
                    AttendanceSheetId = 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),
                    Notes = table.Column<string>(type: "varchar(300)", maxLength: 300, nullable: true),
                    AppealStatus = table.Column<int>(type: "int", nullable: false),
                    AppealReason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    AppealSubmittedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    AppealReviewComment = table.Column<string>(type: "varchar(300)", maxLength: 300, nullable: true),
                    AppealReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AttendanceRecords", x => new { x.AttendanceSheetId, x.StudentId });
                    table.ForeignKey(
                        name: "FK_AttendanceRecords_AttendanceSheets_AttendanceSheetId",
                        column: x => x.AttendanceSheetId,
                        principalTable: "AttendanceSheets",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AttendanceRecords_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "EvaluationDimensions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    EvaluationSetupId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "varchar(60)", maxLength: 60, nullable: false),
                    MaxScore = table.Column<int>(type: "int", nullable: false),
                    SortOrder = table.Column<int>(type: "int", 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_EvaluationDimensions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EvaluationDimensions_EvaluationSetups_EvaluationSetupId",
                        column: x => x.EvaluationSetupId,
                        principalTable: "EvaluationSetups",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "EvaluationRecords",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    EvaluationSetupId = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
                    SubmittedAt = 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_EvaluationRecords", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EvaluationRecords_EvaluationSetups_EvaluationSetupId",
                        column: x => x.EvaluationSetupId,
                        principalTable: "EvaluationSetups",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_EvaluationRecords_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_EvaluationRecords_TeachingTasks_TeachingTaskId",
                        column: x => x.TeachingTaskId,
                        principalTable: "TeachingTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "GradeItemScores",
                columns: table => new
                {
                    GradeRecordId = table.Column<Guid>(type: "char(36)", nullable: false),
                    GradeItemId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Score = table.Column<decimal>(type: "decimal(5,1)", precision: 5, scale: 1, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_GradeItemScores", x => new { x.GradeRecordId, x.GradeItemId });
                    table.ForeignKey(
                        name: "FK_GradeItemScores_GradeItems_GradeItemId",
                        column: x => x.GradeItemId,
                        principalTable: "GradeItems",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_GradeItemScores_GradeRecords_GradeRecordId",
                        column: x => x.GradeRecordId,
                        principalTable: "GradeRecords",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MakeupExamAutoJobs",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    MakeupExamPlanId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    TotalCourses = table.Column<int>(type: "int", nullable: false),
                    ProcessedCourses = table.Column<int>(type: "int", nullable: false),
                    CreatedSessions = table.Column<int>(type: "int", nullable: false),
                    EnrolledStudents = table.Column<int>(type: "int", nullable: false),
                    MessagesJson = table.Column<string>(type: "longtext", nullable: true),
                    ErrorMessage = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: true),
                    StartedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    CompletedAt = 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_MakeupExamAutoJobs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MakeupExamAutoJobs_MakeupExamPlans_MakeupExamPlanId",
                        column: x => x.MakeupExamPlanId,
                        principalTable: "MakeupExamPlans",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MakeupExamSessions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    MakeupExamPlanId = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
                    ClassroomId = table.Column<Guid>(type: "char(36)", nullable: true),
                    ExamDate = table.Column<DateOnly>(type: "date", nullable: false),
                    StartPeriod = table.Column<int>(type: "int", nullable: false),
                    PeriodCount = table.Column<int>(type: "int", nullable: false),
                    StartsAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    EndsAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    RequiredBuildingId = table.Column<Guid>(type: "char(36)", nullable: true),
                    RequiredInvigilatorCount = table.Column<int>(type: "int", nullable: false),
                    Notes = 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_MakeupExamSessions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MakeupExamSessions_Buildings_RequiredBuildingId",
                        column: x => x.RequiredBuildingId,
                        principalTable: "Buildings",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_MakeupExamSessions_Classrooms_ClassroomId",
                        column: x => x.ClassroomId,
                        principalTable: "Classrooms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_MakeupExamSessions_MakeupExamPlans_MakeupExamPlanId",
                        column: x => x.MakeupExamPlanId,
                        principalTable: "MakeupExamPlans",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MakeupExamSessions_TeachingTasks_TeachingTaskId",
                        column: x => x.TeachingTaskId,
                        principalTable: "TeachingTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "EvaluationScores",
                columns: table => new
                {
                    EvaluationRecordId = table.Column<Guid>(type: "char(36)", nullable: false),
                    EvaluationDimensionId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Score = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EvaluationScores", x => new { x.EvaluationRecordId, x.EvaluationDimensionId });
                    table.ForeignKey(
                        name: "FK_EvaluationScores_EvaluationDimensions_EvaluationDimensionId",
                        column: x => x.EvaluationDimensionId,
                        principalTable: "EvaluationDimensions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_EvaluationScores_EvaluationRecords_EvaluationRecordId",
                        column: x => x.EvaluationRecordId,
                        principalTable: "EvaluationRecords",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MakeupExamEnrollments",
                columns: table => new
                {
                    MakeupExamSessionId = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Reason = table.Column<int>(type: "int", nullable: false),
                    SourceGradeRecordId = table.Column<Guid>(type: "char(36)", nullable: true),
                    SourceDeferredExamId = table.Column<Guid>(type: "char(36)", nullable: true),
                    MakeupScore = table.Column<decimal>(type: "decimal(5,1)", precision: 5, scale: 1, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MakeupExamEnrollments", x => new { x.MakeupExamSessionId, x.StudentId });
                    table.ForeignKey(
                        name: "FK_MakeupExamEnrollments_DeferredExams_SourceDeferredExamId",
                        column: x => x.SourceDeferredExamId,
                        principalTable: "DeferredExams",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_MakeupExamEnrollments_GradeRecords_SourceGradeRecordId",
                        column: x => x.SourceGradeRecordId,
                        principalTable: "GradeRecords",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_MakeupExamEnrollments_MakeupExamSessions_MakeupExamSessionId",
                        column: x => x.MakeupExamSessionId,
                        principalTable: "MakeupExamSessions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MakeupExamEnrollments_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MakeupExamSessionInvigilators",
                columns: table => new
                {
                    MakeupExamSessionId = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeacherId = table.Column<Guid>(type: "char(36)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MakeupExamSessionInvigilators", x => new { x.MakeupExamSessionId, x.TeacherId });
                    table.ForeignKey(
                        name: "FK_MakeupExamSessionInvigilators_MakeupExamSessions_MakeupExamS~",
                        column: x => x.MakeupExamSessionId,
                        principalTable: "MakeupExamSessions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MakeupExamSessionInvigilators_Teachers_TeacherId",
                        column: x => x.TeacherId,
                        principalTable: "Teachers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ExamSessions_ExamPlanId_ExamDate",
                table: "ExamSessions",
                columns: new[] { "ExamPlanId", "ExamDate" });

            migrationBuilder.CreateIndex(
                name: "IX_ExamSessions_RequiredBuildingId",
                table: "ExamSessions",
                column: "RequiredBuildingId");

            migrationBuilder.CreateIndex(
                name: "IX_AttendanceRecords_AppealStatus",
                table: "AttendanceRecords",
                column: "AppealStatus");

            migrationBuilder.CreateIndex(
                name: "IX_AttendanceRecords_StudentId",
                table: "AttendanceRecords",
                column: "StudentId");

            migrationBuilder.CreateIndex(
                name: "IX_AttendanceSheets_TeachingTaskId_AttendanceDate",
                table: "AttendanceSheets",
                columns: new[] { "TeachingTaskId", "AttendanceDate" });

            migrationBuilder.CreateIndex(
                name: "IX_CourseAdjustments_ApplicantUserId",
                table: "CourseAdjustments",
                column: "ApplicantUserId");

            migrationBuilder.CreateIndex(
                name: "IX_CourseAdjustments_ClassroomId",
                table: "CourseAdjustments",
                column: "ClassroomId");

            migrationBuilder.CreateIndex(
                name: "IX_CourseAdjustments_Status_CreatedAt",
                table: "CourseAdjustments",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_CourseAdjustments_SubstituteTeacherId",
                table: "CourseAdjustments",
                column: "SubstituteTeacherId");

            migrationBuilder.CreateIndex(
                name: "IX_CourseAdjustments_TeachingTaskId_Status",
                table: "CourseAdjustments",
                columns: new[] { "TeachingTaskId", "Status" });

            migrationBuilder.CreateIndex(
                name: "IX_CourseExemptions_Status_CreatedAt",
                table: "CourseExemptions",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_CourseExemptions_StudentId_TeachingTaskId",
                table: "CourseExemptions",
                columns: new[] { "StudentId", "TeachingTaskId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_CourseExemptions_TeachingTaskId",
                table: "CourseExemptions",
                column: "TeachingTaskId");

            migrationBuilder.CreateIndex(
                name: "IX_CourseSubstitutions_OriginalCourseId",
                table: "CourseSubstitutions",
                column: "OriginalCourseId");

            migrationBuilder.CreateIndex(
                name: "IX_CourseSubstitutions_Status_CreatedAt",
                table: "CourseSubstitutions",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_CourseSubstitutions_StudentId_OriginalCourseId",
                table: "CourseSubstitutions",
                columns: new[] { "StudentId", "OriginalCourseId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_CourseSubstitutions_SubstituteCourseId",
                table: "CourseSubstitutions",
                column: "SubstituteCourseId");

            migrationBuilder.CreateIndex(
                name: "IX_DeferredExams_Status_CreatedAt",
                table: "DeferredExams",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_DeferredExams_StudentId_TeachingTaskId",
                table: "DeferredExams",
                columns: new[] { "StudentId", "TeachingTaskId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DeferredExams_TeachingTaskId",
                table: "DeferredExams",
                column: "TeachingTaskId");

            migrationBuilder.CreateIndex(
                name: "IX_EvaluationDimensions_EvaluationSetupId_SortOrder",
                table: "EvaluationDimensions",
                columns: new[] { "EvaluationSetupId", "SortOrder" });

            migrationBuilder.CreateIndex(
                name: "IX_EvaluationRecords_EvaluationSetupId_StudentId_TeachingTaskId",
                table: "EvaluationRecords",
                columns: new[] { "EvaluationSetupId", "StudentId", "TeachingTaskId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_EvaluationRecords_StudentId",
                table: "EvaluationRecords",
                column: "StudentId");

            migrationBuilder.CreateIndex(
                name: "IX_EvaluationRecords_TeachingTaskId",
                table: "EvaluationRecords",
                column: "TeachingTaskId");

            migrationBuilder.CreateIndex(
                name: "IX_EvaluationScores_EvaluationDimensionId",
                table: "EvaluationScores",
                column: "EvaluationDimensionId");

            migrationBuilder.CreateIndex(
                name: "IX_EvaluationSetups_AcademicTermId_Status",
                table: "EvaluationSetups",
                columns: new[] { "AcademicTermId", "Status" });

            migrationBuilder.CreateIndex(
                name: "IX_GradeItems_GradeSheetId_SortOrder",
                table: "GradeItems",
                columns: new[] { "GradeSheetId", "SortOrder" });

            migrationBuilder.CreateIndex(
                name: "IX_GradeItemScores_GradeItemId",
                table: "GradeItemScores",
                column: "GradeItemId");

            migrationBuilder.CreateIndex(
                name: "IX_GradeModifications_GradeRecordId",
                table: "GradeModifications",
                column: "GradeRecordId");

            migrationBuilder.CreateIndex(
                name: "IX_GradeModifications_Status_CreatedAt",
                table: "GradeModifications",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamAutoJobs_MakeupExamPlanId_CreatedAt",
                table: "MakeupExamAutoJobs",
                columns: new[] { "MakeupExamPlanId", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamAutoJobs_Status_CreatedAt",
                table: "MakeupExamAutoJobs",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamEnrollments_SourceDeferredExamId",
                table: "MakeupExamEnrollments",
                column: "SourceDeferredExamId");

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamEnrollments_SourceGradeRecordId",
                table: "MakeupExamEnrollments",
                column: "SourceGradeRecordId");

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamEnrollments_StudentId_MakeupExamSessionId",
                table: "MakeupExamEnrollments",
                columns: new[] { "StudentId", "MakeupExamSessionId" });

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamPlans_AcademicTermId_Status",
                table: "MakeupExamPlans",
                columns: new[] { "AcademicTermId", "Status" });

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamSessionInvigilators_TeacherId",
                table: "MakeupExamSessionInvigilators",
                column: "TeacherId");

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamSessions_ClassroomId",
                table: "MakeupExamSessions",
                column: "ClassroomId");

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamSessions_MakeupExamPlanId_ExamDate",
                table: "MakeupExamSessions",
                columns: new[] { "MakeupExamPlanId", "ExamDate" });

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamSessions_MakeupExamPlanId_StartsAt",
                table: "MakeupExamSessions",
                columns: new[] { "MakeupExamPlanId", "StartsAt" });

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamSessions_RequiredBuildingId",
                table: "MakeupExamSessions",
                column: "RequiredBuildingId");

            migrationBuilder.CreateIndex(
                name: "IX_MakeupExamSessions_TeachingTaskId",
                table: "MakeupExamSessions",
                column: "TeachingTaskId");

            migrationBuilder.CreateIndex(
                name: "IX_Notifications_CreatedAt",
                table: "Notifications",
                column: "CreatedAt");

            migrationBuilder.CreateIndex(
                name: "IX_Notifications_UserId_IsRead",
                table: "Notifications",
                columns: new[] { "UserId", "IsRead" });

            migrationBuilder.CreateIndex(
                name: "IX_WarningRecords_Status",
                table: "WarningRecords",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_WarningRecords_StudentId_AcademicTermId_Type",
                table: "WarningRecords",
                columns: new[] { "StudentId", "AcademicTermId", "Type" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_WarningRules_AcademicTermId_Type",
                table: "WarningRules",
                columns: new[] { "AcademicTermId", "Type" },
                unique: true);

            migrationBuilder.Sql(
                """
                UPDATE `ExamSessions`
                SET `ExamDate` = DATE(`StartsAt`)
                WHERE `ExamDate` IS NULL;
                """);

            migrationBuilder.AlterColumn<DateOnly>(
                name: "ExamDate",
                table: "ExamSessions",
                type: "date",
                nullable: false,
                oldClrType: typeof(DateOnly),
                oldType: "date",
                oldNullable: true);

            migrationBuilder.Sql(
                """
                INSERT INTO `GradeItems`
                    (`Id`, `GradeSheetId`, `Name`, `Weight`, `SortOrder`, `CreatedAt`, `UpdatedAt`)
                SELECT UUID(), gs.`Id`, '期中成绩', gs.`MidtermWeight`, 10,
                       UTC_TIMESTAMP(6), UTC_TIMESTAMP(6)
                FROM `GradeSheets` AS gs
                WHERE gs.`MidtermWeight` <> 0
                   OR EXISTS (
                       SELECT 1
                       FROM `GradeRecords` AS gr
                       WHERE gr.`GradeSheetId` = gs.`Id`
                         AND gr.`MidtermScore` IS NOT NULL
                   );

                INSERT INTO `GradeItemScores` (`GradeRecordId`, `GradeItemId`, `Score`)
                SELECT gr.`Id`, gi.`Id`, gr.`MidtermScore`
                FROM `GradeRecords` AS gr
                INNER JOIN `GradeItems` AS gi
                    ON gi.`GradeSheetId` = gr.`GradeSheetId`
                   AND gi.`Name` = '期中成绩'
                WHERE gr.`MidtermScore` IS NOT NULL;
                """);

            migrationBuilder.DropColumn(
                name: "MidtermWeight",
                table: "GradeSheets");

            migrationBuilder.DropColumn(
                name: "MidtermScore",
                table: "GradeRecords");

            migrationBuilder.AddForeignKey(
                name: "FK_ExamSessions_Buildings_RequiredBuildingId",
                table: "ExamSessions",
                column: "RequiredBuildingId",
                principalTable: "Buildings",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_ExamSessions_Classrooms_ClassroomId",
                table: "ExamSessions",
                column: "ClassroomId",
                principalTable: "Classrooms",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ExamSessions_Buildings_RequiredBuildingId",
                table: "ExamSessions");

            migrationBuilder.DropForeignKey(
                name: "FK_ExamSessions_Classrooms_ClassroomId",
                table: "ExamSessions");

            migrationBuilder.DropTable(
                name: "AttendanceRecords");

            migrationBuilder.DropTable(
                name: "CourseAdjustments");

            migrationBuilder.DropTable(
                name: "CourseExemptions");

            migrationBuilder.DropTable(
                name: "CourseSubstitutions");

            migrationBuilder.DropTable(
                name: "EvaluationScores");

            migrationBuilder.DropTable(
                name: "GradeItemScores");

            migrationBuilder.DropTable(
                name: "GradeModifications");

            migrationBuilder.DropTable(
                name: "MakeupExamAutoJobs");

            migrationBuilder.DropTable(
                name: "MakeupExamEnrollments");

            migrationBuilder.DropTable(
                name: "MakeupExamSessionInvigilators");

            migrationBuilder.DropTable(
                name: "Notifications");

            migrationBuilder.DropTable(
                name: "WarningRecords");

            migrationBuilder.DropTable(
                name: "WarningRules");

            migrationBuilder.DropTable(
                name: "AttendanceSheets");

            migrationBuilder.DropTable(
                name: "EvaluationDimensions");

            migrationBuilder.DropTable(
                name: "EvaluationRecords");

            migrationBuilder.DropTable(
                name: "GradeItems");

            migrationBuilder.DropTable(
                name: "DeferredExams");

            migrationBuilder.DropTable(
                name: "MakeupExamSessions");

            migrationBuilder.DropTable(
                name: "EvaluationSetups");

            migrationBuilder.DropTable(
                name: "MakeupExamPlans");

            migrationBuilder.DropIndex(
                name: "IX_ExamSessions_ExamPlanId_ExamDate",
                table: "ExamSessions");

            migrationBuilder.DropIndex(
                name: "IX_ExamSessions_RequiredBuildingId",
                table: "ExamSessions");

            migrationBuilder.DropColumn(
                name: "ExamDate",
                table: "ExamSessions");

            migrationBuilder.DropColumn(
                name: "PeriodCount",
                table: "ExamSessions");

            migrationBuilder.DropColumn(
                name: "RequiredBuildingId",
                table: "ExamSessions");

            migrationBuilder.DropColumn(
                name: "RequiredInvigilatorCount",
                table: "ExamSessions");

            migrationBuilder.DropColumn(
                name: "StartPeriod",
                table: "ExamSessions");

            migrationBuilder.DropColumn(
                name: "EnrollmentType",
                table: "CourseEnrollments");

            migrationBuilder.AddColumn<decimal>(
                name: "MidtermWeight",
                table: "GradeSheets",
                type: "decimal(5,1)",
                precision: 5,
                scale: 1,
                nullable: false,
                defaultValue: 0m);

            migrationBuilder.AddColumn<decimal>(
                name: "MidtermScore",
                table: "GradeRecords",
                type: "decimal(5,1)",
                precision: 5,
                scale: 1,
                nullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "ClassroomId",
                table: "ExamSessions",
                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_ExamSessions_Classrooms_ClassroomId",
                table: "ExamSessions",
                column: "ClassroomId",
                principalTable: "Classrooms",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
