using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional namespace iknow_api.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "ActiveSemesters", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Year = table.Column(type: "integer", nullable: false), Type = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ActiveSemesters", x => x.Id); }); migrationBuilder.CreateTable( name: "Documents", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: true), Body = table.Column(type: "text", nullable: true), Cost = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Documents", x => x.Id); }); migrationBuilder.CreateTable( name: "Majors", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Majors", 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: true), Code = table.Column(type: "text", nullable: true), AwardedCredits = table.Column(type: "integer", nullable: true), DependencyCredit = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Subjects", x => x.Id); }); migrationBuilder.CreateTable( name: "User", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: true), EMBG = table.Column(type: "text", nullable: true), Surname = table.Column(type: "text", nullable: true), Index = table.Column(type: "text", nullable: true), Email = table.Column(type: "text", nullable: true), PasswordHash = table.Column(type: "text", nullable: true), MiddleName = table.Column(type: "text", nullable: true), Gender = table.Column(type: "text", nullable: true), Nationality = table.Column(type: "text", nullable: true), Citizenship = table.Column(type: "text", nullable: true), Bday = table.Column(type: "timestamp with time zone", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), Role = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_User", x => x.Id); }); migrationBuilder.CreateTable( name: "DependencySubjects", columns: table => new { SubjectId = table.Column(type: "integer", nullable: false), DependencyId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DependencySubjects", x => new { x.SubjectId, x.DependencyId }); table.ForeignKey( name: "FK_DependencySubjects_Subjects_DependencyId", column: x => x.DependencyId, principalTable: "Subjects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_DependencySubjects_Subjects_SubjectId", column: x => x.SubjectId, principalTable: "Subjects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "MajorSubjects", columns: table => new { MajorId = table.Column(type: "integer", nullable: false), SubjectId = table.Column(type: "integer", nullable: false), MandatorySemester = table.Column(type: "integer", nullable: false), Accreditation = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MajorSubjects", x => new { x.MajorId, x.SubjectId }); table.ForeignKey( name: "FK_MajorSubjects_Majors_MajorId", column: x => x.MajorId, principalTable: "Majors", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_MajorSubjects_Subjects_SubjectId", column: x => x.SubjectId, principalTable: "Subjects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ContactInfo", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), City = table.Column(type: "text", nullable: true), Address = table.Column(type: "text", nullable: true), Municipality = table.Column(type: "text", nullable: true), PhoneNumber = table.Column(type: "text", nullable: true), MicrosoftEmail = table.Column(type: "text", nullable: true), UserId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ContactInfo", x => x.Id); table.ForeignKey( name: "FK_ContactInfo_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "EnrolledSemesters", columns: table => new { Id = table.Column(type: "integer", nullable: false), UserId = table.Column(type: "integer", nullable: false), QuotaType = table.Column(type: "integer", nullable: false), MajorId = table.Column(type: "integer", nullable: false), StudentComment = table.Column(type: "text", nullable: true), Note = table.Column(type: "text", nullable: true), CratedAt = table.Column(type: "timestamp with time zone", nullable: false), LastChange = table.Column(type: "timestamp with time zone", nullable: false), Verified = table.Column(type: "timestamp with time zone", nullable: false), SemesterId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_EnrolledSemesters", x => x.Id); table.ForeignKey( name: "FK_EnrolledSemesters_ActiveSemesters_Id", column: x => x.Id, principalTable: "ActiveSemesters", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_EnrolledSemesters_Majors_MajorId", column: x => x.MajorId, principalTable: "Majors", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_EnrolledSemesters_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "EnrollmentInfo", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), EnrollmentYear = table.Column(type: "integer", nullable: false), Quota = table.Column(type: "integer", nullable: false), MajorId = table.Column(type: "integer", nullable: false), UserId = table.Column(type: "integer", nullable: false), StudyType = table.Column(type: "text", nullable: true), StudyStatus = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_EnrollmentInfo", x => x.Id); table.ForeignKey( name: "FK_EnrollmentInfo_Majors_MajorId", column: x => x.MajorId, principalTable: "Majors", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_EnrollmentInfo_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "HighSchool", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), GPA = table.Column(type: "real", nullable: false), HighSchoolType = table.Column(type: "integer", nullable: false), UserId = table.Column(type: "integer", nullable: false), StudyLanguage = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_HighSchool", x => x.Id); table.ForeignKey( name: "FK_HighSchool_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ProfessorSubjects", columns: table => new { ProfessorId = table.Column(type: "integer", nullable: false), SemesterId = table.Column(type: "integer", nullable: false), SubjectId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ProfessorSubjects", x => new { x.ProfessorId, x.SemesterId, x.SubjectId }); table.ForeignKey( name: "FK_ProfessorSubjects_ActiveSemesters_SemesterId", column: x => x.SemesterId, principalTable: "ActiveSemesters", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ProfessorSubjects_Subjects_SubjectId", column: x => x.SubjectId, principalTable: "Subjects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ProfessorSubjects_User_ProfessorId", column: x => x.ProfessorId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RefreshToken", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), Token = table.Column(type: "text", nullable: true), ExpiresAt = table.Column(type: "timestamp with time zone", nullable: false), IsValid = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_RefreshToken", x => x.Id); table.ForeignKey( name: "FK_RefreshToken_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserDocuments", columns: table => new { UserId = table.Column(type: "integer", nullable: false), DocumentId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserDocuments", x => new { x.UserId, x.DocumentId }); table.ForeignKey( name: "FK_UserDocuments_Documents_DocumentId", column: x => x.DocumentId, principalTable: "Documents", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserDocuments_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Payments", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), EnrollmentInfoId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Payments", x => x.Id); table.ForeignKey( name: "FK_Payments_EnrolledSemesters_EnrollmentInfoId", column: x => x.EnrollmentInfoId, principalTable: "EnrolledSemesters", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Payments_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "SemesterSubjects", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), EnrolledSemesterId = table.Column(type: "integer", nullable: false), SubjectId = table.Column(type: "integer", nullable: false), ProfessorId = table.Column(type: "integer", nullable: false), Signature = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SemesterSubjects", x => x.Id); table.ForeignKey( name: "FK_SemesterSubjects_EnrolledSemesters_EnrolledSemesterId", column: x => x.EnrolledSemesterId, principalTable: "EnrolledSemesters", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SemesterSubjects_Subjects_SubjectId", column: x => x.SubjectId, principalTable: "Subjects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SemesterSubjects_User_ProfessorId", column: x => x.ProfessorId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SemesterSubjects_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "PassedSubjects", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), SemesterSubjectId = table.Column(type: "integer", nullable: false), Grade = table.Column(type: "integer", nullable: false), DatePassed = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PassedSubjects", x => x.Id); table.ForeignKey( name: "FK_PassedSubjects_SemesterSubjects_SemesterSubjectId", column: x => x.SemesterSubjectId, principalTable: "SemesterSubjects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.InsertData( table: "Majors", columns: new[] { "Id", "Name" }, values: new object[,] { { 1, "PIT" }, { 2, "SIIS" }, { 3, "SEIS" }, { 4, "KN" } }); migrationBuilder.CreateIndex( name: "IX_ContactInfo_UserId", table: "ContactInfo", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_DependencySubjects_DependencyId", table: "DependencySubjects", column: "DependencyId"); migrationBuilder.CreateIndex( name: "IX_EnrolledSemesters_MajorId", table: "EnrolledSemesters", column: "MajorId"); migrationBuilder.CreateIndex( name: "IX_EnrolledSemesters_UserId", table: "EnrolledSemesters", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_EnrollmentInfo_MajorId", table: "EnrollmentInfo", column: "MajorId"); migrationBuilder.CreateIndex( name: "IX_EnrollmentInfo_UserId", table: "EnrollmentInfo", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_HighSchool_UserId", table: "HighSchool", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_MajorSubjects_SubjectId", table: "MajorSubjects", column: "SubjectId"); migrationBuilder.CreateIndex( name: "IX_PassedSubjects_SemesterSubjectId", table: "PassedSubjects", column: "SemesterSubjectId", unique: true); migrationBuilder.CreateIndex( name: "IX_Payments_EnrollmentInfoId", table: "Payments", column: "EnrollmentInfoId"); migrationBuilder.CreateIndex( name: "IX_Payments_UserId", table: "Payments", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_ProfessorSubjects_SemesterId", table: "ProfessorSubjects", column: "SemesterId"); migrationBuilder.CreateIndex( name: "IX_ProfessorSubjects_SubjectId", table: "ProfessorSubjects", column: "SubjectId"); migrationBuilder.CreateIndex( name: "IX_RefreshToken_UserId", table: "RefreshToken", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_SemesterSubjects_EnrolledSemesterId", table: "SemesterSubjects", column: "EnrolledSemesterId"); migrationBuilder.CreateIndex( name: "IX_SemesterSubjects_ProfessorId", table: "SemesterSubjects", column: "ProfessorId"); migrationBuilder.CreateIndex( name: "IX_SemesterSubjects_SubjectId", table: "SemesterSubjects", column: "SubjectId"); migrationBuilder.CreateIndex( name: "IX_SemesterSubjects_UserId", table: "SemesterSubjects", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UserDocuments_DocumentId", table: "UserDocuments", column: "DocumentId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ContactInfo"); migrationBuilder.DropTable( name: "DependencySubjects"); migrationBuilder.DropTable( name: "EnrollmentInfo"); migrationBuilder.DropTable( name: "HighSchool"); migrationBuilder.DropTable( name: "MajorSubjects"); migrationBuilder.DropTable( name: "PassedSubjects"); migrationBuilder.DropTable( name: "Payments"); migrationBuilder.DropTable( name: "ProfessorSubjects"); migrationBuilder.DropTable( name: "RefreshToken"); migrationBuilder.DropTable( name: "UserDocuments"); migrationBuilder.DropTable( name: "SemesterSubjects"); migrationBuilder.DropTable( name: "Documents"); migrationBuilder.DropTable( name: "EnrolledSemesters"); migrationBuilder.DropTable( name: "Subjects"); migrationBuilder.DropTable( name: "ActiveSemesters"); migrationBuilder.DropTable( name: "Majors"); migrationBuilder.DropTable( name: "User"); } } }