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: "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: "Traffics", 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_Traffics", x => x.Id); }); migrationBuilder.CreateTable( name: "Students", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), LastName = table.Column(type: "text", nullable: false), FirstName = 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.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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), GroupId = table.Column(type: "integer", nullable: false), SemesterStart = table.Column(type: "integer", nullable: false), SemesterEnd = table.Column(type: "integer", nullable: false), SubjectId = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), DiaryText = table.Column(type: "text", nullable: false), TrafficId = table.Column(type: "integer", nullable: false), StudentGroupSubjectId = table.Column(type: "integer", nullable: false), NumberSubject = table.Column(type: "integer", nullable: false), Date = table.Column(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"); } /// 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"); } } }