source: iknow-api/Migrations/20251029131316_InitialCreate.cs@ f8af32b

Last change on this file since f8af32b was f8af32b, checked in by stefansaveski <stefansaveski19@…>, 11 months ago

Add EMBG property and consolidate migrations

Added EMBG property to User and RegisterDto classes to store unique user identifiers. Removed outdated migration files and introduced a new consolidated migration (20251029131316_InitialCreate) to define the database schema, including User, ContactInfo, EnrollmentInfo, HighSchool, and RefreshToken tables with appropriate relationships. Updated AppDbContextModelSnapshot to reflect the new schema. Changed the development database connection string in appsettings.Development.json for improved configuration.

  • Property mode set to 100644
File size: 7.2 KB
Line 
1using System;
2using Microsoft.EntityFrameworkCore.Migrations;
3using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
4
5#nullable disable
6
7namespace iknow_api.Migrations
8{
9 /// <inheritdoc />
10 public partial class InitialCreate : Migration
11 {
12 /// <inheritdoc />
13 protected override void Up(MigrationBuilder migrationBuilder)
14 {
15 migrationBuilder.CreateTable(
16 name: "User",
17 columns: table => new
18 {
19 Id = table.Column<int>(type: "integer", nullable: false)
20 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
21 Name = table.Column<string>(type: "text", nullable: true),
22 Surname = table.Column<string>(type: "text", nullable: true),
23 Index = table.Column<string>(type: "text", nullable: true),
24 Email = table.Column<string>(type: "text", nullable: true),
25 PasswordHash = table.Column<string>(type: "text", nullable: true),
26 Bday = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
27 CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
28 Role = table.Column<int>(type: "integer", nullable: false)
29 },
30 constraints: table =>
31 {
32 table.PrimaryKey("PK_User", x => x.Id);
33 });
34
35 migrationBuilder.CreateTable(
36 name: "ContactInfo",
37 columns: table => new
38 {
39 Id = table.Column<int>(type: "integer", nullable: false)
40 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
41 city = table.Column<string>(type: "text", nullable: true),
42 address = table.Column<string>(type: "text", nullable: true),
43 municipality = table.Column<string>(type: "text", nullable: true),
44 phoneNumber = table.Column<string>(type: "text", nullable: true),
45 microsoftEmail = table.Column<string>(type: "text", nullable: true),
46 UserId = table.Column<int>(type: "integer", nullable: false)
47 },
48 constraints: table =>
49 {
50 table.PrimaryKey("PK_ContactInfo", x => x.Id);
51 table.ForeignKey(
52 name: "FK_ContactInfo_User_UserId",
53 column: x => x.UserId,
54 principalTable: "User",
55 principalColumn: "Id",
56 onDelete: ReferentialAction.Cascade);
57 });
58
59 migrationBuilder.CreateTable(
60 name: "EnrollmentInfo",
61 columns: table => new
62 {
63 Id = table.Column<int>(type: "integer", nullable: false)
64 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
65 enrollmentYear = table.Column<int>(type: "integer", nullable: false),
66 major = table.Column<int>(type: "integer", nullable: false),
67 UserId = table.Column<int>(type: "integer", nullable: false)
68 },
69 constraints: table =>
70 {
71 table.PrimaryKey("PK_EnrollmentInfo", x => x.Id);
72 table.ForeignKey(
73 name: "FK_EnrollmentInfo_User_UserId",
74 column: x => x.UserId,
75 principalTable: "User",
76 principalColumn: "Id",
77 onDelete: ReferentialAction.Cascade);
78 });
79
80 migrationBuilder.CreateTable(
81 name: "HighSchool",
82 columns: table => new
83 {
84 Id = table.Column<int>(type: "integer", nullable: false)
85 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
86 GPA = table.Column<float>(type: "real", nullable: false),
87 tip = table.Column<int>(type: "integer", nullable: false),
88 UserId = table.Column<int>(type: "integer", nullable: false)
89 },
90 constraints: table =>
91 {
92 table.PrimaryKey("PK_HighSchool", x => x.Id);
93 table.ForeignKey(
94 name: "FK_HighSchool_User_UserId",
95 column: x => x.UserId,
96 principalTable: "User",
97 principalColumn: "Id",
98 onDelete: ReferentialAction.Cascade);
99 });
100
101 migrationBuilder.CreateTable(
102 name: "RefreshToken",
103 columns: table => new
104 {
105 Id = table.Column<int>(type: "integer", nullable: false)
106 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
107 UserId = table.Column<int>(type: "integer", nullable: false),
108 Token = table.Column<string>(type: "text", nullable: true),
109 ExpiresAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
110 IsValid = table.Column<bool>(type: "boolean", nullable: false)
111 },
112 constraints: table =>
113 {
114 table.PrimaryKey("PK_RefreshToken", x => x.Id);
115 table.ForeignKey(
116 name: "FK_RefreshToken_User_UserId",
117 column: x => x.UserId,
118 principalTable: "User",
119 principalColumn: "Id",
120 onDelete: ReferentialAction.Cascade);
121 });
122
123 migrationBuilder.CreateIndex(
124 name: "IX_ContactInfo_UserId",
125 table: "ContactInfo",
126 column: "UserId",
127 unique: true);
128
129 migrationBuilder.CreateIndex(
130 name: "IX_EnrollmentInfo_UserId",
131 table: "EnrollmentInfo",
132 column: "UserId",
133 unique: true);
134
135 migrationBuilder.CreateIndex(
136 name: "IX_HighSchool_UserId",
137 table: "HighSchool",
138 column: "UserId",
139 unique: true);
140
141 migrationBuilder.CreateIndex(
142 name: "IX_RefreshToken_UserId",
143 table: "RefreshToken",
144 column: "UserId");
145 }
146
147 /// <inheritdoc />
148 protected override void Down(MigrationBuilder migrationBuilder)
149 {
150 migrationBuilder.DropTable(
151 name: "ContactInfo");
152
153 migrationBuilder.DropTable(
154 name: "EnrollmentInfo");
155
156 migrationBuilder.DropTable(
157 name: "HighSchool");
158
159 migrationBuilder.DropTable(
160 name: "RefreshToken");
161
162 migrationBuilder.DropTable(
163 name: "User");
164 }
165 }
166}
Note: See TracBrowser for help on using the repository browser.