source: ChapterX.Infrastructure/Migrations/20260824172555_InitialCreate.cs@ e882b92

main
Last change on this file since e882b92 was e882b92, checked in by kikisrbinoska <srbinoskakristina07@…>, 13 days ago

Added corrected entitef from the ER diagram and changes for the logic to be coresponding to the ddl

  • Property mode set to 100644
File size: 23.9 KB
RevLine 
[e882b92]1using System;
2using Microsoft.EntityFrameworkCore.Migrations;
3using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
4
5#nullable disable
6
7namespace ChapterX.Infrastructure.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: "genre",
17 columns: table => new
18 {
19 genre_id = table.Column<int>(type: "integer", nullable: false)
20 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
21 genre_name = table.Column<string>(type: "text", nullable: false)
22 },
23 constraints: table =>
24 {
25 table.PrimaryKey("PK_genre", x => x.genre_id);
26 });
27
28 migrationBuilder.CreateTable(
29 name: "users",
30 columns: table => new
31 {
32 user_id = table.Column<int>(type: "integer", nullable: false)
33 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
34 username = table.Column<string>(type: "text", nullable: false),
35 email = table.Column<string>(type: "text", nullable: false),
36 user_name = table.Column<string>(type: "text", nullable: false),
37 surname = table.Column<string>(type: "text", nullable: false),
38 password = table.Column<string>(type: "text", nullable: false),
39 user_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
40 user_updated_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
41 },
42 constraints: table =>
43 {
44 table.PrimaryKey("PK_users", x => x.user_id);
45 });
46
47 migrationBuilder.CreateTable(
48 name: "admins",
49 columns: table => new
50 {
51 user_id = table.Column<int>(type: "integer", nullable: false),
52 assigned_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
53 },
54 constraints: table =>
55 {
56 table.PrimaryKey("PK_admins", x => x.user_id);
57 table.ForeignKey(
58 name: "FK_admins_users_user_id",
59 column: x => x.user_id,
60 principalTable: "users",
61 principalColumn: "user_id",
62 onDelete: ReferentialAction.Cascade);
63 });
64
65 migrationBuilder.CreateTable(
66 name: "reading_list",
67 columns: table => new
68 {
69 list_id = table.Column<int>(type: "integer", nullable: false)
70 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
71 list_name = table.Column<string>(type: "text", nullable: false),
72 list_content = table.Column<string>(type: "text", nullable: true),
73 is_public = table.Column<bool>(type: "boolean", nullable: false),
74 list_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
75 list_updated_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
76 user_id = table.Column<int>(type: "integer", nullable: false)
77 },
78 constraints: table =>
79 {
80 table.PrimaryKey("PK_reading_list", x => x.list_id);
81 table.ForeignKey(
82 name: "FK_reading_list_users_user_id",
83 column: x => x.user_id,
84 principalTable: "users",
85 principalColumn: "user_id",
86 onDelete: ReferentialAction.Cascade);
87 });
88
89 migrationBuilder.CreateTable(
90 name: "regular_user",
91 columns: table => new
92 {
93 user_id = table.Column<int>(type: "integer", nullable: false),
94 joined_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
95 },
96 constraints: table =>
97 {
98 table.PrimaryKey("PK_regular_user", x => x.user_id);
99 table.ForeignKey(
100 name: "FK_regular_user_users_user_id",
101 column: x => x.user_id,
102 principalTable: "users",
103 principalColumn: "user_id",
104 onDelete: ReferentialAction.Cascade);
105 });
106
107 migrationBuilder.CreateTable(
108 name: "writer",
109 columns: table => new
110 {
111 user_id = table.Column<int>(type: "integer", nullable: false),
112 bio = table.Column<string>(type: "text", nullable: true)
113 },
114 constraints: table =>
115 {
116 table.PrimaryKey("PK_writer", x => x.user_id);
117 table.ForeignKey(
118 name: "FK_writer_users_user_id",
119 column: x => x.user_id,
120 principalTable: "users",
121 principalColumn: "user_id",
122 onDelete: ReferentialAction.Cascade);
123 });
124
125 migrationBuilder.CreateTable(
126 name: "story",
127 columns: table => new
128 {
129 story_id = table.Column<int>(type: "integer", nullable: false)
130 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
131 mature_content = table.Column<bool>(type: "boolean", nullable: false),
132 title = table.Column<string>(type: "text", nullable: false),
133 short_description = table.Column<string>(type: "text", nullable: false),
134 image = table.Column<string>(type: "text", nullable: true),
135 story_content = table.Column<string>(type: "text", nullable: false),
136 status = table.Column<string>(type: "text", nullable: false),
137 story_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
138 story_updated_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
139 user_id = table.Column<int>(type: "integer", nullable: false)
140 },
141 constraints: table =>
142 {
143 table.PrimaryKey("PK_story", x => x.story_id);
144 table.ForeignKey(
145 name: "FK_story_writer_user_id",
146 column: x => x.user_id,
147 principalTable: "writer",
148 principalColumn: "user_id",
149 onDelete: ReferentialAction.Cascade);
150 });
151
152 migrationBuilder.CreateTable(
153 name: "ai_suggestion",
154 columns: table => new
155 {
156 suggestion_id = table.Column<int>(type: "integer", nullable: false)
157 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
158 original_text = table.Column<string>(type: "text", nullable: false),
159 suggested_text = table.Column<string>(type: "text", nullable: false),
160 suggestion_type = table.Column<string>(type: "text", nullable: false),
161 accepted = table.Column<bool>(type: "boolean", nullable: true),
162 suggestion_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
163 applied_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
164 story_id = table.Column<int>(type: "integer", nullable: false)
165 },
166 constraints: table =>
167 {
168 table.PrimaryKey("PK_ai_suggestion", x => x.suggestion_id);
169 table.ForeignKey(
170 name: "FK_ai_suggestion_story_story_id",
171 column: x => x.story_id,
172 principalTable: "story",
173 principalColumn: "story_id",
174 onDelete: ReferentialAction.Cascade);
175 });
176
177 migrationBuilder.CreateTable(
178 name: "chapter",
179 columns: table => new
180 {
181 chapter_id = table.Column<int>(type: "integer", nullable: false)
182 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
183 chapter_number = table.Column<int>(type: "integer", nullable: false),
184 chapter_name = table.Column<string>(type: "text", nullable: false),
185 title = table.Column<string>(type: "text", nullable: false),
186 chapter_content = table.Column<string>(type: "text", nullable: false),
187 word_count = table.Column<int>(type: "integer", nullable: true),
188 rating = table.Column<decimal>(type: "numeric", nullable: true),
189 published_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
190 view_count = table.Column<int>(type: "integer", nullable: false),
191 chapter_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
192 chapter_updated_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
193 story_id = table.Column<int>(type: "integer", nullable: false)
194 },
195 constraints: table =>
196 {
197 table.PrimaryKey("PK_chapter", x => x.chapter_id);
198 table.ForeignKey(
199 name: "FK_chapter_story_story_id",
200 column: x => x.story_id,
201 principalTable: "story",
202 principalColumn: "story_id",
203 onDelete: ReferentialAction.Cascade);
204 });
205
206 migrationBuilder.CreateTable(
207 name: "collaboration",
208 columns: table => new
209 {
210 user_id = table.Column<int>(type: "integer", nullable: false),
211 story_id = table.Column<int>(type: "integer", nullable: false),
212 role = table.Column<string>(type: "text", nullable: false),
213 permission_level = table.Column<int>(type: "integer", nullable: true),
214 collab_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
215 },
216 constraints: table =>
217 {
218 table.PrimaryKey("PK_collaboration", x => new { x.user_id, x.story_id });
219 table.ForeignKey(
220 name: "FK_collaboration_story_story_id",
221 column: x => x.story_id,
222 principalTable: "story",
223 principalColumn: "story_id",
224 onDelete: ReferentialAction.Cascade);
225 table.ForeignKey(
226 name: "FK_collaboration_users_user_id",
227 column: x => x.user_id,
228 principalTable: "users",
229 principalColumn: "user_id",
230 onDelete: ReferentialAction.Cascade);
231 });
232
233 migrationBuilder.CreateTable(
234 name: "comment",
235 columns: table => new
236 {
237 comment_id = table.Column<int>(type: "integer", nullable: false)
238 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
239 comment_content = table.Column<string>(type: "text", nullable: false),
240 comment_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
241 comment_updated_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
242 user_id = table.Column<int>(type: "integer", nullable: false),
243 story_id = table.Column<int>(type: "integer", nullable: false)
244 },
245 constraints: table =>
246 {
247 table.PrimaryKey("PK_comment", x => x.comment_id);
248 table.ForeignKey(
249 name: "FK_comment_story_story_id",
250 column: x => x.story_id,
251 principalTable: "story",
252 principalColumn: "story_id",
253 onDelete: ReferentialAction.Cascade);
254 table.ForeignKey(
255 name: "FK_comment_users_user_id",
256 column: x => x.user_id,
257 principalTable: "users",
258 principalColumn: "user_id",
259 onDelete: ReferentialAction.Cascade);
260 });
261
262 migrationBuilder.CreateTable(
263 name: "has_genre",
264 columns: table => new
265 {
266 story_id = table.Column<int>(type: "integer", nullable: false),
267 genre_id = table.Column<int>(type: "integer", nullable: false)
268 },
269 constraints: table =>
270 {
271 table.PrimaryKey("PK_has_genre", x => new { x.story_id, x.genre_id });
272 table.ForeignKey(
273 name: "FK_has_genre_genre_genre_id",
274 column: x => x.genre_id,
275 principalTable: "genre",
276 principalColumn: "genre_id",
277 onDelete: ReferentialAction.Cascade);
278 table.ForeignKey(
279 name: "FK_has_genre_story_story_id",
280 column: x => x.story_id,
281 principalTable: "story",
282 principalColumn: "story_id",
283 onDelete: ReferentialAction.Cascade);
284 });
285
286 migrationBuilder.CreateTable(
287 name: "likes",
288 columns: table => new
289 {
290 user_id = table.Column<int>(type: "integer", nullable: false),
291 story_id = table.Column<int>(type: "integer", nullable: false),
292 liked_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
293 },
294 constraints: table =>
295 {
296 table.PrimaryKey("PK_likes", x => new { x.user_id, x.story_id });
297 table.ForeignKey(
298 name: "FK_likes_story_story_id",
299 column: x => x.story_id,
300 principalTable: "story",
301 principalColumn: "story_id",
302 onDelete: ReferentialAction.Cascade);
303 table.ForeignKey(
304 name: "FK_likes_users_user_id",
305 column: x => x.user_id,
306 principalTable: "users",
307 principalColumn: "user_id",
308 onDelete: ReferentialAction.Cascade);
309 });
310
311 migrationBuilder.CreateTable(
312 name: "notification",
313 columns: table => new
314 {
315 notification_id = table.Column<int>(type: "integer", nullable: false)
316 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
317 notification_content = table.Column<string>(type: "text", nullable: false),
318 content_type = table.Column<string>(type: "text", nullable: false),
319 is_read = table.Column<bool>(type: "boolean", nullable: false),
320 link = table.Column<string>(type: "text", nullable: true),
321 notification_created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
322 user_id = table.Column<int>(type: "integer", nullable: false),
323 story_id = table.Column<int>(type: "integer", nullable: true)
324 },
325 constraints: table =>
326 {
327 table.PrimaryKey("PK_notification", x => x.notification_id);
328 table.ForeignKey(
329 name: "FK_notification_story_story_id",
330 column: x => x.story_id,
331 principalTable: "story",
332 principalColumn: "story_id",
333 onDelete: ReferentialAction.SetNull);
334 table.ForeignKey(
335 name: "FK_notification_users_user_id",
336 column: x => x.user_id,
337 principalTable: "users",
338 principalColumn: "user_id",
339 onDelete: ReferentialAction.Cascade);
340 });
341
342 migrationBuilder.CreateTable(
343 name: "reading_list_items",
344 columns: table => new
345 {
346 list_id = table.Column<int>(type: "integer", nullable: false),
347 story_id = table.Column<int>(type: "integer", nullable: false),
348 added_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
349 },
350 constraints: table =>
351 {
352 table.PrimaryKey("PK_reading_list_items", x => new { x.list_id, x.story_id });
353 table.ForeignKey(
354 name: "FK_reading_list_items_reading_list_list_id",
355 column: x => x.list_id,
356 principalTable: "reading_list",
357 principalColumn: "list_id",
358 onDelete: ReferentialAction.Cascade);
359 table.ForeignKey(
360 name: "FK_reading_list_items_story_story_id",
361 column: x => x.story_id,
362 principalTable: "story",
363 principalColumn: "story_id",
364 onDelete: ReferentialAction.Cascade);
365 });
366
367 migrationBuilder.CreateTable(
368 name: "need_approval",
369 columns: table => new
370 {
371 suggestion_id = table.Column<int>(type: "integer", nullable: false),
372 story_id = table.Column<int>(type: "integer", nullable: false),
373 chapter_id = table.Column<int>(type: "integer", nullable: false)
374 },
375 constraints: table =>
376 {
377 table.PrimaryKey("PK_need_approval", x => new { x.suggestion_id, x.story_id, x.chapter_id });
378 table.ForeignKey(
379 name: "FK_need_approval_ai_suggestion_suggestion_id",
380 column: x => x.suggestion_id,
381 principalTable: "ai_suggestion",
382 principalColumn: "suggestion_id",
383 onDelete: ReferentialAction.Cascade);
384 table.ForeignKey(
385 name: "FK_need_approval_chapter_chapter_id",
386 column: x => x.chapter_id,
387 principalTable: "chapter",
388 principalColumn: "chapter_id",
389 onDelete: ReferentialAction.Cascade);
390 table.ForeignKey(
391 name: "FK_need_approval_story_story_id",
392 column: x => x.story_id,
393 principalTable: "story",
394 principalColumn: "story_id",
395 onDelete: ReferentialAction.Cascade);
396 });
397
398 migrationBuilder.CreateIndex(
399 name: "IX_ai_suggestion_story_id",
400 table: "ai_suggestion",
401 column: "story_id");
402
403 migrationBuilder.CreateIndex(
404 name: "IX_chapter_story_id",
405 table: "chapter",
406 column: "story_id");
407
408 migrationBuilder.CreateIndex(
409 name: "IX_collaboration_story_id",
410 table: "collaboration",
411 column: "story_id");
412
413 migrationBuilder.CreateIndex(
414 name: "IX_comment_story_id",
415 table: "comment",
416 column: "story_id");
417
418 migrationBuilder.CreateIndex(
419 name: "IX_comment_user_id",
420 table: "comment",
421 column: "user_id");
422
423 migrationBuilder.CreateIndex(
424 name: "IX_has_genre_genre_id",
425 table: "has_genre",
426 column: "genre_id");
427
428 migrationBuilder.CreateIndex(
429 name: "IX_likes_story_id",
430 table: "likes",
431 column: "story_id");
432
433 migrationBuilder.CreateIndex(
434 name: "IX_need_approval_chapter_id",
435 table: "need_approval",
436 column: "chapter_id");
437
438 migrationBuilder.CreateIndex(
439 name: "IX_need_approval_story_id",
440 table: "need_approval",
441 column: "story_id");
442
443 migrationBuilder.CreateIndex(
444 name: "IX_notification_story_id",
445 table: "notification",
446 column: "story_id");
447
448 migrationBuilder.CreateIndex(
449 name: "IX_notification_user_id",
450 table: "notification",
451 column: "user_id");
452
453 migrationBuilder.CreateIndex(
454 name: "IX_reading_list_user_id",
455 table: "reading_list",
456 column: "user_id");
457
458 migrationBuilder.CreateIndex(
459 name: "IX_reading_list_items_story_id",
460 table: "reading_list_items",
461 column: "story_id");
462
463 migrationBuilder.CreateIndex(
464 name: "IX_story_user_id",
465 table: "story",
466 column: "user_id");
467 }
468
469 /// <inheritdoc />
470 protected override void Down(MigrationBuilder migrationBuilder)
471 {
472 migrationBuilder.DropTable(
473 name: "admins");
474
475 migrationBuilder.DropTable(
476 name: "collaboration");
477
478 migrationBuilder.DropTable(
479 name: "comment");
480
481 migrationBuilder.DropTable(
482 name: "has_genre");
483
484 migrationBuilder.DropTable(
485 name: "likes");
486
487 migrationBuilder.DropTable(
488 name: "need_approval");
489
490 migrationBuilder.DropTable(
491 name: "notification");
492
493 migrationBuilder.DropTable(
494 name: "reading_list_items");
495
496 migrationBuilder.DropTable(
497 name: "regular_user");
498
499 migrationBuilder.DropTable(
500 name: "genre");
501
502 migrationBuilder.DropTable(
503 name: "ai_suggestion");
504
505 migrationBuilder.DropTable(
506 name: "chapter");
507
508 migrationBuilder.DropTable(
509 name: "reading_list");
510
511 migrationBuilder.DropTable(
512 name: "story");
513
514 migrationBuilder.DropTable(
515 name: "writer");
516
517 migrationBuilder.DropTable(
518 name: "users");
519 }
520 }
521}
Note: See TracBrowser for help on using the repository browser.