using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace IRaCIS.Core.Infra.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class modifyAudictDoc : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AuditDocumentClosure",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AncestorId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "祖先"),
                    DescendantId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "后代"),
                    Depth = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AuditDocumentClosure", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AuditDocumentClosure_AuditDocument_AncestorId",
                        column: x => x.AncestorId,
                        principalTable: "AuditDocument",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AuditDocumentClosure_AuditDocument_DescendantId",
                        column: x => x.DescendantId,
                        principalTable: "AuditDocument",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AuditDocument_MainFileId",
                table: "AuditDocument",
                column: "MainFileId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditDocumentClosure_AncestorId",
                table: "AuditDocumentClosure",
                column: "AncestorId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditDocumentClosure_DescendantId",
                table: "AuditDocumentClosure",
                column: "DescendantId");

            migrationBuilder.AddForeignKey(
                name: "FK_AuditDocument_AuditDocument_MainFileId",
                table: "AuditDocument",
                column: "MainFileId",
                principalTable: "AuditDocument",
                principalColumn: "Id");
        }

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

            migrationBuilder.DropTable(
                name: "AuditDocumentClosure");

            migrationBuilder.DropIndex(
                name: "IX_AuditDocument_MainFileId",
                table: "AuditDocument");
        }
    }
}
