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 InitalCreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
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)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column(type: "integer", nullable: false),
Year = table.Column(type: "integer", nullable: false),
Type = table.Column(type: "integer", nullable: false),
QuotaType = table.Column(type: "integer", nullable: false),
MajorId = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EnrolledSemesters", x => x.Id);
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: "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: "Payment",
columns: table => new
{
UserId = table.Column(type: "integer", nullable: false),
EnrollmentInfoId = table.Column(type: "integer", nullable: false),
Id = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Payment", x => new { x.UserId, x.EnrollmentInfoId });
table.ForeignKey(
name: "FK_Payment_EnrolledSemesters_EnrollmentInfoId",
column: x => x.EnrollmentInfoId,
principalTable: "EnrolledSemesters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Payment_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SemesterSubject",
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)
},
constraints: table =>
{
table.PrimaryKey("PK_SemesterSubject", x => x.Id);
table.ForeignKey(
name: "FK_SemesterSubject_EnrolledSemesters_EnrolledSemesterId",
column: x => x.EnrolledSemesterId,
principalTable: "EnrolledSemesters",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_SemesterSubject_Subjects_SubjectId",
column: x => x.SubjectId,
principalTable: "Subjects",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_SemesterSubject_User_ProfessorId",
column: x => x.ProfessorId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_SemesterSubject_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_SemesterSubject_SemesterSubjectId",
column: x => x.SemesterSubjectId,
principalTable: "SemesterSubject",
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_Payment_EnrollmentInfoId",
table: "Payment",
column: "EnrollmentInfoId");
migrationBuilder.CreateIndex(
name: "IX_RefreshToken_UserId",
table: "RefreshToken",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_SemesterSubject_EnrolledSemesterId",
table: "SemesterSubject",
column: "EnrolledSemesterId");
migrationBuilder.CreateIndex(
name: "IX_SemesterSubject_ProfessorId",
table: "SemesterSubject",
column: "ProfessorId");
migrationBuilder.CreateIndex(
name: "IX_SemesterSubject_SubjectId",
table: "SemesterSubject",
column: "SubjectId");
migrationBuilder.CreateIndex(
name: "IX_SemesterSubject_UserId",
table: "SemesterSubject",
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: "Payment");
migrationBuilder.DropTable(
name: "RefreshToken");
migrationBuilder.DropTable(
name: "UserDocuments");
migrationBuilder.DropTable(
name: "SemesterSubject");
migrationBuilder.DropTable(
name: "Documents");
migrationBuilder.DropTable(
name: "EnrolledSemesters");
migrationBuilder.DropTable(
name: "Subjects");
migrationBuilder.DropTable(
name: "Majors");
migrationBuilder.DropTable(
name: "User");
}
}
}