using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DiunaBI.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class RecordHistory : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "RecordHistory",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RecordId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    LayerId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ChangedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ChangedById = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ChangeType = table.Column<int>(type: "int", nullable: false),
                    Code = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Desc1 = table.Column<string>(type: "nvarchar(max)", maxLength: 10000, nullable: true),
                    ChangedFields = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    ChangesSummary = table.Column<string>(type: "nvarchar(4000)", maxLength: 4000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RecordHistory", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RecordHistory_Users_ChangedById",
                        column: x => x.ChangedById,
                        principalTable: "Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_RecordHistory_ChangedById",
                table: "RecordHistory",
                column: "ChangedById");

            migrationBuilder.CreateIndex(
                name: "IX_RecordHistory_LayerId_ChangedAt",
                table: "RecordHistory",
                columns: new[] { "LayerId", "ChangedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_RecordHistory_RecordId_ChangedAt",
                table: "RecordHistory",
                columns: new[] { "RecordId", "ChangedAt" });
        }

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