PIbd-21_Pyatakov_KM_Markov_.../UniversityDataBaseImplemet/Migrations/20230520061807_init.cs

390 lines
17 KiB
C#
Raw Normal View History

2023-06-21 21:38:05 +04:00
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace UniversityDataBaseImplemet.Migrations
{
/// <inheritdoc />
public partial class init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Login = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Documents",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Documents", x => x.Id);
table.ForeignKey(
name: "FK_Documents_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "EducationGroups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
NumberOfStudent = table.Column<int>(type: "integer", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EducationGroups", x => x.Id);
table.ForeignKey(
name: "FK_EducationGroups_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "EducationStatuses",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EducationStatuses", x => x.Id);
table.ForeignKey(
name: "FK_EducationStatuses_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Streams",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Course = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Streams", x => x.Id);
table.ForeignKey(
name: "FK_Streams_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "EducationGroupsDocuments",
columns: table => new
{
EducationGroupId = table.Column<int>(type: "integer", nullable: false),
DocumentId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EducationGroupsDocuments", x => new { x.EducationGroupId, x.DocumentId });
table.ForeignKey(
name: "FK_EducationGroupsDocuments_Documents_DocumentId",
column: x => x.DocumentId,
principalTable: "Documents",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EducationGroupsDocuments_EducationGroups_EducationGroupId",
column: x => x.EducationGroupId,
principalTable: "EducationGroups",
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),
Name = table.Column<string>(type: "text", nullable: false),
Surname = table.Column<string>(type: "text", nullable: false),
DateOfBirth = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateOfAddmission = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
StudentCard = table.Column<int>(type: "integer", nullable: false),
EducationStatusId = table.Column<int>(type: "integer", nullable: true),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.Id);
table.ForeignKey(
name: "FK_Students_EducationStatuses_EducationStatusId",
column: x => x.EducationStatusId,
principalTable: "EducationStatuses",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Students_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Discipline",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
StreamId = table.Column<int>(type: "integer", nullable: false),
Hours = table.Column<int>(type: "integer", nullable: false),
MarkType = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Discipline", x => x.Id);
table.ForeignKey(
name: "FK_Discipline_Streams_StreamId",
column: x => x.StreamId,
principalTable: "Streams",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Discipline_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "EducationGroupsStreams",
columns: table => new
{
EducationGroupId = table.Column<int>(type: "integer", nullable: false),
StreamId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EducationGroupsStreams", x => new { x.EducationGroupId, x.StreamId });
table.ForeignKey(
name: "FK_EducationGroupsStreams_EducationGroups_EducationGroupId",
column: x => x.EducationGroupId,
principalTable: "EducationGroups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EducationGroupsStreams_Streams_StreamId",
column: x => x.StreamId,
principalTable: "Streams",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "EducationGroupViewModel",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
NumberOfStudent = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
StreamId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_EducationGroupViewModel", x => x.Id);
table.ForeignKey(
name: "FK_EducationGroupViewModel_Streams_StreamId",
column: x => x.StreamId,
principalTable: "Streams",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "StudentDocuments",
columns: table => new
{
StudentId = table.Column<int>(type: "integer", nullable: false),
DocumentId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StudentDocuments", x => new { x.StudentId, x.DocumentId });
table.ForeignKey(
name: "FK_StudentDocuments_Documents_DocumentId",
column: x => x.DocumentId,
principalTable: "Documents",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StudentDocuments_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "StudentStreams",
columns: table => new
{
StudentId = table.Column<int>(type: "integer", nullable: false),
StreamId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StudentStreams", x => new { x.StudentId, x.StreamId });
table.ForeignKey(
name: "FK_StudentStreams_Streams_StreamId",
column: x => x.StreamId,
principalTable: "Streams",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StudentStreams_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Discipline_StreamId",
table: "Discipline",
column: "StreamId");
migrationBuilder.CreateIndex(
name: "IX_Discipline_UserId",
table: "Discipline",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Documents_UserId",
table: "Documents",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_EducationGroups_UserId",
table: "EducationGroups",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_EducationGroupsDocuments_DocumentId",
table: "EducationGroupsDocuments",
column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_EducationGroupsStreams_StreamId",
table: "EducationGroupsStreams",
column: "StreamId");
migrationBuilder.CreateIndex(
name: "IX_EducationGroupViewModel_StreamId",
table: "EducationGroupViewModel",
column: "StreamId");
migrationBuilder.CreateIndex(
name: "IX_EducationStatuses_UserId",
table: "EducationStatuses",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Streams_UserId",
table: "Streams",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_StudentDocuments_DocumentId",
table: "StudentDocuments",
column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_Students_EducationStatusId",
table: "Students",
column: "EducationStatusId");
migrationBuilder.CreateIndex(
name: "IX_Students_UserId",
table: "Students",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_StudentStreams_StreamId",
table: "StudentStreams",
column: "StreamId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Discipline");
migrationBuilder.DropTable(
name: "EducationGroupsDocuments");
migrationBuilder.DropTable(
name: "EducationGroupsStreams");
migrationBuilder.DropTable(
name: "EducationGroupViewModel");
migrationBuilder.DropTable(
name: "StudentDocuments");
migrationBuilder.DropTable(
name: "StudentStreams");
migrationBuilder.DropTable(
name: "EducationGroups");
migrationBuilder.DropTable(
name: "Documents");
migrationBuilder.DropTable(
name: "Streams");
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "EducationStatuses");
migrationBuilder.DropTable(
name: "User");
}
}
}