/*
  Warnings:

  - You are about to drop the column `userId` on the `db_students` table. All the data in the column will be lost.
  - You are about to drop the column `userId` on the `db_teachers` table. All the data in the column will be lost.

*/
-- DropForeignKey
ALTER TABLE `db_announcement` DROP FOREIGN KEY `db_announcement_courseId_fkey`;

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

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

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

-- DropForeignKey
ALTER TABLE `db_class_code` DROP FOREIGN KEY `db_class_code_schoolActivationId_fkey`;

-- DropForeignKey
ALTER TABLE `db_class_code` DROP FOREIGN KEY `db_class_code_schoolCourseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_class_code_map` DROP FOREIGN KEY `db_class_code_map_classCodeId_fkey`;

-- DropForeignKey
ALTER TABLE `db_class_code_map` DROP FOREIGN KEY `db_class_code_map_schoolActivationId_fkey`;

-- DropForeignKey
ALTER TABLE `db_class_code_map` DROP FOREIGN KEY `db_class_code_map_schoolCourseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_class_code_map` DROP FOREIGN KEY `db_class_code_map_studentId_fkey`;

-- DropForeignKey
ALTER TABLE `db_learning_journey` DROP FOREIGN KEY `db_learning_journey_courseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_learning_journey` DROP FOREIGN KEY `db_learning_journey_schoolCourseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_learning_journey_assign` DROP FOREIGN KEY `db_learning_journey_assign_journeyId_fkey`;

-- DropForeignKey
ALTER TABLE `db_learning_journey_assign` DROP FOREIGN KEY `db_learning_journey_assign_studentId_fkey`;

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

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

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

-- DropForeignKey
ALTER TABLE `db_library_activites` DROP FOREIGN KEY `db_library_activites_topicId_fkey`;

-- DropForeignKey
ALTER TABLE `db_notification` DROP FOREIGN KEY `db_notification_userId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_activation_code` DROP FOREIGN KEY `db_schools_activation_code_courseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_activation_code` DROP FOREIGN KEY `db_schools_activation_code_schoolCourseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_activation_code` DROP FOREIGN KEY `db_schools_activation_code_schoolId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_activation_code` DROP FOREIGN KEY `db_schools_activation_code_usedBy_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_course` DROP FOREIGN KEY `db_schools_course_courseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_course` DROP FOREIGN KEY `db_schools_course_schoolId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_course_history` DROP FOREIGN KEY `db_schools_course_history_courseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_course_history` DROP FOREIGN KEY `db_schools_course_history_schoolCourseId_fkey`;

-- DropForeignKey
ALTER TABLE `db_schools_course_history` DROP FOREIGN KEY `db_schools_course_history_schoolId_fkey`;

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

-- DropForeignKey
ALTER TABLE `db_teacher_activites` DROP FOREIGN KEY `db_teacher_activites_teacherTopicId_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_courseId_fkey`;

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

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

-- DropIndex
DROP INDEX `db_announcement_courseId_fkey` ON `db_announcement`;

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

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

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

-- DropIndex
DROP INDEX `db_class_code_schoolActivationId_fkey` ON `db_class_code`;

-- DropIndex
DROP INDEX `db_class_code_schoolCourseId_fkey` ON `db_class_code`;

-- DropIndex
DROP INDEX `db_class_code_map_classCodeId_fkey` ON `db_class_code_map`;

-- DropIndex
DROP INDEX `db_class_code_map_schoolActivationId_fkey` ON `db_class_code_map`;

-- DropIndex
DROP INDEX `db_class_code_map_schoolCourseId_fkey` ON `db_class_code_map`;

-- DropIndex
DROP INDEX `db_class_code_map_studentId_fkey` ON `db_class_code_map`;

-- DropIndex
DROP INDEX `db_learning_journey_courseId_fkey` ON `db_learning_journey`;

-- DropIndex
DROP INDEX `db_learning_journey_schoolCourseId_fkey` ON `db_learning_journey`;

-- DropIndex
DROP INDEX `db_learning_journey_assign_journeyId_fkey` ON `db_learning_journey_assign`;

-- DropIndex
DROP INDEX `db_learning_journey_assign_studentId_fkey` ON `db_learning_journey_assign`;

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

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

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

-- DropIndex
DROP INDEX `db_library_activites_topicId_fkey` ON `db_library_activites`;

-- DropIndex
DROP INDEX `db_notification_userId_fkey` ON `db_notification`;

-- DropIndex
DROP INDEX `db_schools_activation_code_courseId_fkey` ON `db_schools_activation_code`;

-- DropIndex
DROP INDEX `db_schools_activation_code_schoolCourseId_fkey` ON `db_schools_activation_code`;

