using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace ChapterX.Infrastructure.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Genres", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Genres", x => x.Id); }); migrationBuilder.CreateTable( name: "Notifications", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Content = table.Column(type: "text", nullable: false), IsRead = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), ContentTypes = table.Column(type: "integer[]", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Notifications", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Username = table.Column(type: "text", nullable: false), Email = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false), Surname = table.Column(type: "text", nullable: false), Password = table.Column(type: "text", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Admins", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Admins", x => x.Id); table.ForeignKey( name: "FK_Admins_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ReadingLists", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), Content = table.Column(type: "text", nullable: true), IsPublic = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UserId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ReadingLists", x => x.Id); table.ForeignKey( name: "FK_ReadingLists_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RegularUsers", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_RegularUsers", x => x.Id); table.ForeignKey( name: "FK_RegularUsers_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Writers", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), Bio = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Writers", x => x.Id); table.ForeignKey( name: "FK_Writers_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Stories", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MatureContent = table.Column(type: "boolean", nullable: false), ShortDescription = table.Column(type: "text", nullable: false), Image = table.Column(type: "text", nullable: true), Content = table.Column(type: "text", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UserId = table.Column(type: "integer", nullable: false), WriterId = table.Column(type: "integer", nullable: false), Statuses = table.Column(type: "integer[]", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Stories", x => x.Id); table.ForeignKey( name: "FK_Stories_Writers_WriterId", column: x => x.WriterId, principalTable: "Writers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AISuggestions", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), OriginalText = table.Column(type: "text", nullable: false), SuggestedText = table.Column(type: "text", nullable: false), Accepted = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), AppliedAt = table.Column(type: "timestamp with time zone", nullable: true), StoryId = table.Column(type: "integer", nullable: false), SuggestionTypes = table.Column(type: "integer[]", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AISuggestions", x => x.Id); table.ForeignKey( name: "FK_AISuggestions_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Chapters", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Number = table.Column(type: "integer", nullable: false), Name = table.Column(type: "text", nullable: false), Title = table.Column(type: "text", nullable: false), Content = table.Column(type: "text", nullable: false), WordCount = table.Column(type: "integer", nullable: true), Rating = table.Column(type: "numeric", nullable: true), PublishedAt = table.Column(type: "timestamp with time zone", nullable: false), ViewCount = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), StoryId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Chapters", x => x.Id); table.ForeignKey( name: "FK_Chapters_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Collaborations", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), StoryId = table.Column(type: "integer", nullable: false), Role = table.Column(type: "text", nullable: false), JoinedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Collaborations", x => x.Id); table.ForeignKey( name: "FK_Collaborations_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Collaborations_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Comments", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Content = table.Column(type: "text", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), UserId = table.Column(type: "integer", nullable: false), StoryId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Comments", x => x.Id); table.ForeignKey( name: "FK_Comments_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Comments_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "HasGenres", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), StoryId = table.Column(type: "integer", nullable: false), GenreId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_HasGenres", x => x.Id); table.ForeignKey( name: "FK_HasGenres_Genres_GenreId", column: x => x.GenreId, principalTable: "Genres", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_HasGenres_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Notifies", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), NotificationId = table.Column(type: "integer", nullable: false), IsRead = table.Column(type: "boolean", nullable: false), StoryId = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Notifies", x => x.Id); table.ForeignKey( name: "FK_Notifies_Notifications_NotificationId", column: x => x.NotificationId, principalTable: "Notifications", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Notifies_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id"); table.ForeignKey( name: "FK_Notifies_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ReadingListItems", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ReadingListId = table.Column(type: "integer", nullable: false), StoryId = table.Column(type: "integer", nullable: false), AddedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ReadingListItems", x => x.Id); table.ForeignKey( name: "FK_ReadingListItems_ReadingLists_ReadingListId", column: x => x.ReadingListId, principalTable: "ReadingLists", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ReadingListItems_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Likes", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), ChapterId = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), StoryId = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Likes", x => x.Id); table.ForeignKey( name: "FK_Likes_Chapters_ChapterId", column: x => x.ChapterId, principalTable: "Chapters", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Likes_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id"); table.ForeignKey( name: "FK_Likes_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "NeedApprovals", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), StoryId = table.Column(type: "integer", nullable: false), AdminId = table.Column(type: "integer", nullable: false), Approved = table.Column(type: "boolean", nullable: false), RequestedAt = table.Column(type: "timestamp with time zone", nullable: false), AISuggestionId = table.Column(type: "integer", nullable: true), ChapterId = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_NeedApprovals", x => x.Id); table.ForeignKey( name: "FK_NeedApprovals_AISuggestions_AISuggestionId", column: x => x.AISuggestionId, principalTable: "AISuggestions", principalColumn: "Id"); table.ForeignKey( name: "FK_NeedApprovals_Admins_AdminId", column: x => x.AdminId, principalTable: "Admins", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_NeedApprovals_Chapters_ChapterId", column: x => x.ChapterId, principalTable: "Chapters", principalColumn: "Id"); table.ForeignKey( name: "FK_NeedApprovals_Stories_StoryId", column: x => x.StoryId, principalTable: "Stories", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Admins_UserId", table: "Admins", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_AISuggestions_StoryId", table: "AISuggestions", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Chapters_StoryId", table: "Chapters", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Collaborations_StoryId", table: "Collaborations", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Collaborations_UserId", table: "Collaborations", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Comments_StoryId", table: "Comments", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Comments_UserId", table: "Comments", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_HasGenres_GenreId", table: "HasGenres", column: "GenreId"); migrationBuilder.CreateIndex( name: "IX_HasGenres_StoryId", table: "HasGenres", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Likes_ChapterId", table: "Likes", column: "ChapterId"); migrationBuilder.CreateIndex( name: "IX_Likes_StoryId", table: "Likes", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Likes_UserId", table: "Likes", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_NeedApprovals_AdminId", table: "NeedApprovals", column: "AdminId"); migrationBuilder.CreateIndex( name: "IX_NeedApprovals_AISuggestionId", table: "NeedApprovals", column: "AISuggestionId"); migrationBuilder.CreateIndex( name: "IX_NeedApprovals_ChapterId", table: "NeedApprovals", column: "ChapterId"); migrationBuilder.CreateIndex( name: "IX_NeedApprovals_StoryId", table: "NeedApprovals", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Notifies_NotificationId", table: "Notifies", column: "NotificationId"); migrationBuilder.CreateIndex( name: "IX_Notifies_StoryId", table: "Notifies", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_Notifies_UserId", table: "Notifies", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_ReadingListItems_ReadingListId", table: "ReadingListItems", column: "ReadingListId"); migrationBuilder.CreateIndex( name: "IX_ReadingListItems_StoryId", table: "ReadingListItems", column: "StoryId"); migrationBuilder.CreateIndex( name: "IX_ReadingLists_UserId", table: "ReadingLists", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_RegularUsers_UserId", table: "RegularUsers", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_Stories_WriterId", table: "Stories", column: "WriterId"); migrationBuilder.CreateIndex( name: "IX_Writers_UserId", table: "Writers", column: "UserId", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Collaborations"); migrationBuilder.DropTable( name: "Comments"); migrationBuilder.DropTable( name: "HasGenres"); migrationBuilder.DropTable( name: "Likes"); migrationBuilder.DropTable( name: "NeedApprovals"); migrationBuilder.DropTable( name: "Notifies"); migrationBuilder.DropTable( name: "ReadingListItems"); migrationBuilder.DropTable( name: "RegularUsers"); migrationBuilder.DropTable( name: "Genres"); migrationBuilder.DropTable( name: "AISuggestions"); migrationBuilder.DropTable( name: "Admins"); migrationBuilder.DropTable( name: "Chapters"); migrationBuilder.DropTable( name: "Notifications"); migrationBuilder.DropTable( name: "ReadingLists"); migrationBuilder.DropTable( name: "Stories"); migrationBuilder.DropTable( name: "Writers"); migrationBuilder.DropTable( name: "Users"); } } }