/*
  Warnings:

  - The primary key for the `comments` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - The primary key for the `discussion_statuses` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - The primary key for the `discussions` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - You are about to drop the column `statusId` on the `discussions` table. All the data in the column will be lost.
  - The primary key for the `resource_types` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - The primary key for the `resources` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - The primary key for the `roles` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - You are about to alter the column `name` on the `roles` table. The data in that column could be lost. The data in that column will be cast from `VarChar(191)` to `VarChar(45)`.
  - The primary key for the `training_module_trainers` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - The primary key for the `training_modules` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - The primary key for the `training_sessions` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - You are about to drop the column `ownerId` on the `training_sessions` table. All the data in the column will be lost.
  - The primary key for the `users` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - Added the required column `owner_id` to the `training_sessions` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE `comments` DROP FOREIGN KEY `comments_discussion_id_fkey`;

-- DropForeignKey
ALTER TABLE `comments` DROP FOREIGN KEY `comments_user_id_fkey`;

-- DropForeignKey
ALTER TABLE `discussions` DROP FOREIGN KEY `discussions_statusId_fkey`;

-- DropForeignKey
ALTER TABLE `discussions` DROP FOREIGN KEY `discussions_user_id_fkey`;

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

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

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

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

-- DropForeignKey
ALTER TABLE `training_sessions` DROP FOREIGN KEY `training_sessions_ownerId_fkey`;

-- DropForeignKey
ALTER TABLE `users` DROP FOREIGN KEY `users_role_id_fkey`;

-- DropIndex
DROP INDEX `comments_discussion_id_fkey` ON `comments`;

-- DropIndex
DROP INDEX `comments_user_id_fkey` ON `comments`;

-- DropIndex
DROP INDEX `discussions_statusId_fkey` ON `discussions`;

-- DropIndex
DROP INDEX `discussions_user_id_fkey` ON `discussions`;

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

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

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

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

-- DropIndex
DROP INDEX `training_sessions_ownerId_fkey` ON `training_sessions`;

-- DropIndex
DROP INDEX `users_role_id_fkey` ON `users`;

-- AlterTable
ALTER TABLE `comments` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `comment` MEDIUMTEXT NOT NULL,
    MODIFY `discussion_id` VARCHAR(255) NOT NULL,
    MODIFY `user_id` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `discussion_statuses` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `name` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `discussions` DROP PRIMARY KEY,
    DROP COLUMN `statusId`,
    ADD COLUMN `status_id` VARCHAR(255) NULL,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `subject` VARCHAR(255) NOT NULL,
    MODIFY `description` MEDIUMTEXT NOT NULL,
    MODIFY `link` VARCHAR(255) NOT NULL,
    MODIFY `feedback` MEDIUMTEXT NOT NULL,
    MODIFY `user_id` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `resource_types` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `name` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `resources` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `content` MEDIUMTEXT NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `roles` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `name` VARCHAR(45) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `training_module_trainers` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `training_module_id` VARCHAR(255) NOT NULL,
    MODIFY `resource_id` VARCHAR(255) NOT NULL,
    MODIFY `user_id` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `training_modules` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `title` VARCHAR(255) NOT NULL,
    MODIFY `description` MEDIUMTEXT NOT NULL,
    MODIFY `training_session_id` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `training_sessions` DROP PRIMARY KEY,
    DROP COLUMN `ownerId`,
    ADD COLUMN `owner_id` VARCHAR(255) NOT NULL,
    MODIFY `id` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `users` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(255) NOT NULL,
    MODIFY `email` VARCHAR(255) NOT NULL,
    MODIFY `password` VARCHAR(255) NOT NULL,
    MODIFY `first_name` VARCHAR(255) NOT NULL,
    MODIFY `last_name` VARCHAR(255) NOT NULL,
    MODIFY `phone_number` VARCHAR(255) NULL,
    MODIFY `role_id` VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (`id`);

-- AddForeignKey
ALTER TABLE `users` ADD CONSTRAINT `users_role_id_fkey` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `training_sessions` ADD CONSTRAINT `training_sessions_owner_id_fkey` FOREIGN KEY (`owner_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

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

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

-- AddForeignKey
ALTER TABLE `training_module_trainers` ADD CONSTRAINT `training_module_trainers_resource_id_fkey` FOREIGN KEY (`resource_id`) REFERENCES `resources`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `training_module_trainers` ADD CONSTRAINT `training_module_trainers_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `discussions` ADD CONSTRAINT `discussions_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

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

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

-- AddForeignKey
ALTER TABLE `comments` ADD CONSTRAINT `comments_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
