using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace NexusReader.Data.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class FixKnowledgeUnitEbookId : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_KnowledgeUnits_SourceId",
                table: "KnowledgeUnits");

            migrationBuilder.DropColumn(
                name: "SourceId",
                table: "KnowledgeUnits");

            migrationBuilder.AddColumn<Guid>(
                name: "EbookId",
                table: "KnowledgeUnits",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.CreateIndex(
                name: "IX_KnowledgeUnits_EbookId",
                table: "KnowledgeUnits",
                column: "EbookId");

            migrationBuilder.AddForeignKey(
                name: "FK_KnowledgeUnits_Ebooks_EbookId",
                table: "KnowledgeUnits",
                column: "EbookId",
                principalTable: "Ebooks",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_KnowledgeUnits_Ebooks_EbookId",
                table: "KnowledgeUnits");

            migrationBuilder.DropIndex(
                name: "IX_KnowledgeUnits_EbookId",
                table: "KnowledgeUnits");

            migrationBuilder.DropColumn(
                name: "EbookId",
                table: "KnowledgeUnits");

            migrationBuilder.AddColumn<string>(
                name: "SourceId",
                table: "KnowledgeUnits",
                type: "character varying(128)",
                maxLength: 128,
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateIndex(
                name: "IX_KnowledgeUnits_SourceId",
                table: "KnowledgeUnits",
                column: "SourceId");
        }
    }
}
