using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace YGNT.QuestionLibrary.Migrations
{
    public partial class grade : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Disciplines_EducationCategories_EducationCategoryId",
                table: "Disciplines");

            migrationBuilder.DropIndex(
                name: "IX_Disciplines_EducationCategoryId",
                table: "Disciplines");

            migrationBuilder.DropColumn(
                name: "EducationCategoryId",
                table: "Disciplines");

            migrationBuilder.AddColumn<int>(
                name: "GradeId",
                table: "Disciplines",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "Grades",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(maxLength: 30, nullable: false),
                    EducationCategoryId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Grades", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Grades_EducationCategories_EducationCategoryId",
                        column: x => x.EducationCategoryId,
                        principalTable: "EducationCategories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Disciplines_GradeId",
                table: "Disciplines",
                column: "GradeId");

            migrationBuilder.CreateIndex(
                name: "IX_Grades_EducationCategoryId",
                table: "Grades",
                column: "EducationCategoryId");

            migrationBuilder.AddForeignKey(
                name: "FK_Disciplines_Grades_GradeId",
                table: "Disciplines",
                column: "GradeId",
                principalTable: "Grades",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Disciplines_Grades_GradeId",
                table: "Disciplines");

            migrationBuilder.DropTable(
                name: "Grades");

            migrationBuilder.DropIndex(
                name: "IX_Disciplines_GradeId",
                table: "Disciplines");

            migrationBuilder.DropColumn(
                name: "GradeId",
                table: "Disciplines");

            migrationBuilder.AddColumn<int>(
                name: "EducationCategoryId",
                table: "Disciplines",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateIndex(
                name: "IX_Disciplines_EducationCategoryId",
                table: "Disciplines",
                column: "EducationCategoryId");

            migrationBuilder.AddForeignKey(
                name: "FK_Disciplines_EducationCategories_EducationCategoryId",
                table: "Disciplines",
                column: "EducationCategoryId",
                principalTable: "EducationCategories",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
