-- CreateTable CREATE TABLE `Cohort` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `name` VARCHAR(191) NOT NULL, `dailyView` INTEGER NOT NULL DEFAULT 0, `description` VARCHAR(191) NULL, UNIQUE INDEX `Cohort_name_key`(`name`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Post` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `date` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), `updatedAt` DATETIME(3) NULL, `title` VARCHAR(191) NOT NULL, `content` TEXT NULL, `summary` TEXT NULL, `sourceId` INTEGER NOT NULL, `URL` VARCHAR(191) NOT NULL, `image` VARCHAR(191) NULL, UNIQUE INDEX `Post_URL_key`(`URL`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Source` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `name` VARCHAR(191) NOT NULL, `type` ENUM('FEED') NOT NULL DEFAULT 'FEED', `URL` VARCHAR(191) NOT NULL, `updatedAt` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3), `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), `lastError` VARCHAR(191) NULL, `status` ENUM('OK', 'WARNING', 'ERROR') NOT NULL DEFAULT 'OK', `nErrors` INTEGER NOT NULL DEFAULT 0, `description` VARCHAR(191) NULL, `image` LONGTEXT NULL, `link` VARCHAR(191) NULL, UNIQUE INDEX `Source_URL_key`(`URL`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `Tag` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `name` VARCHAR(191) NOT NULL, UNIQUE INDEX `Tag_name_key`(`name`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `_CohortToSource` ( `A` INTEGER NOT NULL, `B` INTEGER NOT NULL, UNIQUE INDEX `_CohortToSource_AB_unique`(`A`, `B`), INDEX `_CohortToSource_B_index`(`B`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- CreateTable CREATE TABLE `_PostToTag` ( `A` INTEGER NOT NULL, `B` INTEGER NOT NULL, UNIQUE INDEX `_PostToTag_AB_unique`(`A`, `B`), INDEX `_PostToTag_B_index`(`B`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AddForeignKey ALTER TABLE `Post` ADD CONSTRAINT `Post_sourceId_fkey` FOREIGN KEY (`sourceId`) REFERENCES `Source`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `_CohortToSource` ADD FOREIGN KEY (`A`) REFERENCES `Cohort`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `_CohortToSource` ADD FOREIGN KEY (`B`) REFERENCES `Source`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `_PostToTag` ADD FOREIGN KEY (`A`) REFERENCES `Post`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE `_PostToTag` ADD FOREIGN KEY (`B`) REFERENCES `Tag`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;