SUBD_SchoolSchedule/SchoolSchedule/SchoolScheduleDataBaseImplement/Migrations/20240408165811_InitialCreate.cs
2024-04-08 22:02:19 +04:00

231 lines
9.2 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SchoolScheduleDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "SchedulePlaces",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Time = table.Column<TimeOnly>(type: "time", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SchedulePlaces", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Subjects",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SubjectName = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Subjects", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Teachers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FullName = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Teachers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Grades",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Year = table.Column<int>(type: "int", nullable: false),
Letter = table.Column<string>(type: "nvarchar(1)", nullable: false),
TeacherId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Grades", x => x.Id);
table.ForeignKey(
name: "FK_Grades_Teachers_TeacherId",
column: x => x.TeacherId,
principalTable: "Teachers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Lessons",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Date = table.Column<DateOnly>(type: "date", nullable: false),
Homework = table.Column<string>(type: "nvarchar(max)", nullable: false),
SchedulePlaceId = table.Column<int>(type: "int", nullable: false),
TeacherId = table.Column<int>(type: "int", nullable: false),
SubjectId = table.Column<int>(type: "int", nullable: false),
GradeId = table.Column<int>(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.Cascade);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FullName = table.Column<string>(type: "nvarchar(max)", nullable: false),
GradeId = table.Column<int>(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: "LessonStudents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
StudentId = table.Column<int>(type: "int", nullable: false),
LessonId = table.Column<int>(type: "int", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
Mark = table.Column<int>(type: "int", nullable: true)
},
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_Grades_TeacherId",
table: "Grades",
column: "TeacherId");
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");
}
/// <inheritdoc />
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: "Grades");
migrationBuilder.DropTable(
name: "Teachers");
}
}
}