source: iknow-api/Migrations/20251208203846_InitialCreate.cs@ c2f79d7

Last change on this file since c2f79d7 was c2f79d7, checked in by Stefan-Saveski <stefan@…>, 10 months ago

Refactor and enhance application structure

Enhanced error handling in AuthController with detailed exception handling for user registration. Updated UserDTO to improve JSON serialization and renamed enums for clarity. Introduced new entities (Major, PassedSubject, etc.) and seeded initial data in AppDbContext.

Replaced legacy migrations with 20251208203846_InitialCreate, reflecting the updated schema. Fixed typographical errors and improved JSON serialization in Program.cs with case-insensitive property matching and enum handling.

Refactored repository interfaces for better null safety. Improved debugging in AuthService and updated connection strings. Added the PassedSubject entity and cleaned up redundant code and unused imports for better maintainability.

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