Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions src/database/migrations/20230208050008_schema/migration.sql
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;
95 changes: 91 additions & 4 deletions src/database/schema.prisma
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?
Copy link
Contributor

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 이라는 속성을 제공해줍니다! (공식 문서)

Suggested change
updatedAt DateTime?
updatedAt DateTime @updatedAt

status String @default("ACTIVE")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥝 status도 네이밍을 조금 직관적이게 deleted 같은거는 어떨까요?
그러면 기존의 status라는 이름으로 했을때는 enum으로 값을 관리해야 할 것 같은데 deleted로 하면 boolean형으로 비교적 간단하고 직관적으로 관리할 수 있을 것 같아서요!

만약 기존 네이밍을 유지한다면 위에서 말씀드렸던 것처럼 enum으로 값을 관리해야할 것 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지난번에 정했던 부분이긴 하지만 그때는 생각을 못했어가지구, 생각나서 말씀드립니다!ㅎ

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍌 이 친구들 표기법이 PascalCase로 되어있는데 camelCase로 바꿔주는게 맞는 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 이부분 수정할게요!

Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍎 Activity:ActivityEnroll = 1:n 인 점을 생각해보면, ActivityEnroll[]으로 바꿔줘야 하는 것 같아요!
(Github도 마찬가지입니다!)

}

model ActivityEnroll {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥝 이 테이블이 매핑 테이블임을 직관적으로 이해할 수 있도록 지난번에 정했던 이름인 ActivityMemberMapping이 저는 괜찮다고 생각하는데,, 다른분들 의견도 궁금해요!

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥝 githubId도 그냥 id로 바꾸는건 어떤가요..?ㅎ

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥝 이것도 단순 의견인데, 이미 테이블 이름으로 member인게 명시되어 있으니깐, memberName, memberEmailname, email로 변경하는건 어떨까요?

refreshToken String @db.VarChar(500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

🍌 위 이미지에서는 `refresshToken`은 Nullable한 것 같은데 어느쪽이 맞는지는 잘 모르겠어요..!

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍌 이름이 너무 길고 오타가 있는데, MemberPart이나 MemberPartType은 어떤가요?


enum Role {
LEAD
CORE_MEMBER
MEMBER
}
Comment on lines +92 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥝 Role 네이밍을 확장성을 고려해서 MemberRole이나 MemberRoleType으로 변경하는건 어떤가요..?ㅎ


enum Type {
STUDY
PROJECT
}
Comment on lines +98 to +101
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥝 음 "활동 종류"를 위한 enum의 네이밍이니깐 ActivityType 같은건 어떤가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아요!