source: iknow-api/Migrations/20251209133847_InitalCreate.cs@ 2d64b2e

Last change on this file since 2d64b2e was 2d64b2e, checked in by imbrsk <boris696boris@…>, 10 months ago

Refactor model properties for consistency and clarity

  • Property mode set to 100644
File size: 23.1 KB
Line 
1using System;
2using Microsoft.EntityFrameworkCore.Migrations;
3using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
4
5#nullable disable
6
7#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
8
9namespace iknow_api.Migrations
10{
11 /// <inheritdoc />
12 public partial class InitalCreate : Migration
13 {
14 /// <inheritdoc />
15 protected override void Up(MigrationBuilder migrationBuilder)
16 {
17 migrationBuilder.CreateTable(
18 name: "Documents",
19 columns: table => new
20 {
21 Id = table.Column<int>(type: "integer", nullable: false)
22 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
23 Name = table.Column<string>(type: "text", nullable: true),
24 Body = table.Column<string>(type: "text", nullable: true),
25 Cost = table.Column<int>(type: "integer", nullable: false)
26 },
27 constraints: table =>
28 {
29 table.PrimaryKey("PK_Documents", x => x.Id);
30 });
31
32 migrationBuilder.CreateTable(
33 name: "Majors",
34 columns: table => new
35 {
36 Id = table.Column<int>(type: "integer", nullable: false)
37 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
38 Name = table.Column<string>(type: "text", nullable: true)
39 },
40 constraints: table =>
41 {
42 table.PrimaryKey("PK_Majors", x => x.Id);
43 });
44
45 migrationBuilder.CreateTable(
46 name: "Subjects",
47 columns: table => new
48 {
49 Id = table.Column<int>(type: "integer", nullable: false)
50 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
51 Name = table.Column<string>(type: "text", nullable: true),
52 Code = table.Column<string>(type: "text", nullable: true),
53 AwardedCredits = table.Column<int>(type: "integer", nullable: true),
54 DependencyCredit = table.Column<int>(type: "integer", nullable: true)
55 },
56 constraints: table =>
57 {
58 table.PrimaryKey("PK_Subjects", x => x.Id);
59 });
60
61 migrationBuilder.CreateTable(
62 name: "User",
63 columns: table => new
64 {
65 Id = table.Column<int>(type: "integer", nullable: false)
66 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
67 Name = table.Column<string>(type: "text", nullable: true),
68 EMBG = table.Column<string>(type: "text", nullable: true),
69 Surname = table.Column<string>(type: "text", nullable: true),
70 Index = table.Column<string>(type: "text", nullable: true),
71 Email = table.Column<string>(type: "text", nullable: true),
72 PasswordHash = table.Column<string>(type: "text", nullable: true),
73 MiddleName = table.Column<string>(type: "text", nullable: true),
74 Gender = table.Column<string>(type: "text", nullable: true),
75 Nationality = table.Column<string>(type: "text", nullable: true),
76 Citizenship = table.Column<string>(type: "text", nullable: true),
77 Bday = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
78 CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
79 Role = table.Column<int>(type: "integer", nullable: false)
80 },
81 constraints: table =>
82 {
83 table.PrimaryKey("PK_User", x => x.Id);
84 });
85
86 migrationBuilder.CreateTable(
87 name: "DependencySubjects",
88 columns: table => new
89 {
90 SubjectId = table.Column<int>(type: "integer", nullable: false),
91 DependencyId = table.Column<int>(type: "integer", nullable: false)
92 },
93 constraints: table =>
94 {
95 table.PrimaryKey("PK_DependencySubjects", x => new { x.SubjectId, x.DependencyId });
96 table.ForeignKey(
97 name: "FK_DependencySubjects_Subjects_DependencyId",
98 column: x => x.DependencyId,
99 principalTable: "Subjects",
100 principalColumn: "Id",
101 onDelete: ReferentialAction.Restrict);
102 table.ForeignKey(
103 name: "FK_DependencySubjects_Subjects_SubjectId",
104 column: x => x.SubjectId,
105 principalTable: "Subjects",
106 principalColumn: "Id",
107 onDelete: ReferentialAction.Restrict);
108 });
109
110 migrationBuilder.CreateTable(
111 name: "MajorSubjects",
112 columns: table => new
113 {
114 MajorId = table.Column<int>(type: "integer", nullable: false),
115 SubjectId = table.Column<int>(type: "integer", nullable: false),
116 MandatorySemester = table.Column<int>(type: "integer", nullable: false),
117 Accreditation = table.Column<int>(type: "integer", nullable: false)
118 },
119 constraints: table =>
120 {
121 table.PrimaryKey("PK_MajorSubjects", x => new { x.MajorId, x.SubjectId });
122 table.ForeignKey(
123 name: "FK_MajorSubjects_Majors_MajorId",
124 column: x => x.MajorId,
125 principalTable: "Majors",
126 principalColumn: "Id",
127 onDelete: ReferentialAction.Cascade);
128 table.ForeignKey(
129 name: "FK_MajorSubjects_Subjects_SubjectId",
130 column: x => x.SubjectId,
131 principalTable: "Subjects",
132 principalColumn: "Id",
133 onDelete: ReferentialAction.Cascade);
134 });
135
136 migrationBuilder.CreateTable(
137 name: "ContactInfo",
138 columns: table => new
139 {
140 Id = table.Column<int>(type: "integer", nullable: false)
141 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
142 City = table.Column<string>(type: "text", nullable: true),
143 Address = table.Column<string>(type: "text", nullable: true),
144 Municipality = table.Column<string>(type: "text", nullable: true),
145 PhoneNumber = table.Column<string>(type: "text", nullable: true),
146 MicrosoftEmail = table.Column<string>(type: "text", nullable: true),
147 UserId = table.Column<int>(type: "integer", nullable: false)
148 },
149 constraints: table =>
150 {
151 table.PrimaryKey("PK_ContactInfo", x => x.Id);
152 table.ForeignKey(
153 name: "FK_ContactInfo_User_UserId",
154 column: x => x.UserId,
155 principalTable: "User",
156 principalColumn: "Id",
157 onDelete: ReferentialAction.Cascade);
158 });
159
160 migrationBuilder.CreateTable(
161 name: "EnrolledSemesters",
162 columns: table => new
163 {
164 Id = table.Column<int>(type: "integer", nullable: false)
165 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
166 UserId = table.Column<int>(type: "integer", nullable: false),
167 Year = table.Column<int>(type: "integer", nullable: false),
168 Type = table.Column<int>(type: "integer", nullable: false),
169 QuotaType = table.Column<int>(type: "integer", nullable: false),
170 MajorId = table.Column<int>(type: "integer", nullable: false)
171 },
172 constraints: table =>
173 {
174 table.PrimaryKey("PK_EnrolledSemesters", x => x.Id);
175 table.ForeignKey(
176 name: "FK_EnrolledSemesters_Majors_MajorId",
177 column: x => x.MajorId,
178 principalTable: "Majors",
179 principalColumn: "Id",
180 onDelete: ReferentialAction.Cascade);
181 table.ForeignKey(
182 name: "FK_EnrolledSemesters_User_UserId",
183 column: x => x.UserId,
184 principalTable: "User",
185 principalColumn: "Id",
186 onDelete: ReferentialAction.Cascade);
187 });
188
189 migrationBuilder.CreateTable(
190 name: "EnrollmentInfo",
191 columns: table => new
192 {
193 Id = table.Column<int>(type: "integer", nullable: false)
194 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
195 enrollmentYear = table.Column<int>(type: "integer", nullable: false),
196 quota = table.Column<int>(type: "integer", nullable: false),
197 MajorId = table.Column<int>(type: "integer", nullable: false),
198 UserId = table.Column<int>(type: "integer", nullable: false),
199 StudyType = table.Column<string>(type: "text", nullable: true),
200 StudyStatus = table.Column<string>(type: "text", nullable: true)
201 },
202 constraints: table =>
203 {
204 table.PrimaryKey("PK_EnrollmentInfo", x => x.Id);
205 table.ForeignKey(
206 name: "FK_EnrollmentInfo_Majors_MajorId",
207 column: x => x.MajorId,
208 principalTable: "Majors",
209 principalColumn: "Id",
210 onDelete: ReferentialAction.Cascade);
211 table.ForeignKey(
212 name: "FK_EnrollmentInfo_User_UserId",
213 column: x => x.UserId,
214 principalTable: "User",
215 principalColumn: "Id",
216 onDelete: ReferentialAction.Cascade);
217 });
218
219 migrationBuilder.CreateTable(
220 name: "HighSchool",
221 columns: table => new
222 {
223 Id = table.Column<int>(type: "integer", nullable: false)
224 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
225 GPA = table.Column<float>(type: "real", nullable: false),
226 HighSchoolType = table.Column<int>(type: "integer", nullable: false),
227 UserId = table.Column<int>(type: "integer", nullable: false),
228 StudyLanguage = table.Column<string>(type: "text", nullable: true)
229 },
230 constraints: table =>
231 {
232 table.PrimaryKey("PK_HighSchool", x => x.Id);
233 table.ForeignKey(
234 name: "FK_HighSchool_User_UserId",
235 column: x => x.UserId,
236 principalTable: "User",
237 principalColumn: "Id",
238 onDelete: ReferentialAction.Cascade);
239 });
240
241 migrationBuilder.CreateTable(
242 name: "RefreshToken",
243 columns: table => new
244 {
245 Id = table.Column<int>(type: "integer", nullable: false)
246 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
247 UserId = table.Column<int>(type: "integer", nullable: false),
248 Token = table.Column<string>(type: "text", nullable: true),
249 ExpiresAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
250 IsValid = table.Column<bool>(type: "boolean", nullable: false)
251 },
252 constraints: table =>
253 {
254 table.PrimaryKey("PK_RefreshToken", x => x.Id);
255 table.ForeignKey(
256 name: "FK_RefreshToken_User_UserId",
257 column: x => x.UserId,
258 principalTable: "User",
259 principalColumn: "Id",
260 onDelete: ReferentialAction.Cascade);
261 });
262
263 migrationBuilder.CreateTable(
264 name: "UserDocuments",
265 columns: table => new
266 {
267 UserId = table.Column<int>(type: "integer", nullable: false),
268 DocumentId = table.Column<int>(type: "integer", nullable: false)
269 },
270 constraints: table =>
271 {
272 table.PrimaryKey("PK_UserDocuments", x => new { x.UserId, x.DocumentId });
273 table.ForeignKey(
274 name: "FK_UserDocuments_Documents_DocumentId",
275 column: x => x.DocumentId,
276 principalTable: "Documents",
277 principalColumn: "Id",
278 onDelete: ReferentialAction.Cascade);
279 table.ForeignKey(
280 name: "FK_UserDocuments_User_UserId",
281 column: x => x.UserId,
282 principalTable: "User",
283 principalColumn: "Id",
284 onDelete: ReferentialAction.Cascade);
285 });
286
287 migrationBuilder.CreateTable(
288 name: "Payment",
289 columns: table => new
290 {
291 UserId = table.Column<int>(type: "integer", nullable: false),
292 EnrollmentInfoId = table.Column<int>(type: "integer", nullable: false),
293 Id = table.Column<int>(type: "integer", nullable: false)
294 },
295 constraints: table =>
296 {
297 table.PrimaryKey("PK_Payment", x => new { x.UserId, x.EnrollmentInfoId });
298 table.ForeignKey(
299 name: "FK_Payment_EnrolledSemesters_EnrollmentInfoId",
300 column: x => x.EnrollmentInfoId,
301 principalTable: "EnrolledSemesters",
302 principalColumn: "Id",
303 onDelete: ReferentialAction.Cascade);
304 table.ForeignKey(
305 name: "FK_Payment_User_UserId",
306 column: x => x.UserId,
307 principalTable: "User",
308 principalColumn: "Id",
309 onDelete: ReferentialAction.Cascade);
310 });
311
312 migrationBuilder.CreateTable(
313 name: "SemesterSubject",
314 columns: table => new
315 {
316 Id = table.Column<int>(type: "integer", nullable: false)
317 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
318 UserId = table.Column<int>(type: "integer", nullable: false),
319 EnrolledSemesterId = table.Column<int>(type: "integer", nullable: false),
320 SubjectId = table.Column<int>(type: "integer", nullable: false),
321 ProfessorId = table.Column<int>(type: "integer", nullable: false)
322 },
323 constraints: table =>
324 {
325 table.PrimaryKey("PK_SemesterSubject", x => x.Id);
326 table.ForeignKey(
327 name: "FK_SemesterSubject_EnrolledSemesters_EnrolledSemesterId",
328 column: x => x.EnrolledSemesterId,
329 principalTable: "EnrolledSemesters",
330 principalColumn: "Id",
331 onDelete: ReferentialAction.Restrict);
332 table.ForeignKey(
333 name: "FK_SemesterSubject_Subjects_SubjectId",
334 column: x => x.SubjectId,
335 principalTable: "Subjects",
336 principalColumn: "Id",
337 onDelete: ReferentialAction.Restrict);
338 table.ForeignKey(
339 name: "FK_SemesterSubject_User_ProfessorId",
340 column: x => x.ProfessorId,
341 principalTable: "User",
342 principalColumn: "Id",
343 onDelete: ReferentialAction.Restrict);
344 table.ForeignKey(
345 name: "FK_SemesterSubject_User_UserId",
346 column: x => x.UserId,
347 principalTable: "User",
348 principalColumn: "Id",
349 onDelete: ReferentialAction.Restrict);
350 });
351
352 migrationBuilder.CreateTable(
353 name: "PassedSubjects",
354 columns: table => new
355 {
356 Id = table.Column<int>(type: "integer", nullable: false)
357 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
358 SemesterSubjectId = table.Column<int>(type: "integer", nullable: false),
359 Grade = table.Column<int>(type: "integer", nullable: false),
360 DatePassed = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
361 },
362 constraints: table =>
363 {
364 table.PrimaryKey("PK_PassedSubjects", x => x.Id);
365 table.ForeignKey(
366 name: "FK_PassedSubjects_SemesterSubject_SemesterSubjectId",
367 column: x => x.SemesterSubjectId,
368 principalTable: "SemesterSubject",
369 principalColumn: "Id",
370 onDelete: ReferentialAction.Cascade);
371 });
372
373 migrationBuilder.InsertData(
374 table: "Majors",
375 columns: new[] { "Id", "Name" },
376 values: new object[,]
377 {
378 { 1, "PIT" },
379 { 2, "SIIS" },
380 { 3, "SEIS" },
381 { 4, "KN" }
382 });
383
384 migrationBuilder.CreateIndex(
385 name: "IX_ContactInfo_UserId",
386 table: "ContactInfo",
387 column: "UserId",
388 unique: true);
389
390 migrationBuilder.CreateIndex(
391 name: "IX_DependencySubjects_DependencyId",
392 table: "DependencySubjects",
393 column: "DependencyId");
394
395 migrationBuilder.CreateIndex(
396 name: "IX_EnrolledSemesters_MajorId",
397 table: "EnrolledSemesters",
398 column: "MajorId");
399
400 migrationBuilder.CreateIndex(
401 name: "IX_EnrolledSemesters_UserId",
402 table: "EnrolledSemesters",
403 column: "UserId");
404
405 migrationBuilder.CreateIndex(
406 name: "IX_EnrollmentInfo_MajorId",
407 table: "EnrollmentInfo",
408 column: "MajorId");
409
410 migrationBuilder.CreateIndex(
411 name: "IX_EnrollmentInfo_UserId",
412 table: "EnrollmentInfo",
413 column: "UserId",
414 unique: true);
415
416 migrationBuilder.CreateIndex(
417 name: "IX_HighSchool_UserId",
418 table: "HighSchool",
419 column: "UserId",
420 unique: true);
421
422 migrationBuilder.CreateIndex(
423 name: "IX_MajorSubjects_SubjectId",
424 table: "MajorSubjects",
425 column: "SubjectId");
426
427 migrationBuilder.CreateIndex(
428 name: "IX_PassedSubjects_SemesterSubjectId",
429 table: "PassedSubjects",
430 column: "SemesterSubjectId",
431 unique: true);
432
433 migrationBuilder.CreateIndex(
434 name: "IX_Payment_EnrollmentInfoId",
435 table: "Payment",
436 column: "EnrollmentInfoId");
437
438 migrationBuilder.CreateIndex(
439 name: "IX_RefreshToken_UserId",
440 table: "RefreshToken",
441 column: "UserId");
442
443 migrationBuilder.CreateIndex(
444 name: "IX_SemesterSubject_EnrolledSemesterId",
445 table: "SemesterSubject",
446 column: "EnrolledSemesterId");
447
448 migrationBuilder.CreateIndex(
449 name: "IX_SemesterSubject_ProfessorId",
450 table: "SemesterSubject",
451 column: "ProfessorId");
452
453 migrationBuilder.CreateIndex(
454 name: "IX_SemesterSubject_SubjectId",
455 table: "SemesterSubject",
456 column: "SubjectId");
457
458 migrationBuilder.CreateIndex(
459 name: "IX_SemesterSubject_UserId",
460 table: "SemesterSubject",
461 column: "UserId");
462
463 migrationBuilder.CreateIndex(
464 name: "IX_UserDocuments_DocumentId",
465 table: "UserDocuments",
466 column: "DocumentId");
467 }
468
469 /// <inheritdoc />
470 protected override void Down(MigrationBuilder migrationBuilder)
471 {
472 migrationBuilder.DropTable(
473 name: "ContactInfo");
474
475 migrationBuilder.DropTable(
476 name: "DependencySubjects");
477
478 migrationBuilder.DropTable(
479 name: "EnrollmentInfo");
480
481 migrationBuilder.DropTable(
482 name: "HighSchool");
483
484 migrationBuilder.DropTable(
485 name: "MajorSubjects");
486
487 migrationBuilder.DropTable(
488 name: "PassedSubjects");
489
490 migrationBuilder.DropTable(
491 name: "Payment");
492
493 migrationBuilder.DropTable(
494 name: "RefreshToken");
495
496 migrationBuilder.DropTable(
497 name: "UserDocuments");
498
499 migrationBuilder.DropTable(
500 name: "SemesterSubject");
501
502 migrationBuilder.DropTable(
503 name: "Documents");
504
505 migrationBuilder.DropTable(
506 name: "EnrolledSemesters");
507
508 migrationBuilder.DropTable(
509 name: "Subjects");
510
511 migrationBuilder.DropTable(
512 name: "Majors");
513
514 migrationBuilder.DropTable(
515 name: "User");
516 }
517 }
518}
Note: See TracBrowser for help on using the repository browser.