using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace data.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Groups", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Groups", x => x.Id); }); migrationBuilder.CreateTable( name: "Semesters", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Semesters", x => x.Id); }); migrationBuilder.CreateTable( name: "Subjects", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Subjects", x => x.Id); }); migrationBuilder.CreateTable( name: "Students", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), GroupId = table.Column(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: "Lessons", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), SubjectId = table.Column(type: "integer", nullable: false), SemesterId = table.Column(type: "integer", nullable: false), GroupId = table.Column(type: "integer", nullable: false), Date = table.Column(type: "timestamp with time zone", nullable: false), LessonNumber = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Lessons", x => x.Id); table.ForeignKey( name: "FK_Lessons_Groups_GroupId", column: x => x.GroupId, principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Lessons_Semesters_SemesterId", column: x => x.SemesterId, principalTable: "Semesters", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Lessons_Subjects_SubjectId", column: x => x.SubjectId, principalTable: "Subjects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Attendances", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), StudentId = table.Column(type: "integer", nullable: false), LessonId = table.Column(type: "integer", nullable: false), Status = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Attendances", x => x.Id); table.ForeignKey( name: "FK_Attendances_Lessons_LessonId", column: x => x.LessonId, principalTable: "Lessons", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Attendances_Students_StudentId", column: x => x.StudentId, principalTable: "Students", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Attendances_LessonId", table: "Attendances", column: "LessonId"); migrationBuilder.CreateIndex( name: "IX_Attendances_StudentId", table: "Attendances", column: "StudentId"); migrationBuilder.CreateIndex( name: "IX_Lessons_GroupId", table: "Lessons", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_Lessons_SemesterId", table: "Lessons", column: "SemesterId"); migrationBuilder.CreateIndex( name: "IX_Lessons_SubjectId", table: "Lessons", column: "SubjectId"); migrationBuilder.CreateIndex( name: "IX_Students_GroupId", table: "Students", column: "GroupId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Attendances"); migrationBuilder.DropTable( name: "Lessons"); migrationBuilder.DropTable( name: "Students"); migrationBuilder.DropTable( name: "Semesters"); migrationBuilder.DropTable( name: "Subjects"); migrationBuilder.DropTable( name: "Groups"); } } }