Files
CourseWork_GradeBook_Backend/GradeBookServer.Infrastructure/Migrations/20250525163835_AllBD.cs

286 lines
12 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GradeBookServer.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AllBD : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Disciplines",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
TotalHours = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Disciplines", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Faculties",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Faculties", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
Password = table.Column<string>(type: "text", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Directions",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
FacultyID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Directions", x => x.ID);
table.ForeignKey(
name: "FK_Directions_Faculties_FacultyID",
column: x => x.FacultyID,
principalTable: "Faculties",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "DirectionDiscipline",
columns: table => new
{
DirectionsID = table.Column<int>(type: "integer", nullable: false),
DisciplinesID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DirectionDiscipline", x => new { x.DirectionsID, x.DisciplinesID });
table.ForeignKey(
name: "FK_DirectionDiscipline_Directions_DirectionsID",
column: x => x.DirectionsID,
principalTable: "Directions",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DirectionDiscipline_Disciplines_DisciplinesID",
column: x => x.DisciplinesID,
principalTable: "Disciplines",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
DirectionID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.ID);
table.ForeignKey(
name: "FK_Groups_Directions_DirectionID",
column: x => x.DirectionID,
principalTable: "Directions",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FullName = table.Column<string>(type: "text", nullable: false),
Age = table.Column<int>(type: "integer", nullable: false),
GroupID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.ID);
table.ForeignKey(
name: "FK_Students_Groups_GroupID",
column: x => x.GroupID,
principalTable: "Groups",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Vedomosti",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ExamType = table.Column<int>(type: "integer", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
AcademicYear = table.Column<DateOnly>(type: "date", nullable: false),
Semester = table.Column<int>(type: "integer", nullable: false),
Hours = table.Column<int>(type: "integer", nullable: false),
GroupID = table.Column<int>(type: "integer", nullable: false),
DisciplineID = table.Column<int>(type: "integer", nullable: false),
ProfessorID = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Vedomosti", x => x.ID);
table.ForeignKey(
name: "FK_Vedomosti_Disciplines_DisciplineID",
column: x => x.DisciplineID,
principalTable: "Disciplines",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Vedomosti_Groups_GroupID",
column: x => x.GroupID,
principalTable: "Groups",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Vedomosti_Users_ProfessorID",
column: x => x.ProfessorID,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Grades",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StudentID = table.Column<int>(type: "integer", nullable: false),
VedomostID = table.Column<int>(type: "integer", nullable: false),
GradeValue = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Grades", x => x.ID);
table.ForeignKey(
name: "FK_Grades_Students_StudentID",
column: x => x.StudentID,
principalTable: "Students",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Grades_Vedomosti_VedomostID",
column: x => x.VedomostID,
principalTable: "Vedomosti",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DirectionDiscipline_DisciplinesID",
table: "DirectionDiscipline",
column: "DisciplinesID");
migrationBuilder.CreateIndex(
name: "IX_Directions_FacultyID",
table: "Directions",
column: "FacultyID");
migrationBuilder.CreateIndex(
name: "IX_Grades_StudentID",
table: "Grades",
column: "StudentID");
migrationBuilder.CreateIndex(
name: "IX_Grades_VedomostID",
table: "Grades",
column: "VedomostID");
migrationBuilder.CreateIndex(
name: "IX_Groups_DirectionID",
table: "Groups",
column: "DirectionID");
migrationBuilder.CreateIndex(
name: "IX_Students_GroupID",
table: "Students",
column: "GroupID");
migrationBuilder.CreateIndex(
name: "IX_Vedomosti_DisciplineID",
table: "Vedomosti",
column: "DisciplineID");
migrationBuilder.CreateIndex(
name: "IX_Vedomosti_GroupID",
table: "Vedomosti",
column: "GroupID");
migrationBuilder.CreateIndex(
name: "IX_Vedomosti_ProfessorID",
table: "Vedomosti",
column: "ProfessorID");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DirectionDiscipline");
migrationBuilder.DropTable(
name: "Grades");
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "Vedomosti");
migrationBuilder.DropTable(
name: "Disciplines");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Directions");
migrationBuilder.DropTable(
name: "Faculties");
}
}
}