diff --git a/src/database/migrations/20230208050008_schema/migration.sql b/src/database/migrations/20230208050008_schema/migration.sql new file mode 100644 index 0000000..5722282 --- /dev/null +++ b/src/database/migrations/20230208050008_schema/migration.sql @@ -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; diff --git a/src/database/schema.prisma b/src/database/schema.prisma index ab7a59e..641a806 100644 --- a/src/database/schema.prisma +++ b/src/database/schema.prisma @@ -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") + activityName String + ActivityEnroll ActivityEnroll? + Github Github? +} + +model ActivityEnroll { + 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()) + 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) + refreshToken String @db.VarChar(500) + createdAt DateTime @default(now()) + updatedAt DateTime? + status String @default("ACTIVE") + ActivityEnroll ActivityEnroll? + MemberSeasonInfo MemberSeasonInfo? +} + +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 +} + +enum Role { + LEAD + CORE_MEMBER + MEMBER +} + +enum Type { + STUDY + PROJECT +}