using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Edge.Core.Database.Migrations
{
    public partial class ProcessorMetaConfigDbModel : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ProcessorMetaConfigs",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Name = table.Column<string>(nullable: false),
                    Description = table.Column<string>(nullable: true),
                    Type = table.Column<int>(nullable: false),
                    Activated = table.Column<bool>(nullable: false),
                    TimeStamp = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProcessorMetaConfigs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ProcessorPartsMetaConfigs",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ProcessorMetaConfigId = table.Column<int>(nullable: false),
                    Type = table.Column<int>(nullable: false),
                    FullTypeString = table.Column<string>(nullable: false),
                    ParametersJsonArrayStr = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProcessorPartsMetaConfigs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProcessorPartsMetaConfigs_ProcessorMetaConfigs_ProcessorMetaConfigId",
                        column: x => x.ProcessorMetaConfigId,
                        principalTable: "ProcessorMetaConfigs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ProcessorMetaConfigs_Name",
                table: "ProcessorMetaConfigs",
                column: "Name",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ProcessorMetaConfigs_TimeStamp",
                table: "ProcessorMetaConfigs",
                column: "TimeStamp");

            migrationBuilder.CreateIndex(
                name: "IX_ProcessorPartsMetaConfigs_ProcessorMetaConfigId_Type",
                table: "ProcessorPartsMetaConfigs",
                columns: new[] { "ProcessorMetaConfigId", "Type" },
                unique: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ProcessorPartsMetaConfigs");

            migrationBuilder.DropTable(
                name: "ProcessorMetaConfigs");
        }
    }
}