using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblUnitsInTemplateAddUnitFieldValueId : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropPrimaryKey(
                name: "PK_UnitsInTemplates",
                schema: "job",
                table: "UnitsInTemplates");

            migrationBuilder.AddColumn<Guid>(
                name: "UnitFieldValueId",
                schema: "job",
                table: "UnitsInTemplates",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("d6485475-d4c5-47f0-a48f-b364a6321cc4"));

            migrationBuilder.AddPrimaryKey(
                name: "PK_UnitsInTemplates",
                schema: "job",
                table: "UnitsInTemplates",
                columns: new[] { "TemplateId", "UnitId", "UnitFieldValueId" });

            migrationBuilder.UpdateData(
                schema: "task",
                table: "Types",
                keyColumn: "Code",
                keyValue: 0,
                column: "MaxExecutionTimeMinutes",
                value: 60);

            migrationBuilder.CreateIndex(
                name: "IX_UnitsInTemplates_UnitFieldValueId",
                schema: "job",
                table: "UnitsInTemplates",
                column: "UnitFieldValueId");

            migrationBuilder.AddForeignKey(
                name: "FK_UnitsInTemplates_FieldValues_UnitFieldValueId",
                schema: "job",
                table: "UnitsInTemplates",
                column: "UnitFieldValueId",
                principalSchema: "unit",
                principalTable: "FieldValues",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_UnitsInTemplates_FieldValues_UnitFieldValueId",
                schema: "job",
                table: "UnitsInTemplates");

            migrationBuilder.DropPrimaryKey(
                name: "PK_UnitsInTemplates",
                schema: "job",
                table: "UnitsInTemplates");

            migrationBuilder.DropIndex(
                name: "IX_UnitsInTemplates_UnitFieldValueId",
                schema: "job",
                table: "UnitsInTemplates");

            migrationBuilder.DropColumn(
                name: "UnitFieldValueId",
                schema: "job",
                table: "UnitsInTemplates");

            migrationBuilder.AddPrimaryKey(
                name: "PK_UnitsInTemplates",
                schema: "job",
                table: "UnitsInTemplates",
                columns: new[] { "TemplateId", "UnitId" });

            migrationBuilder.UpdateData(
                schema: "task",
                table: "Types",
                keyColumn: "Code",
                keyValue: 0,
                column: "MaxExecutionTimeMinutes",
                value: 30);
        }
    }
}
