using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace data.Migrations { /// public partial class InitialCreate123 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Groups", columns: table => new { GroupId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), GroupName = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Groups", x => x.GroupId); }); migrationBuilder.CreateTable( name: "Semesters", columns: table => new { SemesterId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), StartTime = table.Column(type: "timestamp with time zone", nullable: false), EndTime = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Semesters", x => x.SemesterId); }); migrationBuilder.CreateTable( name: "Visits", columns: table => new { VisitId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), VisitName = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Visits", x => x.VisitId); }); migrationBuilder.CreateTable( name: "Students", columns: table => new { StudentId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), FirstName = table.Column(type: "text", nullable: false), LastName = table.Column(type: "text", nullable: false), Patronymic = table.Column(type: "text", nullable: false), GroupId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Students", x => x.StudentId); table.ForeignKey( name: "FK_Students_Groups_GroupId", column: x => x.GroupId, principalTable: "Groups", principalColumn: "GroupId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Subjects", columns: table => new { SubjectId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), SubjectName = table.Column(type: "text", nullable: false), GroupId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Subjects", x => x.SubjectId); table.ForeignKey( name: "FK_Subjects_Groups_GroupId", column: x => x.GroupId, principalTable: "Groups", principalColumn: "GroupId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "GroupSubjects", columns: table => new { GroupSubjectId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), SemesterId = table.Column(type: "integer", nullable: false), GroupId = table.Column(type: "integer", nullable: false), SubjectId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GroupSubjects", x => x.GroupSubjectId); table.ForeignKey( name: "FK_GroupSubjects_Groups_GroupId", column: x => x.GroupId, principalTable: "Groups", principalColumn: "GroupId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_GroupSubjects_Semesters_SemesterId", column: x => x.SemesterId, principalTable: "Semesters", principalColumn: "SemesterId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_GroupSubjects_Subjects_SubjectId", column: x => x.SubjectId, principalTable: "Subjects", principalColumn: "SubjectId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Attendances", columns: table => new { AttendanceId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Date = table.Column(type: "date", nullable: false), GroupSubjectId = table.Column(type: "integer", nullable: false), StudentId = table.Column(type: "integer", nullable: false), GroupId = table.Column(type: "integer", nullable: false), VisitId = table.Column(type: "integer", nullable: false), LessonNumber = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Attendances", x => x.AttendanceId); table.ForeignKey( name: "FK_Attendances_GroupSubjects_GroupSubjectId", column: x => x.GroupSubjectId, principalTable: "GroupSubjects", principalColumn: "GroupSubjectId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Attendances_Groups_GroupId", column: x => x.GroupId, principalTable: "Groups", principalColumn: "GroupId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Attendances_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "StudentId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Attendances_Visits_VisitId", column: x => x.VisitId, principalTable: "Visits", principalColumn: "VisitId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Attendances_GroupId", table: "Attendances", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_Attendances_GroupSubjectId", table: "Attendances", column: "GroupSubjectId"); migrationBuilder.CreateIndex( name: "IX_Attendances_StudentId", table: "Attendances", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_Attendances_VisitId", table: "Attendances", column: "VisitId"); migrationBuilder.CreateIndex( name: "IX_GroupSubjects_GroupId", table: "GroupSubjects", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_GroupSubjects_SemesterId", table: "GroupSubjects", column: "SemesterId"); migrationBuilder.CreateIndex( name: "IX_GroupSubjects_SubjectId", table: "GroupSubjects", column: "SubjectId"); migrationBuilder.CreateIndex( name: "IX_Students_GroupId", table: "Students", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_Subjects_GroupId", table: "Subjects", column: "GroupId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Attendances"); migrationBuilder.DropTable( name: "GroupSubjects"); migrationBuilder.DropTable( name: "Students"); migrationBuilder.DropTable( name: "Visits"); migrationBuilder.DropTable( name: "Semesters"); migrationBuilder.DropTable( name: "Subjects"); migrationBuilder.DropTable( name: "Groups"); } } }