using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace IRaCIS.Core.Infra.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class addfile : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "CommonUploadRecordId",
                table: "TrialSiteSurvey",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "CommonUploadRecord",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FileType = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false, comment: "文件类型"),
                    FileName = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false),
                    FileSize = table.Column<long>(type: "bigint", nullable: false),
                    Path = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CommonUploadRecord", x => x.Id)
                        .Annotation("SqlServer:Clustered", false);
                    table.ForeignKey(
                        name: "FK_CommonUploadRecord_User_CreateUserId",
                        column: x => x.CreateUserId,
                        principalTable: "User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            //migrationBuilder.CreateIndex(
            //    name: "IX_CommonUploadRecord_CreateTime",
            //    table: "CommonUploadRecord",
            //    column: "CreateTime")
            //    .Annotation("SqlServer:Clustered", true);

            //migrationBuilder.AddForeignKey(
            //    name: "FK_TrialSiteSurvey_CommonUploadRecord_CommonUploadRecordId",
            //    table: "TrialSiteSurvey",
            //    column: "CommonUploadRecordId",
            //    principalTable: "CommonUploadRecord",
            //    principalColumn: "Id");
        }

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

            migrationBuilder.DropTable(
                name: "CommonUploadRecord");

            migrationBuilder.DropColumn(
                name: "CommonUploadRecordId",
                table: "TrialSiteSurvey");
        }
    }
}
