/*
  Warnings:

  - You are about to drop the column `coaching_start_date` on the `discussions` table. All the data in the column will be lost.
  - You are about to drop the column `coaching_stop_date` on the `discussions` table. All the data in the column will be lost.
  - You are about to drop the column `resource_id` on the `training_module_trainers` table. All the data in the column will be lost.
  - You are about to drop the column `training_session_id` on the `training_modules` table. All the data in the column will be lost.
  - You are about to drop the `discussion_statuses` table. If the table is not empty, all the data it contains will be lost.
  - Added the required column `training_module_id` to the `resources` table without a default value. This is not possible if the table is not empty.
  - Added the required column `trainingModuleId` to the `training_sessions` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE `discussions` DROP FOREIGN KEY `discussions_status_id_fkey`;

-- DropForeignKey
ALTER TABLE `training_module_trainers` DROP FOREIGN KEY `training_module_trainers_resource_id_fkey`;

-- DropForeignKey
ALTER TABLE `training_modules` DROP FOREIGN KEY `training_modules_training_session_id_fkey`;

-- DropIndex
DROP INDEX `training_module_trainers_resource_id_fkey` ON `training_module_trainers`;

-- DropIndex
DROP INDEX `training_modules_training_session_id_fkey` ON `training_modules`;

-- AlterTable
ALTER TABLE `discussions` DROP COLUMN `coaching_start_date`,
    DROP COLUMN `coaching_stop_date`;

-- AlterTable
ALTER TABLE `resources` ADD COLUMN `training_module_id` INTEGER NOT NULL;

-- AlterTable
ALTER TABLE `training_module_trainers` DROP COLUMN `resource_id`;

-- AlterTable
ALTER TABLE `training_modules` DROP COLUMN `training_session_id`;

-- AlterTable
ALTER TABLE `training_sessions` ADD COLUMN `trainingModuleId` INTEGER NOT NULL;

-- DropTable
DROP TABLE `discussion_statuses`;

-- CreateTable
CREATE TABLE `training_sessions_stakeholders` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `trainingSessionId` INTEGER NOT NULL,
    `stakeholderId` INTEGER NOT NULL,

    INDEX `training_sessions_stakeholders_trainingSessionId_idx`(`trainingSessionId`),
    INDEX `training_sessions_stakeholders_stakeholderId_idx`(`stakeholderId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `coaching_sessions` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `start_date` DATETIME(3) NOT NULL,
    `stop_date` DATETIME(3) NOT NULL,
    `discussion_id` INTEGER NOT NULL,

    INDEX `coaching_sessions_discussion_id_idx`(`discussion_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DiscussionStatus` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL,

    INDEX `DiscussionStatus_name_idx`(`name`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE INDEX `files_name_idx` ON `files`(`name`);

-- CreateIndex
CREATE INDEX `resources_training_module_id_idx` ON `resources`(`training_module_id`);

-- CreateIndex
CREATE INDEX `training_sessions_trainingModuleId_idx` ON `training_sessions`(`trainingModuleId`);

-- AddForeignKey
ALTER TABLE `training_sessions` ADD CONSTRAINT `training_sessions_trainingModuleId_fkey` FOREIGN KEY (`trainingModuleId`) REFERENCES `training_modules`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `training_sessions_stakeholders` ADD CONSTRAINT `training_sessions_stakeholders_trainingSessionId_fkey` FOREIGN KEY (`trainingSessionId`) REFERENCES `training_sessions`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `training_sessions_stakeholders` ADD CONSTRAINT `training_sessions_stakeholders_stakeholderId_fkey` FOREIGN KEY (`stakeholderId`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `resources` ADD CONSTRAINT `resources_training_module_id_fkey` FOREIGN KEY (`training_module_id`) REFERENCES `training_modules`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `discussions` ADD CONSTRAINT `discussions_status_id_fkey` FOREIGN KEY (`status_id`) REFERENCES `DiscussionStatus`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `coaching_sessions` ADD CONSTRAINT `coaching_sessions_discussion_id_fkey` FOREIGN KEY (`discussion_id`) REFERENCES `discussions`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- RenameIndex
ALTER TABLE `comments` RENAME INDEX `comments_discussion_id_fkey` TO `comments_discussion_id_idx`;

-- RenameIndex
ALTER TABLE `comments` RENAME INDEX `comments_user_id_fkey` TO `comments_user_id_idx`;

-- RenameIndex
ALTER TABLE `discussions` RENAME INDEX `discussions_status_id_fkey` TO `discussions_status_id_idx`;

-- RenameIndex
ALTER TABLE `discussions` RENAME INDEX `discussions_user_id_fkey` TO `discussions_user_id_idx`;

-- RenameIndex
ALTER TABLE `files` RENAME INDEX `files_user_id_fkey` TO `files_user_id_idx`;

-- RenameIndex
ALTER TABLE `resources` RENAME INDEX `resources_resource_type_id_fkey` TO `resources_resource_type_id_idx`;

-- RenameIndex
ALTER TABLE `training_module_trainers` RENAME INDEX `training_module_trainers_training_module_id_fkey` TO `training_module_trainers_training_module_id_idx`;

-- RenameIndex
ALTER TABLE `training_module_trainers` RENAME INDEX `training_module_trainers_user_id_fkey` TO `training_module_trainers_user_id_idx`;

-- RenameIndex
ALTER TABLE `training_sessions` RENAME INDEX `training_sessions_owner_id_fkey` TO `training_sessions_owner_id_idx`;

-- RenameIndex
ALTER TABLE `users` RENAME INDEX `users_role_id_fkey` TO `users_role_id_idx`;