-- DropIndex
DROP INDEX `db_schools_activation_code_schoolId_fkey` ON `db_schools_activation_code`;

-- DropIndex
DROP INDEX `db_schools_activation_code_usedBy_fkey` ON `db_schools_activation_code`;

-- DropIndex
DROP INDEX `db_schools_course_courseId_fkey` ON `db_schools_course`;

-- DropIndex
DROP INDEX `db_schools_course_schoolId_fkey` ON `db_schools_course`;

-- DropIndex
DROP INDEX `db_schools_course_history_courseId_fkey` ON `db_schools_course_history`;

-- DropIndex
DROP INDEX `db_schools_course_history_schoolCourseId_fkey` ON `db_schools_course_history`;

-- DropIndex
DROP INDEX `db_schools_course_history_schoolId_fkey` ON `db_schools_course_history`;

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

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

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

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

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

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

-- DropIndex
DROP INDEX `db_users_mobile_key` ON `db_users`;

-- AlterTable
ALTER TABLE `db_learning_journey` ADD COLUMN `bannerUrl` VARCHAR(255) NULL;

-- AlterTable
ALTER TABLE `db_students` DROP COLUMN `userId`;

-- AlterTable
ALTER TABLE `db_teachers` DROP COLUMN `userId`;

-- AlterTable
ALTER TABLE `db_users` ADD COLUMN `gender` VARCHAR(191) NULL;

-- CreateTable
CREATE TABLE `db_users_history` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NULL,
    `email` VARCHAR(255) NOT NULL,
    `password` VARCHAR(255) NULL,
    `googleId` VARCHAR(255) NULL,
    `mobile` VARCHAR(16) NULL,
    `profileUrl` VARCHAR(191) NULL,
    `gender` VARCHAR(191) NULL,
    `role` ENUM('SUPER_ADMIN', 'ADMIN', 'SCHOOL_ADMIN', 'TEACHER', 'INDIVIDUAL_TEACHER', 'STUDENT', 'INDIVIDUAL_STUDENT') NOT NULL,
    `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    `userId` INTEGER NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `createdBy` INTEGER NULL,
    `updatedBy` INTEGER NULL,

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

-- CreateTable
CREATE TABLE `db_banner` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(255) 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 DEFAULT 1,
    `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_users_history` ADD CONSTRAINT `db_users_history_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `db_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_library_activites` ADD CONSTRAINT `db_library_activites_topicId_fkey` FOREIGN KEY (`topicId`) REFERENCES `db_library_topics`(`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_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `db_teacher_activites` ADD CONSTRAINT `db_teacher_activites_teacherTopicId_fkey` FOREIGN KEY (`teacherTopicId`) REFERENCES `db_teacher_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

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

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

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

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

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

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

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

-- AddForeignKey
ALTER TABLE `db_schools_activation_code` ADD CONSTRAINT `db_schools_activation_code_usedBy_fkey` FOREIGN KEY (`usedBy`) REFERENCES `db_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_notification` ADD CONSTRAINT `db_notification_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `db_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `db_teacher_order` ADD CONSTRAINT `db_teacher_order_moduleId_fkey` FOREIGN KEY (`moduleId`) REFERENCES `db_modules`(`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_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

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

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

-- AddForeignKey
ALTER TABLE `db_learning_journey_assign` ADD CONSTRAINT `db_learning_journey_assign_journeyId_fkey` FOREIGN KEY (`journeyId`) REFERENCES `db_learning_journey`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `db_learning_journey_sequence` ADD CONSTRAINT `db_learning_journey_sequence_journeyId_fkey` FOREIGN KEY (`journeyId`) REFERENCES `db_learning_journey`(`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_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_learning_journey_sequence` ADD CONSTRAINT `db_learning_journey_sequence_teacherTopicId_fkey` FOREIGN KEY (`teacherTopicId`) REFERENCES `db_teacher_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `db_class_code` ADD CONSTRAINT `db_class_code_schoolActivationId_fkey` FOREIGN KEY (`schoolActivationId`) REFERENCES `db_schools_activation_code`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `db_class_code_map` ADD CONSTRAINT `db_class_code_map_schoolActivationId_fkey` FOREIGN KEY (`schoolActivationId`) REFERENCES `db_schools_activation_code`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `db_class_code_map` ADD CONSTRAINT `db_class_code_map_classCodeId_fkey` FOREIGN KEY (`classCodeId`) REFERENCES `db_class_code`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

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

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

-- AddForeignKey
ALTER TABLE `db_calender` ADD CONSTRAINT `db_calender_teacherTopicId_fkey` FOREIGN KEY (`teacherTopicId`) REFERENCES `db_teacher_topics`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
