using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace IRaCIS.Core.Infra.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class EmailAttachmentLog : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Attachments",
                table: "EmailLog");

            migrationBuilder.CreateTable(
                name: "EmailAttachmentLog",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EmailLogId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AttachmentName = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false),
                    AttachmentPath = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EmailAttachmentLog", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EmailAttachmentLog_EmailLog_EmailLogId",
                        column: x => x.EmailLogId,
                        principalTable: "EmailLog",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_EmailAttachmentLog_User_CreateUserId",
                        column: x => x.CreateUserId,
                        principalTable: "User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "邮件附件日志");

            migrationBuilder.CreateIndex(
                name: "IX_EmailAttachmentLog_CreateUserId",
                table: "EmailAttachmentLog",
                column: "CreateUserId");

            migrationBuilder.CreateIndex(
                name: "IX_EmailAttachmentLog_EmailLogId",
                table: "EmailAttachmentLog",
                column: "EmailLogId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "EmailAttachmentLog");

            migrationBuilder.AddColumn<string>(
                name: "Attachments",
                table: "EmailLog",
                type: "nvarchar(max)",
                nullable: true);
        }
    }
}
