-- CreateTable
CREATE TABLE `users` (
`id` VARCHAR(191) NOT NULL,
`email` VARCHAR(191) NOT NULL,
`name` VARCHAR(20) NOT NULL,
`password` VARCHAR(80) NOT NULL,
`college` VARCHAR(20) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
`roles` JSON NOT NULL,
UNIQUE INDEX `users_email_key`(`email`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `papers` (
`id` VARCHAR(191) NOT NULL,
`course` VARCHAR(20) NOT NULL,
`college` VARCHAR(24) NOT NULL,
`teacher_id` VARCHAR(191) NOT NULL,
`remark` VARCHAR(191) NULL,
`status` ENUM('PENDING', 'PASSED', 'REJECTED', 'REVIEW_PASSED', 'REVIEW_REJECTED', 'PRINT') NOT NULL,
`a_name` VARCHAR(50) NOT NULL,
`b_name` VARCHAR(50) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `paper_lifes` (
`id` VARCHAR(191) NOT NULL,
`paper_id` VARCHAR(191) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,
`status` ENUM('CREATE', 'UPDATE', 'PENDING', 'PASSED', 'REJECTED', 'REVIEW_PASSED', 'REVIEW_REJECTED', 'PRINT') NOT NULL,
`content` VARCHAR(191) NULL,
`images` JSON NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`a_name` VARCHAR(50) NULL,
`b_name` VARCHAR(50) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `manager_notices` (
`id` VARCHAR(191) NOT NULL,
`title` VARCHAR(40) NOT NULL,
`content` VARCHAR(191) NULL,
`user_id` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `user_notices` (
`id` VARCHAR(191) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,
`notice_id` VARCHAR(191) NOT NULL,
`read` BOOLEAN NOT NULL DEFAULT false,
`readAt` DATETIME(3) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `refresh_tokens` (
`token` VARCHAR(32) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`os` JSON NOT NULL,
`device` JSON NOT NULL,
`browser` JSON NOT NULL,
UNIQUE INDEX `refresh_tokens_token_key`(`token`),
PRIMARY KEY (`token`, `user_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `colleges` (
`id` INTEGER NOT NULL,
`name` VARCHAR(20) NOT NULL,
UNIQUE INDEX `colleges_name_key`(`name`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `users` ADD CONSTRAINT `users_college_fkey` FOREIGN KEY (`college`) REFERENCES `colleges`(`name`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `papers` ADD CONSTRAINT `papers_teacher_id_fkey` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `paper_lifes` ADD CONSTRAINT `paper_lifes_paper_id_fkey` FOREIGN KEY (`paper_id`) REFERENCES `papers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `user_notices` ADD CONSTRAINT `user_notices_notice_id_fkey` FOREIGN KEY (`notice_id`) REFERENCES `manager_notices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;