using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace UniversityDatabaseImplement.Migrations { /// public partial class InitDb : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Login = table.Column(type: "nvarchar(max)", nullable: false), Password = table.Column(type: "nvarchar(max)", nullable: false), Email = table.Column(type: "nvarchar(max)", nullable: false), Role = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "PlanOfStudys", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), Profile = table.Column(type: "nvarchar(max)", nullable: false), FormOfStudy = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PlanOfStudys", x => x.Id); table.ForeignKey( name: "FK_PlanOfStudys_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Teachers", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), AcademicDegree = table.Column(type: "nvarchar(max)", nullable: false), Position = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Teachers", x => x.Id); table.ForeignKey( name: "FK_Teachers_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Students", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), PlanOfStudyId = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Students", x => x.Id); table.ForeignKey( name: "FK_Students_PlanOfStudys_PlanOfStudyId", column: x => x.PlanOfStudyId, principalTable: "PlanOfStudys", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Students_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.NoAction); }); migrationBuilder.CreateTable( name: "Disciplines", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), TeacherId = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Disciplines", x => x.Id); table.ForeignKey( name: "FK_Disciplines_Teachers_TeacherId", column: x => x.TeacherId, principalTable: "Teachers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Disciplines_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.NoAction); }); migrationBuilder.CreateTable( name: "PlanOfStudyTeachers", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), PlanOfStudyId = table.Column(type: "int", nullable: false), TeacherId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PlanOfStudyTeachers", x => x.Id); table.ForeignKey( name: "FK_PlanOfStudyTeachers_PlanOfStudys_PlanOfStudyId", column: x => x.PlanOfStudyId, principalTable: "PlanOfStudys", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PlanOfStudyTeachers_Teachers_TeacherId", column: x => x.TeacherId, principalTable: "Teachers", principalColumn: "Id", onDelete: ReferentialAction.NoAction); }); migrationBuilder.CreateTable( name: "Statements", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), TeacherId = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), Date = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Statements", x => x.Id); table.ForeignKey( name: "FK_Statements_Teachers_TeacherId", column: x => x.TeacherId, principalTable: "Teachers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Statements_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.NoAction); }); migrationBuilder.CreateTable( name: "Attestations", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "int", nullable: false), StudentId = table.Column(type: "int", nullable: false), FormOfEvaluation = table.Column(type: "nvarchar(max)", nullable: false), Score = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Attestations", x => x.Id); table.ForeignKey( name: "FK_Attestations_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Attestations_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.NoAction); }); migrationBuilder.CreateTable( name: "StudentDisciplines", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), StudentId = table.Column(type: "int", nullable: false), DisciplineId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_StudentDisciplines", x => x.Id); table.ForeignKey( name: "FK_StudentDisciplines_Disciplines_DisciplineId", column: x => x.DisciplineId, principalTable: "Disciplines", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_StudentDisciplines_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "Id", onDelete: ReferentialAction.NoAction); }); migrationBuilder.CreateIndex( name: "IX_Attestations_StudentId", table: "Attestations", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_Attestations_UserId", table: "Attestations", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Disciplines_TeacherId", table: "Disciplines", column: "TeacherId"); migrationBuilder.CreateIndex( name: "IX_Disciplines_UserId", table: "Disciplines", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_PlanOfStudys_UserId", table: "PlanOfStudys", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_PlanOfStudyTeachers_PlanOfStudyId", table: "PlanOfStudyTeachers", column: "PlanOfStudyId"); migrationBuilder.CreateIndex( name: "IX_PlanOfStudyTeachers_TeacherId", table: "PlanOfStudyTeachers", column: "TeacherId"); migrationBuilder.CreateIndex( name: "IX_Statements_TeacherId", table: "Statements", column: "TeacherId"); migrationBuilder.CreateIndex( name: "IX_Statements_UserId", table: "Statements", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_StudentDisciplines_DisciplineId", table: "StudentDisciplines", column: "DisciplineId"); migrationBuilder.CreateIndex( name: "IX_StudentDisciplines_StudentId", table: "StudentDisciplines", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_Students_PlanOfStudyId", table: "Students", column: "PlanOfStudyId"); migrationBuilder.CreateIndex( name: "IX_Students_UserId", table: "Students", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Teachers_UserId", table: "Teachers", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Attestations"); migrationBuilder.DropTable( name: "PlanOfStudyTeachers"); migrationBuilder.DropTable( name: "Statements"); migrationBuilder.DropTable( name: "StudentDisciplines"); migrationBuilder.DropTable( name: "Disciplines"); migrationBuilder.DropTable( name: "Students"); migrationBuilder.DropTable( name: "Teachers"); migrationBuilder.DropTable( name: "PlanOfStudys"); migrationBuilder.DropTable( name: "Users"); } } }