using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblJobRelationshipFiltersCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "RelationshipFilters",
                schema: "job",
                columns: table => new
                {
                    UnitFilterId = table.Column<Guid>(type: "uuid", nullable: false),
                    FieldId = table.Column<Guid>(type: "uuid", nullable: false),
                    IsParent = table.Column<bool>(type: "boolean", nullable: false),
                    ValueMask = table.Column<string>(type: "text", nullable: false),
                    IsFullMatch = table.Column<bool>(type: "boolean", nullable: false),
                    IsInverse = table.Column<bool>(type: "boolean", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RelationshipFilters", x => new { x.UnitFilterId, x.FieldId });
                    table.ForeignKey(
                        name: "FK_RelationshipFilters_Fields_FieldId",
                        column: x => x.FieldId,
                        principalSchema: "unit",
                        principalTable: "Fields",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_RelationshipFilters_UnitFilters_UnitFilterId",
                        column: x => x.UnitFilterId,
                        principalSchema: "job",
                        principalTable: "UnitFilters",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Таблица фильтров связей ЭК");

            migrationBuilder.CreateIndex(
                name: "IX_RelationshipFilters_FieldId",
                schema: "job",
                table: "RelationshipFilters",
                column: "FieldId");
        }

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