using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblUnitInFieldsRemove : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "UnitInFields",
                schema: "unit");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "UnitInFields",
                schema: "unit",
                columns: table => new
                {
                    UnitId = table.Column<Guid>(type: "uuid", nullable: false),
                    FieldId = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UnitInFields", x => new { x.UnitId, x.FieldId });
                    table.ForeignKey(
                        name: "FK_UnitInFields_Fields_FieldId",
                        column: x => x.FieldId,
                        principalSchema: "unit",
                        principalTable: "Fields",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_UnitInFields_Units_UnitId",
                        column: x => x.UnitId,
                        principalSchema: "unit",
                        principalTable: "Units",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Справочник полей ЭК");

            migrationBuilder.CreateIndex(
                name: "IX_UnitInFields_FieldId",
                schema: "unit",
                table: "UnitInFields",
                column: "FieldId");
        }
    }
}
