using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace SchoolScheduleDataBaseImplement.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Grades", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Year = table.Column(type: "int", nullable: false), Letter = table.Column(type: "nvarchar(1)", nullable: false), TeacherId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Grades", x => x.Id); }); migrationBuilder.CreateTable( name: "SchedulePlaces", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Time = table.Column(type: "time", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SchedulePlaces", x => x.Id); }); migrationBuilder.CreateTable( name: "Subjects", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), SubjectName = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Subjects", x => x.Id); }); migrationBuilder.CreateTable( name: "Students", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), FullName = table.Column(type: "nvarchar(max)", nullable: false), GradeId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Students", x => x.Id); table.ForeignKey( name: "FK_Students_Grades_GradeId", column: x => x.GradeId, principalTable: "Grades", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Teachers", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), FullName = table.Column(type: "nvarchar(max)", nullable: false), TeacherId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Teachers", x => x.Id); table.ForeignKey( name: "FK_Teachers_Grades_TeacherId", column: x => x.TeacherId, principalTable: "Grades", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Lessons", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Date = table.Column(type: "date", nullable: false), Homework = table.Column(type: "nvarchar(max)", nullable: false), SchedulePlaceId = table.Column(type: "int", nullable: false), TeacherId = table.Column(type: "int", nullable: false), SubjectId = table.Column(type: "int", nullable: false), GradeId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Lessons", x => x.Id); table.ForeignKey( name: "FK_Lessons_Grades_GradeId", column: x => x.GradeId, principalTable: "Grades", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Lessons_SchedulePlaces_SchedulePlaceId", column: x => x.SchedulePlaceId, principalTable: "SchedulePlaces", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Lessons_Subjects_SubjectId", column: x => x.SubjectId, principalTable: "Subjects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Lessons_Teachers_TeacherId", column: x => x.TeacherId, principalTable: "Teachers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "LessonStudents", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), StudentId = table.Column(type: "int", nullable: false), LessonId = table.Column(type: "int", nullable: false), Status = table.Column(type: "int", nullable: false), Mark = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_LessonStudents", x => x.Id); table.ForeignKey( name: "FK_LessonStudents_Lessons_LessonId", column: x => x.LessonId, principalTable: "Lessons", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_LessonStudents_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Lessons_GradeId", table: "Lessons", column: "GradeId"); migrationBuilder.CreateIndex( name: "IX_Lessons_SchedulePlaceId", table: "Lessons", column: "SchedulePlaceId"); migrationBuilder.CreateIndex( name: "IX_Lessons_SubjectId", table: "Lessons", column: "SubjectId"); migrationBuilder.CreateIndex( name: "IX_Lessons_TeacherId", table: "Lessons", column: "TeacherId"); migrationBuilder.CreateIndex( name: "IX_LessonStudents_LessonId", table: "LessonStudents", column: "LessonId"); migrationBuilder.CreateIndex( name: "IX_LessonStudents_StudentId", table: "LessonStudents", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_Students_GradeId", table: "Students", column: "GradeId"); migrationBuilder.CreateIndex( name: "IX_Teachers_TeacherId", table: "Teachers", column: "TeacherId", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "LessonStudents"); migrationBuilder.DropTable( name: "Lessons"); migrationBuilder.DropTable( name: "Students"); migrationBuilder.DropTable( name: "SchedulePlaces"); migrationBuilder.DropTable( name: "Subjects"); migrationBuilder.DropTable( name: "Teachers"); migrationBuilder.DropTable( name: "Grades"); } } }