/*
  Warnings:

  - You are about to drop the `db_activites_quiz` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `db_activites_quiz_option` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `db_activities` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `db_topics` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE `db_activites_quiz` DROP FOREIGN KEY `db_activites_quiz_activityId_fkey`;

-- DropForeignKey
ALTER TABLE `db_activites_quiz_option` DROP FOREIGN KEY `db_activites_quiz_option_quizId_fkey`;

-- DropForeignKey
ALTER TABLE `db_activities` DROP FOREIGN KEY `db_activities_activitesTypeId_fkey`;

-- DropForeignKey
ALTER TABLE `db_activities` DROP FOREIGN KEY `db_activities_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_calender` DROP FOREIGN KEY `db_calender_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_learning_journey_sequence` DROP FOREIGN KEY `db_learning_journey_sequence_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_student_activities_answer_log` DROP FOREIGN KEY `db_student_activities_answer_log_quizId_fkey`;

-- DropForeignKey
ALTER TABLE `db_student_activities_log` DROP FOREIGN KEY `db_student_activities_log_activityId_fkey`;

-- DropForeignKey
ALTER TABLE `db_student_activities_log` DROP FOREIGN KEY `db_student_activities_log_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_student_topic_progress` DROP FOREIGN KEY `db_student_topic_progress_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_teacher_activites` DROP FOREIGN KEY `db_teacher_activites_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_teacher_order` DROP FOREIGN KEY `db_teacher_order_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_topics` DROP FOREIGN KEY `db_topics_moduleId_fkey`;

-- DropIndex
DROP INDEX `db_calender_topicId_fkey` ON `db_calender`;

-- DropIndex
DROP INDEX `db_learning_journey_sequence_topicId_fkey` ON `db_learning_journey_sequence`;

-- DropIndex
DROP INDEX `db_student_activities_answer_log_quizId_fkey` ON `db_student_activities_answer_log`;

-- DropIndex
DROP INDEX `db_student_activities_log_activityId_fkey` ON `db_student_activities_log`;

-- DropIndex
DROP INDEX `db_student_activities_log_topicId_fkey` ON `db_student_activities_log`;

-- DropIndex
DROP INDEX `db_student_topic_progress_topicId_fkey` ON `db_student_topic_progress`;

-- DropIndex
DROP INDEX `db_teacher_activites_topicId_fkey` ON `db_teacher_activites`;

-- DropIndex
DROP INDEX `db_teacher_order_topicId_fkey` ON `db_teacher_order`;

-- DropTable
DROP TABLE `db_activites_quiz`;

-- DropTable
DROP TABLE `db_activites_quiz_option`;

-- DropTable
DROP TABLE `db_activities`;

-- DropTable
DROP TABLE `db_topics`;

-- CreateTable
CREATE TABLE `db_courses_topics` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(255) NOT NULL,
    `slug` VARCHAR(255) NOT NULL,
    `description` TEXT NULL,
    `bannerUrl` VARCHAR(255) NULL,
    `thumbnailUrl` VARCHAR(255) NULL,
    `isPublished` BOOLEAN NOT NULL DEFAULT false,
    `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    `index` INTEGER NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `created_by` INTEGER NULL,
    `updated_by` INTEGER NULL,
    `moduleId` INTEGER NOT NULL,

    UNIQUE INDEX `db_courses_topics_slug_key`(`slug`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `db_courses_activities` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(255) NOT NULL,
    `type` VARCHAR(255) NULL,
    `details` TEXT NULL,
    `isPublished` BOOLEAN NOT NULL DEFAULT false,
    `bannerUrl` VARCHAR(255) NULL,
    `thumbnailUrl` VARCHAR(255) NULL,
    `file` VARCHAR(255) NULL,
    `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    `index` INTEGER NULL DEFAULT 1,
    `resourcesType` VARCHAR(255) NULL,
    `isTeacherDownload` BOOLEAN NOT NULL DEFAULT false,
    `isStudentDownload` BOOLEAN NOT NULL DEFAULT false,
    `topicId` INTEGER NOT NULL,
    `activitesTypeId` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `created_by` INTEGER NULL,
    `updated_by` INTEGER NULL,

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

-- CreateTable
CREATE TABLE `db_courses_activites_quiz` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `question` TEXT NULL,
    `difficultyLevel` VARCHAR(255) NULL,
    `mark` VARCHAR(255) NULL,
    `explaination` TEXT NULL,
    `bloomTaxonomy` VARCHAR(255) NULL,
    `isPublished` BOOLEAN NOT NULL DEFAULT false,
    `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    `index` INTEGER NULL DEFAULT 1,
    `questionTime` DOUBLE NULL,
    `answerMethod` VARCHAR(255) NULL,
    `quizType` VARCHAR(10) NULL DEFAULT 'QUIZ',
    `activityId` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `created_by` INTEGER NULL,
    `updated_by` INTEGER NULL,

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

-- CreateTable
CREATE TABLE `db_courses_activites_quiz_option` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `choice` TEXT NULL,
    `answer` BOOLEAN NOT NULL DEFAULT false,
    `isPublished` BOOLEAN NOT NULL DEFAULT false,
    `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    `index` INTEGER NULL DEFAULT 1,
    `quizId` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `created_by` INTEGER NULL,
    `updated_by` INTEGER NULL,

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

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

-- AddForeignKey
ALTER TABLE `db_courses_activities` ADD CONSTRAINT `db_courses_activities_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_courses_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_courses_activities` ADD CONSTRAINT `db_courses_activities_activitesTypeId_fkey` FOREIGN KEY (`activitesTypeId`) REFERENCES `db_activities_type`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

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

-- AddForeignKey
ALTER TABLE `db_teacher_activites` ADD CONSTRAINT `db_teacher_activites_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_courses_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_teacher_order` ADD CONSTRAINT `db_teacher_order_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_courses_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_learning_journey_sequence` ADD CONSTRAINT `db_learning_journey_sequence_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_courses_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_calender` ADD CONSTRAINT `db_calender_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_courses_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_student_activities_log` ADD CONSTRAINT `db_student_activities_log_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_courses_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

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

-- AddForeignKey
ALTER TABLE `db_student_topic_progress` ADD CONSTRAINT `db_student_topic_progress_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_courses_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
