From 7c40353f6b27bfd521852dbb9794bc1a5dc1fe5e Mon Sep 17 00:00:00 2001 From: Keane Chan Date: Thu, 6 Oct 2022 14:59:14 +0800 Subject: [PATCH] [resumes][feat] add resumes schema (#308) * [resumes][feat] add resumes schema * [resumes][feat] rename to ResumesSection * [resumes][feat] update resume schema --- .vscode/settings.json | 3 + .../migration.sql | 71 ++++++++++++++++++ apps/portal/prisma/schema.prisma | 75 +++++++++++++++++-- 3 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 apps/portal/prisma/migrations/20221006064944_add_resume_schemas/migration.sql diff --git a/.vscode/settings.json b/.vscode/settings.json index 067b7966..caa4523e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,5 +15,8 @@ "typescript.format.enable": true, "editor.codeActionsOnSave": { "source.fixAll": true + }, + "[prisma]": { + "editor.defaultFormatter": "Prisma.prisma" } } diff --git a/apps/portal/prisma/migrations/20221006064944_add_resume_schemas/migration.sql b/apps/portal/prisma/migrations/20221006064944_add_resume_schemas/migration.sql new file mode 100644 index 00000000..67b66abf --- /dev/null +++ b/apps/portal/prisma/migrations/20221006064944_add_resume_schemas/migration.sql @@ -0,0 +1,71 @@ +-- CreateEnum +CREATE TYPE "ResumesSection" AS ENUM ('GENERAL', 'EDUCATION', 'EXPERIENCE', 'PROJECTS', 'SKILLS'); + +-- CreateTable +CREATE TABLE "ResumesResume" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "title" TEXT NOT NULL, + "additionalInfo" TEXT NOT NULL, + "url" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "ResumesResume_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "ResumesStar" ( + "id" TEXT NOT NULL, + "resumeId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "ResumesStar_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "ResumesComment" ( + "id" TEXT NOT NULL, + "resumeId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "description" TEXT NOT NULL, + "section" "ResumesSection" NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "ResumesComment_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "ResumesCommentVote" ( + "id" TEXT NOT NULL, + "commentId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "value" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "ResumesCommentVote_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "ResumesResume" ADD CONSTRAINT "ResumesResume_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ResumesStar" ADD CONSTRAINT "ResumesStar_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ResumesStar" ADD CONSTRAINT "ResumesStar_resumeId_fkey" FOREIGN KEY ("resumeId") REFERENCES "ResumesResume"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ResumesComment" ADD CONSTRAINT "ResumesComment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ResumesComment" ADD CONSTRAINT "ResumesComment_resumeId_fkey" FOREIGN KEY ("resumeId") REFERENCES "ResumesResume"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ResumesCommentVote" ADD CONSTRAINT "ResumesCommentVote_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ResumesCommentVote" ADD CONSTRAINT "ResumesCommentVote_commentId_fkey" FOREIGN KEY ("commentId") REFERENCES "ResumesComment"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index ab494cee..b62ad310 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -37,14 +37,18 @@ model Session { } model User { - id String @id @default(cuid()) - name String? - email String? @unique - emailVerified DateTime? - image String? - accounts Account[] - sessions Session[] - todos Todo[] + id String @id @default(cuid()) + name String? + email String? @unique + emailVerified DateTime? + image String? + accounts Account[] + sessions Session[] + todos Todo[] + resumesResumes ResumesResume[] + resumesStars ResumesStar[] + resumesComments ResumesComment[] + resumesCommentVotes ResumesCommentVote[] } model VerificationToken { @@ -86,6 +90,61 @@ model Company { // across all models in this file. // End of Resumes project models. +model ResumesResume { + id String @id @default(cuid()) + userId String + title String @db.Text + additionalInfo String @db.Text + // TODO: Add role, experience, location from Enums + url String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + stars ResumesStar[] + comments ResumesComment[] +} + +model ResumesStar { + id String @id @default(cuid()) + resumeId String + userId String + createdAt DateTime @default(now()) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade) +} + +model ResumesComment { + id String @id @default(cuid()) + resumeId String + userId String + description String @db.Text + section ResumesSection + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + resume ResumesResume @relation(fields: [resumeId], references: [id], onDelete: Cascade) + votes ResumesCommentVote[] +} + +enum ResumesSection { + GENERAL + EDUCATION + EXPERIENCE + PROJECTS + SKILLS +} + +model ResumesCommentVote { + id String @id @default(cuid()) + commentId String + userId String + value Int + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + comment ResumesComment @relation(fields: [commentId], references: [id], onDelete: Cascade) +} + // Start of Offers project models. // Add Offers project models here, prefix all models with "Offer", // use camelCase for field names, and try to name them consistently