using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TechHelper.Server.Migrations
{
    /// <inheritdoc />
    public partial class temp_1 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_assignment_attachments_assignments_assignment_id",
                table: "assignment_attachments");

            migrationBuilder.DropForeignKey(
                name: "FK_assignment_questions_QuestionContexts_description",
                table: "assignment_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_assignment_questions_assignment_questions_parent_question_gr~",
                table: "assignment_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_assignment_questions_question_types_QuestionTypeId",
                table: "assignment_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_assignment_questions_questions_question_id",
                table: "assignment_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_assignments_AspNetUsers_created_by",
                table: "assignments");

            migrationBuilder.DropForeignKey(
                name: "FK_assignments_assignment_questions_exam_struct_id",
                table: "assignments");

            migrationBuilder.DropForeignKey(
                name: "FK_assignments_exam_type_exam_type_id",
                table: "assignments");

            migrationBuilder.DropForeignKey(
                name: "FK_assignments_subjects_subject_id",
                table: "assignments");

            migrationBuilder.DropForeignKey(
                name: "FK_submission_details_assignment_questions_assignment_question_~",
                table: "submission_details");

            migrationBuilder.DropForeignKey(
                name: "FK_submissions_assignments_exam_id",
                table: "submissions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_assignments",
                table: "assignments");

            migrationBuilder.DropPrimaryKey(
                name: "PK_assignment_questions",
                table: "assignment_questions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_assignment_attachments",
                table: "assignment_attachments");

            migrationBuilder.RenameTable(
                name: "assignments",
                newName: "exams");

            migrationBuilder.RenameTable(
                name: "assignment_questions",
                newName: "exam_questions");

            migrationBuilder.RenameTable(
                name: "assignment_attachments",
                newName: "exam_attachments");

            migrationBuilder.RenameColumn(
                name: "assignment_question_id",
                table: "submission_details",
                newName: "exam_question_id");

            migrationBuilder.RenameIndex(
                name: "IX_submission_details_assignment_question_id",
                table: "submission_details",
                newName: "IX_submission_details_exam_question_id");

            migrationBuilder.RenameIndex(
                name: "IX_assignments_subject_id",
                table: "exams",
                newName: "IX_exams_subject_id");

            migrationBuilder.RenameIndex(
                name: "IX_assignments_exam_type_id",
                table: "exams",
                newName: "IX_exams_exam_type_id");

            migrationBuilder.RenameIndex(
                name: "IX_assignments_exam_struct_id",
                table: "exams",
                newName: "IX_exams_exam_struct_id");

            migrationBuilder.RenameIndex(
                name: "IX_assignments_created_by",
                table: "exams",
                newName: "IX_exams_created_by");

            migrationBuilder.RenameIndex(
                name: "IX_assignment_questions_QuestionTypeId",
                table: "exam_questions",
                newName: "IX_exam_questions_QuestionTypeId");

            migrationBuilder.RenameIndex(
                name: "IX_assignment_questions_question_id",
                table: "exam_questions",
                newName: "IX_exam_questions_question_id");

            migrationBuilder.RenameIndex(
                name: "IX_assignment_questions_parent_question_group_id",
                table: "exam_questions",
                newName: "IX_exam_questions_parent_question_group_id");

            migrationBuilder.RenameIndex(
                name: "IX_assignment_questions_description",
                table: "exam_questions",
                newName: "IX_exam_questions_description");

            migrationBuilder.RenameColumn(
                name: "assignment_id",
                table: "exam_attachments",
                newName: "exam_id");

            migrationBuilder.RenameIndex(
                name: "IX_assignment_attachments_assignment_id",
                table: "exam_attachments",
                newName: "IX_exam_attachments_exam_id");

            migrationBuilder.AlterColumn<float>(
                name: "TotalScore",
                table: "submissions",
                type: "float",
                nullable: false,
                oldClrType: typeof(byte),
                oldType: "tinyint unsigned");

            migrationBuilder.AddColumn<byte>(
                name: "exam_struct_type",
                table: "exam_questions",
                type: "tinyint unsigned",
                nullable: false,
                defaultValue: (byte)0);

            migrationBuilder.AddPrimaryKey(
                name: "PK_exams",
                table: "exams",
                column: "id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_exam_questions",
                table: "exam_questions",
                column: "id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_exam_attachments",
                table: "exam_attachments",
                column: "id");

            migrationBuilder.AddForeignKey(
                name: "FK_exam_attachments_exams_exam_id",
                table: "exam_attachments",
                column: "exam_id",
                principalTable: "exams",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_exam_questions_QuestionContexts_description",
                table: "exam_questions",
                column: "description",
                principalTable: "QuestionContexts",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_exam_questions_exam_questions_parent_question_group_id",
                table: "exam_questions",
                column: "parent_question_group_id",
                principalTable: "exam_questions",
                principalColumn: "id");

            migrationBuilder.AddForeignKey(
                name: "FK_exam_questions_question_types_QuestionTypeId",
                table: "exam_questions",
                column: "QuestionTypeId",
                principalTable: "question_types",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_exam_questions_questions_question_id",
                table: "exam_questions",
                column: "question_id",
                principalTable: "questions",
                principalColumn: "id");

            migrationBuilder.AddForeignKey(
                name: "FK_exams_AspNetUsers_created_by",
                table: "exams",
                column: "created_by",
                principalTable: "AspNetUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_exams_exam_questions_exam_struct_id",
                table: "exams",
                column: "exam_struct_id",
                principalTable: "exam_questions",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_exams_exam_type_exam_type_id",
                table: "exams",
                column: "exam_type_id",
                principalTable: "exam_type",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_exams_subjects_subject_id",
                table: "exams",
                column: "subject_id",
                principalTable: "subjects",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_submission_details_exam_questions_exam_question_id",
                table: "submission_details",
                column: "exam_question_id",
                principalTable: "exam_questions",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_submissions_exams_exam_id",
                table: "submissions",
                column: "exam_id",
                principalTable: "exams",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_exam_attachments_exams_exam_id",
                table: "exam_attachments");

            migrationBuilder.DropForeignKey(
                name: "FK_exam_questions_QuestionContexts_description",
                table: "exam_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_exam_questions_exam_questions_parent_question_group_id",
                table: "exam_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_exam_questions_question_types_QuestionTypeId",
                table: "exam_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_exam_questions_questions_question_id",
                table: "exam_questions");

            migrationBuilder.DropForeignKey(
                name: "FK_exams_AspNetUsers_created_by",
                table: "exams");

            migrationBuilder.DropForeignKey(
                name: "FK_exams_exam_questions_exam_struct_id",
                table: "exams");

            migrationBuilder.DropForeignKey(
                name: "FK_exams_exam_type_exam_type_id",
                table: "exams");

            migrationBuilder.DropForeignKey(
                name: "FK_exams_subjects_subject_id",
                table: "exams");

            migrationBuilder.DropForeignKey(
                name: "FK_submission_details_exam_questions_exam_question_id",
                table: "submission_details");

            migrationBuilder.DropForeignKey(
                name: "FK_submissions_exams_exam_id",
                table: "submissions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_exams",
                table: "exams");

            migrationBuilder.DropPrimaryKey(
                name: "PK_exam_questions",
                table: "exam_questions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_exam_attachments",
                table: "exam_attachments");

            migrationBuilder.DropColumn(
                name: "exam_struct_type",
                table: "exam_questions");

            migrationBuilder.RenameTable(
                name: "exams",
                newName: "assignments");

            migrationBuilder.RenameTable(
                name: "exam_questions",
                newName: "assignment_questions");

            migrationBuilder.RenameTable(
                name: "exam_attachments",
                newName: "assignment_attachments");

            migrationBuilder.RenameColumn(
                name: "exam_question_id",
                table: "submission_details",
                newName: "assignment_question_id");

            migrationBuilder.RenameIndex(
                name: "IX_submission_details_exam_question_id",
                table: "submission_details",
                newName: "IX_submission_details_assignment_question_id");

            migrationBuilder.RenameIndex(
                name: "IX_exams_subject_id",
                table: "assignments",
                newName: "IX_assignments_subject_id");

            migrationBuilder.RenameIndex(
                name: "IX_exams_exam_type_id",
                table: "assignments",
                newName: "IX_assignments_exam_type_id");

            migrationBuilder.RenameIndex(
                name: "IX_exams_exam_struct_id",
                table: "assignments",
                newName: "IX_assignments_exam_struct_id");

            migrationBuilder.RenameIndex(
                name: "IX_exams_created_by",
                table: "assignments",
                newName: "IX_assignments_created_by");

            migrationBuilder.RenameIndex(
                name: "IX_exam_questions_QuestionTypeId",
                table: "assignment_questions",
                newName: "IX_assignment_questions_QuestionTypeId");

            migrationBuilder.RenameIndex(
                name: "IX_exam_questions_question_id",
                table: "assignment_questions",
                newName: "IX_assignment_questions_question_id");

            migrationBuilder.RenameIndex(
                name: "IX_exam_questions_parent_question_group_id",
                table: "assignment_questions",
                newName: "IX_assignment_questions_parent_question_group_id");

            migrationBuilder.RenameIndex(
                name: "IX_exam_questions_description",
                table: "assignment_questions",
                newName: "IX_assignment_questions_description");

            migrationBuilder.RenameColumn(
                name: "exam_id",
                table: "assignment_attachments",
                newName: "assignment_id");

            migrationBuilder.RenameIndex(
                name: "IX_exam_attachments_exam_id",
                table: "assignment_attachments",
                newName: "IX_assignment_attachments_assignment_id");

            migrationBuilder.AlterColumn<byte>(
                name: "TotalScore",
                table: "submissions",
                type: "tinyint unsigned",
                nullable: false,
                oldClrType: typeof(float),
                oldType: "float");

            migrationBuilder.AddPrimaryKey(
                name: "PK_assignments",
                table: "assignments",
                column: "id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_assignment_questions",
                table: "assignment_questions",
                column: "id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_assignment_attachments",
                table: "assignment_attachments",
                column: "id");

            migrationBuilder.AddForeignKey(
                name: "FK_assignment_attachments_assignments_assignment_id",
                table: "assignment_attachments",
                column: "assignment_id",
                principalTable: "assignments",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_assignment_questions_QuestionContexts_description",
                table: "assignment_questions",
                column: "description",
                principalTable: "QuestionContexts",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_assignment_questions_assignment_questions_parent_question_gr~",
                table: "assignment_questions",
                column: "parent_question_group_id",
                principalTable: "assignment_questions",
                principalColumn: "id");

            migrationBuilder.AddForeignKey(
                name: "FK_assignment_questions_question_types_QuestionTypeId",
                table: "assignment_questions",
                column: "QuestionTypeId",
                principalTable: "question_types",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_assignment_questions_questions_question_id",
                table: "assignment_questions",
                column: "question_id",
                principalTable: "questions",
                principalColumn: "id");

            migrationBuilder.AddForeignKey(
                name: "FK_assignments_AspNetUsers_created_by",
                table: "assignments",
                column: "created_by",
                principalTable: "AspNetUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_assignments_assignment_questions_exam_struct_id",
                table: "assignments",
                column: "exam_struct_id",
                principalTable: "assignment_questions",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_assignments_exam_type_exam_type_id",
                table: "assignments",
                column: "exam_type_id",
                principalTable: "exam_type",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_assignments_subjects_subject_id",
                table: "assignments",
                column: "subject_id",
                principalTable: "subjects",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_submission_details_assignment_questions_assignment_question_~",
                table: "submission_details",
                column: "assignment_question_id",
                principalTable: "assignment_questions",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_submissions_assignments_exam_id",
                table: "submissions",
                column: "exam_id",
                principalTable: "assignments",
                principalColumn: "id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
