source: iknow-api/Migrations/20251210134426_UpdateModels.cs@ 39f76a9

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

feat: Add ActiveSemesters model and update related entities

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