using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql { /// public partial class ExperimentGradeManagement : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "SourceSnapshotAt", table: "GradeItems", type: "datetime(6)", nullable: true); migrationBuilder.AddColumn( name: "SourceType", table: "GradeItems", type: "int", nullable: false, defaultValue: 1); migrationBuilder.CreateTable( name: "ExperimentGradeSheets", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), ExperimentProjectId = table.Column(type: "char(36)", nullable: false), ContributionWeight = table.Column(type: "decimal(5,1)", precision: 5, scale: 1, nullable: false), PassScore = table.Column(type: "decimal(5,1)", precision: 5, scale: 1, nullable: false), Status = table.Column(type: "int", nullable: false), ReviewComment = table.Column(type: "varchar(500)", maxLength: 500, nullable: true), SubmittedAt = table.Column(type: "datetime(6)", nullable: true), ReviewedAt = table.Column(type: "datetime(6)", nullable: true), PublishedAt = table.Column(type: "datetime(6)", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ExperimentGradeSheets", x => x.Id); table.ForeignKey( name: "FK_ExperimentGradeSheets_ExperimentProjects_ExperimentProjectId", column: x => x.ExperimentProjectId, principalTable: "ExperimentProjects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "ExperimentGradeItems", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), ExperimentGradeSheetId = table.Column(type: "char(36)", nullable: false), Name = table.Column(type: "varchar(60)", maxLength: 60, nullable: false), Kind = table.Column(type: "int", nullable: false), Weight = table.Column(type: "decimal(5,1)", precision: 5, scale: 1, nullable: false), SortOrder = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ExperimentGradeItems", x => x.Id); table.ForeignKey( name: "FK_ExperimentGradeItems_ExperimentGradeSheets_ExperimentGradeSh~", column: x => x.ExperimentGradeSheetId, principalTable: "ExperimentGradeSheets", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "ExperimentGradeRecords", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), ExperimentGradeSheetId = table.Column(type: "char(36)", nullable: false), StudentId = table.Column(type: "char(36)", nullable: false), ExperimentSessionId = table.Column(type: "char(36)", nullable: true), ParticipationStatus = table.Column(type: "int", nullable: false), TotalScore = table.Column(type: "decimal(5,1)", precision: 5, scale: 1, nullable: true), IsPassed = table.Column(type: "tinyint(1)", nullable: true), SafetyViolation = table.Column(type: "tinyint(1)", nullable: false), AttemptNumber = table.Column(type: "int", nullable: false), SubmissionReference = table.Column(type: "varchar(500)", maxLength: 500, nullable: true), SubmittedAt = table.Column(type: "datetime(6)", nullable: true), IsLate = table.Column(type: "tinyint(1)", nullable: false), TeacherComment = table.Column(type: "varchar(500)", maxLength: 500, nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ExperimentGradeRecords", x => x.Id); table.ForeignKey( name: "FK_ExperimentGradeRecords_ExperimentGradeSheets_ExperimentGrade~", column: x => x.ExperimentGradeSheetId, principalTable: "ExperimentGradeSheets", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ExperimentGradeRecords_ExperimentSessions_ExperimentSessionId", column: x => x.ExperimentSessionId, principalTable: "ExperimentSessions", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_ExperimentGradeRecords_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "ExperimentGradeItemScores", columns: table => new { ExperimentGradeRecordId = table.Column(type: "char(36)", nullable: false), ExperimentGradeItemId = table.Column(type: "char(36)", nullable: false), Score = table.Column(type: "decimal(5,1)", precision: 5, scale: 1, nullable: true), Comment = table.Column(type: "varchar(300)", maxLength: 300, nullable: true) }, constraints: table => { table.PrimaryKey("PK_ExperimentGradeItemScores", x => new { x.ExperimentGradeRecordId, x.ExperimentGradeItemId }); table.ForeignKey( name: "FK_ExperimentGradeItemScores_ExperimentGradeItems_ExperimentGra~", column: x => x.ExperimentGradeItemId, principalTable: "ExperimentGradeItems", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ExperimentGradeItemScores_ExperimentGradeRecords_ExperimentG~", column: x => x.ExperimentGradeRecordId, principalTable: "ExperimentGradeRecords", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_ExperimentGradeItems_ExperimentGradeSheetId_SortOrder", table: "ExperimentGradeItems", columns: new[] { "ExperimentGradeSheetId", "SortOrder" }); migrationBuilder.CreateIndex( name: "IX_ExperimentGradeItemScores_ExperimentGradeItemId", table: "ExperimentGradeItemScores", column: "ExperimentGradeItemId"); migrationBuilder.CreateIndex( name: "IX_ExperimentGradeRecords_ExperimentGradeSheetId_StudentId", table: "ExperimentGradeRecords", columns: new[] { "ExperimentGradeSheetId", "StudentId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_ExperimentGradeRecords_ExperimentSessionId", table: "ExperimentGradeRecords", column: "ExperimentSessionId"); migrationBuilder.CreateIndex( name: "IX_ExperimentGradeRecords_StudentId", table: "ExperimentGradeRecords", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_ExperimentGradeSheets_ExperimentProjectId", table: "ExperimentGradeSheets", column: "ExperimentProjectId", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ExperimentGradeItemScores"); migrationBuilder.DropTable( name: "ExperimentGradeItems"); migrationBuilder.DropTable( name: "ExperimentGradeRecords"); migrationBuilder.DropTable( name: "ExperimentGradeSheets"); migrationBuilder.DropColumn( name: "SourceSnapshotAt", table: "GradeItems"); migrationBuilder.DropColumn( name: "SourceType", table: "GradeItems"); } } }