Skip to content

Commit

Permalink
chore: DB Migration 초기화
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyongp committed Nov 14, 2023
1 parent b5d9793 commit 53647b1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 70 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -30,34 +30,33 @@ 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;

-- 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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;
5 changes: 1 addition & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ model Blog {
posts Post[]
keywordTagMaps KeywordTagMap[]
@@unique([id, userId], name: "blogIdIndex")
@@unique([userId, name], name: "userNameIndex")
@@map("blogs")
}
Expand All @@ -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")
}

Expand Down

0 comments on commit 53647b1

Please sign in to comment.