-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add db schema #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
-- CreateEnum | ||
CREATE TYPE "MemberSeasonInfo_memverPart" AS ENUM ('WEB_MOBILE', 'SERVER_CLOUD', 'AI'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "Role" AS ENUM ('LEAD', 'CORE_MEMBER', 'MEMBER'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "Type" AS ENUM ('STUDY', 'PROJECT'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Activity" ( | ||
"id" SERIAL NOT NULL, | ||
"type" "Type" NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
"status" TEXT NOT NULL DEFAULT 'ACTIVE', | ||
"activityName" TEXT NOT NULL, | ||
|
||
CONSTRAINT "Activity_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ActivityEnroll" ( | ||
"id" SERIAL NOT NULL, | ||
"activityId" INTEGER NOT NULL, | ||
"memberId" INTEGER NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
"status" TEXT NOT NULL DEFAULT 'ACTIVE', | ||
|
||
CONSTRAINT "ActivityEnroll_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Github" ( | ||
"githubId" SERIAL NOT NULL, | ||
"activityId" INTEGER NOT NULL, | ||
"githubURL" VARCHAR(300) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
"status" TEXT NOT NULL DEFAULT 'ACTIVE', | ||
|
||
CONSTRAINT "Github_pkey" PRIMARY KEY ("githubId") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Member" ( | ||
"id" SERIAL NOT NULL, | ||
"memberName" TEXT NOT NULL, | ||
"profileImgURL" VARCHAR(300) NOT NULL, | ||
"githubURL" VARCHAR(300) NOT NULL, | ||
"memberEmail" VARCHAR(300) NOT NULL, | ||
"refreshToken" VARCHAR(500) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
"status" TEXT NOT NULL DEFAULT 'ACTIVE', | ||
|
||
CONSTRAINT "Member_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "MemberSeasonInfo" ( | ||
"id" SERIAL NOT NULL, | ||
"seasonNum" INTEGER NOT NULL, | ||
"memberRole" "Role" NOT NULL, | ||
"activityId" INTEGER NOT NULL, | ||
"seasonId" INTEGER NOT NULL, | ||
"memberId" INTEGER NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
"status" TEXT NOT NULL DEFAULT 'ACTIVE', | ||
"memberPart" "MemberSeasonInfo_memverPart" NOT NULL, | ||
|
||
CONSTRAINT "MemberSeasonInfo_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Season" ( | ||
"id" SERIAL NOT NULL, | ||
"seasonNum" INTEGER NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
"status" TEXT NOT NULL DEFAULT 'ACTIVE', | ||
|
||
CONSTRAINT "Season_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ActivityEnroll_activityId_key" ON "ActivityEnroll"("activityId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ActivityEnroll_memberId_key" ON "ActivityEnroll"("memberId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Github_activityId_key" ON "Github"("activityId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "MemberSeasonInfo_activityId_key" ON "MemberSeasonInfo"("activityId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "MemberSeasonInfo_memberId_key" ON "MemberSeasonInfo"("memberId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ActivityEnroll" ADD CONSTRAINT "ActivityEnroll_activityId_fkey" FOREIGN KEY ("activityId") REFERENCES "Activity"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ActivityEnroll" ADD CONSTRAINT "ActivityEnroll_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Github" ADD CONSTRAINT "Github_activityId_fkey" FOREIGN KEY ("activityId") REFERENCES "Activity"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "MemberSeasonInfo" ADD CONSTRAINT "MemberSeasonInfo_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "MemberSeasonInfo" ADD CONSTRAINT "MemberSeasonInfo_seasonId_fkey" FOREIGN KEY ("seasonId") REFERENCES "Season"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,101 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
model test { | ||
id Int @id @default(autoincrement()) | ||
test String | ||
test2 String | ||
} | ||
|
||
model Activity { | ||
id Int @id @default(autoincrement()) | ||
type Type | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime? | ||
status String @default("ACTIVE") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥝 status도 네이밍을 조금 직관적이게 deleted 같은거는 어떨까요? 만약 기존 네이밍을 유지한다면 위에서 말씀드렸던 것처럼 enum으로 값을 관리해야할 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지난번에 정했던 부분이긴 하지만 그때는 생각을 못했어가지구, 생각나서 말씀드립니다!ㅎ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. status enum으로 관리하는거 좋은 것 같습니다! |
||
activityName String | ||
ActivityEnroll ActivityEnroll? | ||
Github Github? | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍌 이 친구들 표기법이 PascalCase로 되어있는데 camelCase로 바꿔주는게 맞는 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 이부분 수정할게요!
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍎 Activity:ActivityEnroll = 1:n 인 점을 생각해보면, |
||
} | ||
|
||
model ActivityEnroll { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥝 이 테이블이 매핑 테이블임을 직관적으로 이해할 수 있도록 지난번에 정했던 이름인 |
||
id Int @id @default(autoincrement()) | ||
activityId Int @unique | ||
memberId Int @unique | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime? | ||
status String @default("ACTIVE") | ||
Activity Activity @relation(fields: [activityId], references: [id]) | ||
Member Member @relation(fields: [memberId], references: [id]) | ||
} | ||
|
||
model Github { | ||
githubId Int @id @default(autoincrement()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥝 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! |
||
activityId Int @unique | ||
githubURL String @db.VarChar(300) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime? | ||
status String @default("ACTIVE") | ||
Activity Activity @relation(fields: [activityId], references: [id]) | ||
} | ||
|
||
model Member { | ||
id Int @id @default(autoincrement()) | ||
memberName String | ||
profileImgURL String @db.VarChar(300) | ||
githubURL String @db.VarChar(300) | ||
memberEmail String @db.VarChar(300) | ||
Comment on lines
+50
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥝 이것도 단순 의견인데, 이미 테이블 이름으로 member인게 명시되어 있으니깐, |
||
refreshToken String @db.VarChar(500) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이거 null 아닙니다 ㅜㅜ 제가 수정해놓을게요 죄송해요..! |
||
createdAt DateTime @default(now()) | ||
updatedAt DateTime? | ||
status String @default("ACTIVE") | ||
ActivityEnroll ActivityEnroll? | ||
MemberSeasonInfo MemberSeasonInfo? | ||
Comment on lines
+58
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍎 여기도 1:n 관계인 점을 고려해서 타입 변경해줘야할 것 같습니다! |
||
} | ||
|
||
model MemberSeasonInfo { | ||
id Int @id @default(autoincrement()) | ||
seasonNum Int | ||
memberRole Role | ||
activityId Int @unique | ||
seasonId Int | ||
memberId Int @unique | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime? | ||
status String @default("ACTIVE") | ||
memberPart MemberSeasonInfo_memverPart | ||
Member Member @relation(fields: [memberId], references: [id]) | ||
Season Season @relation(fields: [seasonId], references: [id]) | ||
} | ||
|
||
model Season { | ||
id Int @id @default(autoincrement()) | ||
seasonNum Int | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime? | ||
status String @default("ACTIVE") | ||
MemberSeasonInfo MemberSeasonInfo[] | ||
} | ||
|
||
enum MemberSeasonInfo_memverPart { | ||
WEB_MOBILE | ||
SERVER_CLOUD | ||
AI | ||
} | ||
Comment on lines
+86
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍌 이름이 너무 길고 오타가 있는데, |
||
|
||
enum Role { | ||
LEAD | ||
CORE_MEMBER | ||
MEMBER | ||
} | ||
Comment on lines
+92
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥝 |
||
|
||
enum Type { | ||
STUDY | ||
PROJECT | ||
} | ||
Comment on lines
+98
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥝 음 "활동 종류"를 위한 enum의 네이밍이니깐 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋아요! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍌
updatedAt
도 처음에는createdAt
이랑 같은 값을 가지고, 이후에 변경될 때마다 업데이트 되어야하니깐createdAt
과 마찬가지로 NOT NULL 속성을 가져야하는 것으로 알고 있어요!그리고 매번 직접 업데이트하지 않고 편리하게 사용할 수 있도록 Prisma에서
@updateAt
이라는 속성을 제공해줍니다! (공식 문서)