diff --git a/prisma/migrations/20231109070005_change_updated_at_column/migration.sql b/prisma/migrations/20231109070005_change_updated_at_column/migration.sql deleted file mode 100644 index 67b3865..0000000 --- a/prisma/migrations/20231109070005_change_updated_at_column/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- AlterTable -ALTER TABLE `blogs` MODIFY `updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0); - --- AlterTable -ALTER TABLE `posts` MODIFY `updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0); - --- AlterTable -ALTER TABLE `users` MODIFY `updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0); diff --git a/prisma/migrations/20231113054945_create_report_and_block_tables/migration.sql b/prisma/migrations/20231113054945_create_report_and_block_tables/migration.sql deleted file mode 100644 index 0f372aa..0000000 --- a/prisma/migrations/20231113054945_create_report_and_block_tables/migration.sql +++ /dev/null @@ -1,32 +0,0 @@ --- CreateTable -CREATE TABLE `user_reports` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `reporter_id` INTEGER NOT NULL, - `reported_id` INTEGER NOT NULL, - `reason` VARCHAR(100) NOT NULL, - - UNIQUE INDEX `user_reports_reporter_id_reported_id_key`(`reporter_id`, `reported_id`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `user_blocks` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `blocker_id` INTEGER NOT NULL, - `blocked_id` INTEGER NOT NULL, - - UNIQUE INDEX `user_blocks_blocker_id_blocked_id_key`(`blocker_id`, `blocked_id`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `user_reports` ADD CONSTRAINT `user_reports_reporter_id_fkey` FOREIGN KEY (`reporter_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `user_reports` ADD CONSTRAINT `user_reports_reported_id_fkey` FOREIGN KEY (`reported_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `user_blocks` ADD CONSTRAINT `user_blocks_blocker_id_fkey` FOREIGN KEY (`blocker_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `user_blocks` ADD CONSTRAINT `user_blocks_blocked_id_fkey` FOREIGN KEY (`blocked_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20231113101900_update_blog_url_and_rss/migration.sql b/prisma/migrations/20231113101900_update_blog_url_and_rss/migration.sql deleted file mode 100644 index 53480fd..0000000 --- a/prisma/migrations/20231113101900_update_blog_url_and_rss/migration.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[url]` on the table `blogs` will be added. If there are existing duplicate values, this will fail. - - A unique constraint covering the columns `[rss]` on the table `blogs` will be added. If there are existing duplicate values, this will fail. - -*/ --- AlterTable -ALTER TABLE `blogs` MODIFY `url` VARCHAR(512) NOT NULL, - MODIFY `rss` VARCHAR(512) NOT NULL; - --- CreateIndex -CREATE UNIQUE INDEX `blogs_url_key` ON `blogs`(`url`); - --- CreateIndex -CREATE UNIQUE INDEX `blogs_rss_key` ON `blogs`(`rss`); diff --git a/prisma/migrations/20231103064351_create_tables/migration.sql b/prisma/migrations/20231114074851_init/migration.sql similarity index 71% rename from prisma/migrations/20231103064351_create_tables/migration.sql rename to prisma/migrations/20231114074851_init/migration.sql index 6e84fd9..d1789ef 100644 --- a/prisma/migrations/20231103064351_create_tables/migration.sql +++ b/prisma/migrations/20231114074851_init/migration.sql @@ -6,7 +6,7 @@ CREATE TABLE `users` ( `provider` VARCHAR(10) NULL, `provider_id` VARCHAR(100) NULL, `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), - `updated_at` TIMESTAMP(0) NOT NULL, + `updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), `last_signed_at` TIMESTAMP(0) NULL, `deleted_at` TIMESTAMP(0) NULL, @@ -30,14 +30,15 @@ CREATE TABLE `blogs` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `user_id` INTEGER NOT NULL, `name` VARCHAR(30) NOT NULL, - `url` TEXT NOT NULL, - `rss` TEXT NOT NULL, + `url` VARCHAR(512) NOT NULL, + `rss` VARCHAR(512) NOT NULL, `main` BOOLEAN NOT NULL DEFAULT false, `last_published_at` TIMESTAMP(0) NULL, `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), - `updated_at` TIMESTAMP(0) NOT NULL, + `updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), - UNIQUE INDEX `blogs_id_user_id_key`(`id`, `user_id`), + UNIQUE INDEX `blogs_url_key`(`url`), + UNIQUE INDEX `blogs_rss_key`(`rss`), UNIQUE INDEX `blogs_user_id_name_key`(`user_id`, `name`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -45,19 +46,17 @@ CREATE TABLE `blogs` ( -- CreateTable CREATE TABLE `posts` ( `id` INTEGER NOT NULL AUTO_INCREMENT, - `user_id` INTEGER NOT NULL, `blog_id` INTEGER NOT NULL, + `user_id` INTEGER NOT NULL, `title` VARCHAR(50) NOT NULL, `content` VARCHAR(100) NOT NULL, `url` VARCHAR(512) NOT NULL, `published_at` TIMESTAMP(0) NOT NULL, `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), - `updated_at` TIMESTAMP(0) NOT NULL, + `updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), UNIQUE INDEX `posts_url_key`(`url`), INDEX `publishedAtIndex`(`published_at`), - UNIQUE INDEX `posts_id_blog_id_key`(`id`, `blog_id`), - UNIQUE INDEX `posts_id_user_id_key`(`id`, `user_id`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -92,6 +91,27 @@ CREATE TABLE `post_likes` ( PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +-- CreateTable +CREATE TABLE `user_reports` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `reporter_id` INTEGER NOT NULL, + `reported_id` INTEGER NOT NULL, + `reason` VARCHAR(100) NOT NULL, + + UNIQUE INDEX `user_reports_reporter_id_reported_id_key`(`reporter_id`, `reported_id`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `user_blocks` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `blocker_id` INTEGER NOT NULL, + `blocked_id` INTEGER NOT NULL, + + UNIQUE INDEX `user_blocks_blocker_id_blocked_id_key`(`blocker_id`, `blocked_id`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + -- AddForeignKey ALTER TABLE `follows` ADD CONSTRAINT `follows_follower_id_fkey` FOREIGN KEY (`follower_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; @@ -113,8 +133,20 @@ ALTER TABLE `post_tags` ADD CONSTRAINT `post_tags_post_id_fkey` FOREIGN KEY (`po -- AddForeignKey ALTER TABLE `keyword_tag_maps` ADD CONSTRAINT `keyword_tag_maps_blog_id_fkey` FOREIGN KEY (`blog_id`) REFERENCES `blogs`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; +-- AddForeignKey +ALTER TABLE `post_likes` ADD CONSTRAINT `post_likes_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + -- AddForeignKey ALTER TABLE `post_likes` ADD CONSTRAINT `post_likes_post_id_fkey` FOREIGN KEY (`post_id`) REFERENCES `posts`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE `post_likes` ADD CONSTRAINT `post_likes_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `user_reports` ADD CONSTRAINT `user_reports_reporter_id_fkey` FOREIGN KEY (`reporter_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `user_reports` ADD CONSTRAINT `user_reports_reported_id_fkey` FOREIGN KEY (`reported_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `user_blocks` ADD CONSTRAINT `user_blocks_blocker_id_fkey` FOREIGN KEY (`blocker_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `user_blocks` ADD CONSTRAINT `user_blocks_blocked_id_fkey` FOREIGN KEY (`blocked_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0546491..6e1ab88 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -64,7 +64,6 @@ model Blog { posts Post[] keywordTagMaps KeywordTagMap[] - @@unique([id, userId], name: "blogIdIndex") @@unique([userId, name], name: "userNameIndex") @@map("blogs") } @@ -85,9 +84,7 @@ model Post { postTags PostTag[] postLikes PostLike[] - @@unique([id, blogId], name: "postBlogIdIndex") - @@unique([id, userId], name: "postUserIdIndex") - @@index([publishedAt], name: "publishedAtIndex") + @@index(publishedAt, name: "publishedAtIndex") @@map("posts") }