presence/data/Migrations/20241120062915_InitialCreate.cs

182 lines
7.6 KiB
C#
Raw Normal View History

2024-11-26 05:09:12 +00:00
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
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)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Subjects",
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_Subjects", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Traffics",
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_Traffics", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
LastName = table.Column<string>(type: "text", nullable: false),
FirstName = table.Column<string>(type: "text", nullable: false),
Patronymic = table.Column<string>(type: "text", 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: "StudentGroupsSubjects",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GroupId = table.Column<int>(type: "integer", nullable: false),
SemesterStart = table.Column<int>(type: "integer", nullable: false),
SemesterEnd = table.Column<int>(type: "integer", nullable: false),
SubjectId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StudentGroupsSubjects", x => x.Id);
table.ForeignKey(
name: "FK_StudentGroupsSubjects_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StudentGroupsSubjects_Subjects_SubjectId",
column: x => x.SubjectId,
principalTable: "Subjects",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Diaries",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DiaryText = table.Column<string>(type: "text", nullable: false),
TrafficId = table.Column<int>(type: "integer", nullable: false),
StudentGroupSubjectId = table.Column<int>(type: "integer", nullable: false),
NumberSubject = table.Column<int>(type: "integer", nullable: false),
Date = table.Column<DateOnly>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Diaries", x => x.Id);
table.ForeignKey(
name: "FK_Diaries_StudentGroupsSubjects_StudentGroupSubjectId",
column: x => x.StudentGroupSubjectId,
principalTable: "StudentGroupsSubjects",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Diaries_Traffics_TrafficId",
column: x => x.TrafficId,
principalTable: "Traffics",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Diaries_StudentGroupSubjectId",
table: "Diaries",
column: "StudentGroupSubjectId");
migrationBuilder.CreateIndex(
name: "IX_Diaries_TrafficId",
table: "Diaries",
column: "TrafficId");
migrationBuilder.CreateIndex(
name: "IX_StudentGroupsSubjects_GroupId",
table: "StudentGroupsSubjects",
column: "GroupId");
migrationBuilder.CreateIndex(
name: "IX_StudentGroupsSubjects_SubjectId",
table: "StudentGroupsSubjects",
column: "SubjectId");
migrationBuilder.CreateIndex(
name: "IX_Students_GroupId",
table: "Students",
column: "GroupId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Diaries");
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "StudentGroupsSubjects");
migrationBuilder.DropTable(
name: "Traffics");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropTable(
name: "Subjects");
}
}
}