using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace TafsirQuran.Infrastructure.Persistence.Migrations { /// public partial class AyahBrowseAndGharaati : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_ListeningProgresses_Episodes_EpisodeId", table: "ListeningProgresses"); migrationBuilder.DropTable( name: "Bookmarks"); migrationBuilder.DropTable( name: "Favorites"); // Episode-based progress cannot map cleanly to Surah/Ayah; reset rows. migrationBuilder.Sql("DELETE FROM [ListeningProgresses];"); migrationBuilder.DropIndex( name: "IX_ListeningProgresses_EpisodeId", table: "ListeningProgresses"); migrationBuilder.DropColumn( name: "EpisodeId", table: "ListeningProgresses"); migrationBuilder.AddColumn( name: "TafsirId", table: "ListeningProgresses", type: "uniqueidentifier", nullable: false, defaultValue: new Guid("11111111-1111-1111-1111-111111111111")); migrationBuilder.AddColumn( name: "AyahNumber", table: "ListeningProgresses", type: "int", nullable: false, defaultValue: 1); migrationBuilder.AddColumn( name: "SurahId", table: "ListeningProgresses", type: "int", nullable: false, defaultValue: 1); migrationBuilder.CreateIndex( name: "IX_ListeningProgresses_TafsirId", table: "ListeningProgresses", column: "TafsirId"); migrationBuilder.CreateTable( name: "AyahBookmarks", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), UserId = table.Column(type: "uniqueidentifier", nullable: true), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), TafsirId = table.Column(type: "uniqueidentifier", nullable: false), SurahId = table.Column(type: "int", nullable: false), AyahNumber = table.Column(type: "int", nullable: false), Note = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), CreatedAt = table.Column(type: "datetimeoffset", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AyahBookmarks", x => x.Id); table.ForeignKey( name: "FK_AyahBookmarks_Surahs_SurahId", column: x => x.SurahId, principalTable: "Surahs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AyahBookmarks_Tafsirs_TafsirId", column: x => x.TafsirId, principalTable: "Tafsirs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AyahBookmarks_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "AyahFavorites", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), UserId = table.Column(type: "uniqueidentifier", nullable: true), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), TafsirId = table.Column(type: "uniqueidentifier", nullable: false), SurahId = table.Column(type: "int", nullable: false), AyahNumber = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetimeoffset", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AyahFavorites", x => x.Id); table.ForeignKey( name: "FK_AyahFavorites_Surahs_SurahId", column: x => x.SurahId, principalTable: "Surahs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AyahFavorites_Tafsirs_TafsirId", column: x => x.TafsirId, principalTable: "Tafsirs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AyahFavorites_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "SurahBookmarks", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), UserId = table.Column(type: "uniqueidentifier", nullable: true), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), TafsirId = table.Column(type: "uniqueidentifier", nullable: false), SurahId = table.Column(type: "int", nullable: false), Note = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), CreatedAt = table.Column(type: "datetimeoffset", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SurahBookmarks", x => x.Id); table.ForeignKey( name: "FK_SurahBookmarks_Surahs_SurahId", column: x => x.SurahId, principalTable: "Surahs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SurahBookmarks_Tafsirs_TafsirId", column: x => x.TafsirId, principalTable: "Tafsirs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SurahBookmarks_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "TafsirAyahContents", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), TafsirId = table.Column(type: "uniqueidentifier", nullable: false), SurahId = table.Column(type: "int", nullable: false), AyahNumber = table.Column(type: "int", nullable: false), NotesHtml = table.Column(type: "nvarchar(max)", nullable: true), MessagesHtml = table.Column(type: "nvarchar(max)", nullable: true), VideoEmbedUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), AudioPath = table.Column(type: "nvarchar(400)", maxLength: 400, nullable: true), UpdatedAt = table.Column(type: "datetimeoffset", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TafsirAyahContents", x => x.Id); table.ForeignKey( name: "FK_TafsirAyahContents_Surahs_SurahId", column: x => x.SurahId, principalTable: "Surahs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_TafsirAyahContents_Tafsirs_TafsirId", column: x => x.TafsirId, principalTable: "Tafsirs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_ListeningProgresses_SurahId", table: "ListeningProgresses", column: "SurahId"); migrationBuilder.CreateIndex( name: "IX_AyahBookmarks_DeviceId_UserId_TafsirId_SurahId_AyahNumber", table: "AyahBookmarks", columns: new[] { "DeviceId", "UserId", "TafsirId", "SurahId", "AyahNumber" }, unique: true, filter: "[UserId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_AyahBookmarks_SurahId", table: "AyahBookmarks", column: "SurahId"); migrationBuilder.CreateIndex( name: "IX_AyahBookmarks_TafsirId", table: "AyahBookmarks", column: "TafsirId"); migrationBuilder.CreateIndex( name: "IX_AyahBookmarks_UserId", table: "AyahBookmarks", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_AyahFavorites_DeviceId_UserId_TafsirId_SurahId_AyahNumber", table: "AyahFavorites", columns: new[] { "DeviceId", "UserId", "TafsirId", "SurahId", "AyahNumber" }, unique: true, filter: "[UserId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_AyahFavorites_SurahId", table: "AyahFavorites", column: "SurahId"); migrationBuilder.CreateIndex( name: "IX_AyahFavorites_TafsirId", table: "AyahFavorites", column: "TafsirId"); migrationBuilder.CreateIndex( name: "IX_AyahFavorites_UserId", table: "AyahFavorites", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_SurahBookmarks_DeviceId_UserId_TafsirId_SurahId", table: "SurahBookmarks", columns: new[] { "DeviceId", "UserId", "TafsirId", "SurahId" }, unique: true, filter: "[UserId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_SurahBookmarks_SurahId", table: "SurahBookmarks", column: "SurahId"); migrationBuilder.CreateIndex( name: "IX_SurahBookmarks_TafsirId", table: "SurahBookmarks", column: "TafsirId"); migrationBuilder.CreateIndex( name: "IX_SurahBookmarks_UserId", table: "SurahBookmarks", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_TafsirAyahContents_SurahId", table: "TafsirAyahContents", column: "SurahId"); migrationBuilder.CreateIndex( name: "IX_TafsirAyahContents_TafsirId_SurahId_AyahNumber", table: "TafsirAyahContents", columns: new[] { "TafsirId", "SurahId", "AyahNumber" }, unique: true); migrationBuilder.AddForeignKey( name: "FK_ListeningProgresses_Surahs_SurahId", table: "ListeningProgresses", column: "SurahId", principalTable: "Surahs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); migrationBuilder.AddForeignKey( name: "FK_ListeningProgresses_Tafsirs_TafsirId", table: "ListeningProgresses", column: "TafsirId", principalTable: "Tafsirs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_ListeningProgresses_Surahs_SurahId", table: "ListeningProgresses"); migrationBuilder.DropForeignKey( name: "FK_ListeningProgresses_Tafsirs_TafsirId", table: "ListeningProgresses"); migrationBuilder.DropTable( name: "AyahBookmarks"); migrationBuilder.DropTable( name: "AyahFavorites"); migrationBuilder.DropTable( name: "SurahBookmarks"); migrationBuilder.DropTable( name: "TafsirAyahContents"); migrationBuilder.DropIndex( name: "IX_ListeningProgresses_SurahId", table: "ListeningProgresses"); migrationBuilder.DropColumn( name: "AyahNumber", table: "ListeningProgresses"); migrationBuilder.DropColumn( name: "SurahId", table: "ListeningProgresses"); migrationBuilder.RenameColumn( name: "TafsirId", table: "ListeningProgresses", newName: "EpisodeId"); migrationBuilder.RenameIndex( name: "IX_ListeningProgresses_TafsirId", table: "ListeningProgresses", newName: "IX_ListeningProgresses_EpisodeId"); migrationBuilder.CreateTable( name: "Bookmarks", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), EpisodeId = table.Column(type: "uniqueidentifier", nullable: false), UserId = table.Column(type: "uniqueidentifier", nullable: true), CreatedAt = table.Column(type: "datetimeoffset", nullable: false), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false), Note = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true) }, constraints: table => { table.PrimaryKey("PK_Bookmarks", x => x.Id); table.ForeignKey( name: "FK_Bookmarks_Episodes_EpisodeId", column: x => x.EpisodeId, principalTable: "Episodes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Bookmarks_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Favorites", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), EpisodeId = table.Column(type: "uniqueidentifier", nullable: false), UserId = table.Column(type: "uniqueidentifier", nullable: true), CreatedAt = table.Column(type: "datetimeoffset", nullable: false), DeviceId = table.Column(type: "nvarchar(64)", maxLength: 64, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Favorites", x => x.Id); table.ForeignKey( name: "FK_Favorites_Episodes_EpisodeId", column: x => x.EpisodeId, principalTable: "Episodes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Favorites_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateIndex( name: "IX_Bookmarks_DeviceId_UserId_EpisodeId", table: "Bookmarks", columns: new[] { "DeviceId", "UserId", "EpisodeId" }, unique: true, filter: "[UserId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Bookmarks_EpisodeId", table: "Bookmarks", column: "EpisodeId"); migrationBuilder.CreateIndex( name: "IX_Bookmarks_UserId", table: "Bookmarks", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Favorites_DeviceId_UserId_EpisodeId", table: "Favorites", columns: new[] { "DeviceId", "UserId", "EpisodeId" }, unique: true, filter: "[UserId] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_Favorites_EpisodeId", table: "Favorites", column: "EpisodeId"); migrationBuilder.CreateIndex( name: "IX_Favorites_UserId", table: "Favorites", column: "UserId"); migrationBuilder.AddForeignKey( name: "FK_ListeningProgresses_Episodes_EpisodeId", table: "ListeningProgresses", column: "EpisodeId", principalTable: "Episodes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); } } }