-- CreateTable
CREATE TABLE `db_student_practice_log` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `studentId` INTEGER NULL,
    `schoolId` INTEGER NULL,
    `courseId` INTEGER NULL,
    `moduleId` INTEGER NULL,
    `teacherModuleId` INTEGER NULL,
    `schoolCourseId` INTEGER NULL,
    `teacherId` INTEGER NULL,
    `activityId` INTEGER NULL,
    `teacherActivityId` INTEGER NULL,
    `activityType` VARCHAR(191) NULL,
    `type` VARCHAR(191) NULL DEFAULT 'ACTIVITY',
    `totalMark` DOUBLE NULL,
    `obtainMark` DOUBLE NULL,
    `opened` BOOLEAN NULL,
    `openedAt` DATETIME(3) NULL,
    `timeSpent` INTEGER NULL DEFAULT 0,
    `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,
    `createdBy` INTEGER NULL,
    `updatedBy` INTEGER NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `db_student_practice_answer_log` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `studentId` INTEGER NULL,
    `quizId` INTEGER NULL,
    `teacherQuizId` INTEGER NULL,
    `answer` VARCHAR(191) NULL,
    `correctAnswer` VARCHAR(191) NULL,
    `question` TEXT NULL,
    `isRight` BOOLEAN NOT NULL DEFAULT false,
    `score` INTEGER NULL DEFAULT 0,
    `timeSpent` INTEGER NULL DEFAULT 0,
    `studentActivitiesLogId` INTEGER NULL,
    `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,
    `createdBy` INTEGER NULL,
    `updatedBy` INTEGER NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_studentId_fkey` FOREIGN KEY (`studentId`) REFERENCES `db_students`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_schoolId_fkey` FOREIGN KEY (`schoolId`) REFERENCES `db_schools`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_courseId_fkey` FOREIGN KEY (`courseId`) REFERENCES `db_courses`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_moduleId_fkey` FOREIGN KEY (`moduleId`) REFERENCES `db_courses_modules`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_teacherModuleId_fkey` FOREIGN KEY (`teacherModuleId`) REFERENCES `db_teacher_modules`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_schoolCourseId_fkey` FOREIGN KEY (`schoolCourseId`) REFERENCES `db_schools_course`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_teacherId_fkey` FOREIGN KEY (`teacherId`) REFERENCES `db_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_activityId_fkey` FOREIGN KEY (`activityId`) REFERENCES `db_courses_activities`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_log` ADD CONSTRAINT `db_student_practice_log_teacherActivityId_fkey` FOREIGN KEY (`teacherActivityId`) REFERENCES `db_teacher_activites`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_answer_log` ADD CONSTRAINT `db_student_practice_answer_log_studentId_fkey` FOREIGN KEY (`studentId`) REFERENCES `db_students`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_answer_log` ADD CONSTRAINT `db_student_practice_answer_log_quizId_fkey` FOREIGN KEY (`quizId`) REFERENCES `db_courses_activites_quiz`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_answer_log` ADD CONSTRAINT `db_student_practice_answer_log_teacherQuizId_fkey` FOREIGN KEY (`teacherQuizId`) REFERENCES `db_teacher_activites_quiz`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_practice_answer_log` ADD CONSTRAINT `db_student_practice_answer_log_studentActivitiesLogId_fkey` FOREIGN KEY (`studentActivitiesLogId`) REFERENCES `db_student_practice_log`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
