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

namespace YGNT.QuestionLibrary.Migrations
{
    public partial class add_TestingKnowledge : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "TestingKnowledge",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TestingId = table.Column<int>(nullable: false),
                    KnowledgeId = table.Column<long>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TestingKnowledge", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TestingKnowledge_Testings_TestingId",
                        column: x => x.TestingId,
                        principalTable: "Testings",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Testings_DisciplineId",
                table: "Testings",
                column: "DisciplineId");

            migrationBuilder.CreateIndex(
                name: "IX_Testings_GradeId",
                table: "Testings",
                column: "GradeId");

            migrationBuilder.CreateIndex(
                name: "IX_TestingQuestions_QuestionId",
                table: "TestingQuestions",
                column: "QuestionId");

            migrationBuilder.CreateIndex(
                name: "IX_TestingKnowledge_TestingId",
                table: "TestingKnowledge",
                column: "TestingId");

            migrationBuilder.AddForeignKey(
                name: "FK_TestingQuestions_Questions_QuestionId",
                table: "TestingQuestions",
                column: "QuestionId",
                principalTable: "Questions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Testings_Disciplines_DisciplineId",
                table: "Testings",
                column: "DisciplineId",
                principalTable: "Disciplines",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

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

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

            migrationBuilder.DropForeignKey(
                name: "FK_Testings_Disciplines_DisciplineId",
                table: "Testings");

            migrationBuilder.DropForeignKey(
                name: "FK_Testings_Grades_GradeId",
                table: "Testings");

            migrationBuilder.DropTable(
                name: "TestingKnowledge");

            migrationBuilder.DropIndex(
                name: "IX_Testings_DisciplineId",
                table: "Testings");

            migrationBuilder.DropIndex(
                name: "IX_Testings_GradeId",
                table: "Testings");

            migrationBuilder.DropIndex(
                name: "IX_TestingQuestions_QuestionId",
                table: "TestingQuestions");
        }
    }
}
