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

Create prisma models for the remaining entities #38

Merged
merged 7 commits into from
Oct 23, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
-- CreateEnum
CREATE TYPE "SignupStatus" AS ENUM ('PENDING', 'CONFIRMED', 'CANCELED');

-- CreateEnum
CREATE TYPE "PostingType" AS ENUM ('INDIVIDUAL', 'GROUP');

-- CreateTable
CREATE TABLE "postings" (
"id" SERIAL NOT NULL,
"branch_id" INTEGER NOT NULL,
"title" TEXT NOT NULL,
"type" "PostingType" NOT NULL,
"purpose" TEXT NOT NULL,
"responsibilitie" TEXT NOT NULL,
"tasks" TEXT NOT NULL,
"desired_qualities" TEXT NOT NULL,
"mandatory_activities" TEXT NOT NULL,
"benefits" TEXT NOT NULL,
"working_conditions" TEXT NOT NULL,
"num_volunteers" INTEGER NOT NULL DEFAULT 1,

CONSTRAINT "postings_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "skills" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,

CONSTRAINT "skills_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "prerequisites" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"completed" BOOLEAN NOT NULL,

CONSTRAINT "prerequisites_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "branches" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,

CONSTRAINT "branches_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "shifts" (
"id" SERIAL NOT NULL,
"posting_id" INTEGER NOT NULL,
"start_time" TIMESTAMP(3) NOT NULL,
"end_time" TIMESTAMP(3) NOT NULL,
"repeat_interval" INTEGER,
"repeat_end" TIMESTAMP(3),

CONSTRAINT "shifts_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "signups" (
"id" SERIAL NOT NULL,
"shifts_id" INTEGER NOT NULL,
"userId" INTEGER NOT NULL,
"status" "SignupStatus" NOT NULL,
"num_volunteers" INTEGER NOT NULL DEFAULT 1,

CONSTRAINT "signups_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "availabilities" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"start_time" TIMESTAMP(3) NOT NULL,
"end_time" TIMESTAMP(3) NOT NULL,
"repeat_interval" INTEGER,
"repeat_end" TIMESTAMP(3),

CONSTRAINT "availabilities_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "volunteers" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"default_branch_id" INTEGER NOT NULL,
"hire_date" TIMESTAMP(3) NOT NULL,
"date_of_birth" TIMESTAMP(3) NOT NULL,
"pronouns" TEXT NOT NULL,

CONSTRAINT "volunteers_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "employees" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"branch_id" INTEGER NOT NULL,

CONSTRAINT "employees_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "postings_on_skills" (
"postings_id" INTEGER NOT NULL,
"skills_id" INTEGER NOT NULL,

CONSTRAINT "postings_on_skills_pkey" PRIMARY KEY ("postings_id","skills_id")
);

-- CreateTable
CREATE TABLE "postings_on_prerequisites" (
"postings_id" INTEGER NOT NULL,
"prerequisites_id" INTEGER NOT NULL,

CONSTRAINT "postings_on_prerequisites_pkey" PRIMARY KEY ("postings_id","prerequisites_id")
);

-- CreateTable
CREATE TABLE "postings_on_employees_pocs" (
"posting_id" INTEGER NOT NULL,
"employee_id" INTEGER NOT NULL,

CONSTRAINT "postings_on_employees_pocs_pkey" PRIMARY KEY ("posting_id","employee_id")
);

-- CreateTable
CREATE TABLE "volunteers_on_skills" (
"volunteer_id" INTEGER NOT NULL,
"skills_id" INTEGER NOT NULL,

CONSTRAINT "volunteers_on_skills_pkey" PRIMARY KEY ("volunteer_id","skills_id")
);

-- CreateTable
CREATE TABLE "volunteers_on_prerequisites" (
"volunteers_id" INTEGER NOT NULL,
"prerequisites_id" INTEGER NOT NULL,

CONSTRAINT "volunteers_on_prerequisites_pkey" PRIMARY KEY ("volunteers_id","prerequisites_id")
);

-- CreateIndex
CREATE UNIQUE INDEX "volunteers_userId_key" ON "volunteers"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "employees_userId_key" ON "employees"("userId");

-- AddForeignKey
ALTER TABLE "postings" ADD CONSTRAINT "postings_branch_id_fkey" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "shifts" ADD CONSTRAINT "shifts_posting_id_fkey" FOREIGN KEY ("posting_id") REFERENCES "postings"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "signups" ADD CONSTRAINT "signups_shifts_id_fkey" FOREIGN KEY ("shifts_id") REFERENCES "shifts"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "volunteers" ADD CONSTRAINT "volunteers_default_branch_id_fkey" FOREIGN KEY ("default_branch_id") REFERENCES "branches"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employees" ADD CONSTRAINT "employees_branch_id_fkey" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "postings_on_skills" ADD CONSTRAINT "postings_on_skills_postings_id_fkey" FOREIGN KEY ("postings_id") REFERENCES "postings"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "postings_on_skills" ADD CONSTRAINT "postings_on_skills_skills_id_fkey" FOREIGN KEY ("skills_id") REFERENCES "skills"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "postings_on_prerequisites" ADD CONSTRAINT "postings_on_prerequisites_postings_id_fkey" FOREIGN KEY ("postings_id") REFERENCES "postings"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "postings_on_prerequisites" ADD CONSTRAINT "postings_on_prerequisites_prerequisites_id_fkey" FOREIGN KEY ("prerequisites_id") REFERENCES "prerequisites"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "postings_on_employees_pocs" ADD CONSTRAINT "postings_on_employees_pocs_posting_id_fkey" FOREIGN KEY ("posting_id") REFERENCES "postings"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "postings_on_employees_pocs" ADD CONSTRAINT "postings_on_employees_pocs_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "volunteers_on_skills" ADD CONSTRAINT "volunteers_on_skills_volunteer_id_fkey" FOREIGN KEY ("volunteer_id") REFERENCES "volunteers"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "volunteers_on_skills" ADD CONSTRAINT "volunteers_on_skills_skills_id_fkey" FOREIGN KEY ("skills_id") REFERENCES "skills"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "volunteers_on_prerequisites" ADD CONSTRAINT "volunteers_on_prerequisites_volunteers_id_fkey" FOREIGN KEY ("volunteers_id") REFERENCES "volunteers"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "volunteers_on_prerequisites" ADD CONSTRAINT "volunteers_on_prerequisites_prerequisites_id_fkey" FOREIGN KEY ("prerequisites_id") REFERENCES "prerequisites"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
183 changes: 177 additions & 6 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ model Entity {
}

model User {
id Int @id @default(autoincrement())
firstName String @map("first_name")
lastName String @map("last_name")
authId String @unique @map("auth_id")
role Role
id Int @id @default(autoincrement())
firstName String @map("first_name")
lastName String @map("last_name")
authId String @unique @map("auth_id")
role Role

@@map("users")
}
Expand All @@ -36,7 +36,178 @@ enum Letters {
D
}

enum SignupStatus {
PENDING
CONFIRMED
CANCELED
}

enum PostingType {
INDIVIDUAL
GROUP
}

enum Role {
User
User
Admin
}

model Posting {
id Int @id @default(autoincrement())
branchId Int @map("branch_id")
branch Branch @relation(fields: [branchId], references: [id])
shifts Shift[]
skills PostingOnSkill[]
prerequisite PostingOnPrerequisite[]
employee PostingOnEmployeePoc[]
title String
type PostingType
purpose String
responsibilitie String
tasks String
desiredQualitie String @map("desired_qualities")
mandatoryActivities String @map("mandatory_activities")
benefits String
workingConditions String @map("working_conditions")
numVolunteers Int @default(1) @map("num_volunteers")

@@map("postings")
}

model Skill {
id Int @id @default(autoincrement())
name String
postings PostingOnSkill[]
volunteers VolunteerOnSkill[]

@@map("skills")
}

model Prerequisite {
id Int @id @default(autoincrement())
name String
completed Boolean
postings PostingOnPrerequisite[]
volunteers VolunteerOnPrerequisite[]

@@map("prerequisites")
}

model Branch {
id Int @id @default(autoincrement())
posting Posting[]
name String
employees Employee[]
volunteers Volunteer[]

@@map("branches")
}

model Shift {
id Int @id @default(autoincrement())
postingId Int @map("posting_id")
posting Posting @relation(fields: [postingId], references: [id])
startTime DateTime @map("start_time")
endTime DateTime @map("end_time")
repeatInterval Int? @map("repeat_interval")
repeatEnd DateTime? @map("repeat_end")
signups Signup[]

@@map("shifts")
}

model Signup {
id Int @id @default(autoincrement())
shift Shift @relation(fields: [shiftId], references: [id])
shiftId Int @map("shifts_id")
userId Int
status SignupStatus
numVolunteers Int @default(1) @map("num_volunteers")

@@map("signups")
}

model Availability {
id Int @id @default(autoincrement())
userId Int
startTime DateTime @map("start_time")
endTime DateTime @map("end_time")
repeatInterval Int? @map("repeat_interval")
repeatEnd DateTime? @map("repeat_end")

@@map("availabilities")
}

model Volunteer {
id Int @id @default(autoincrement())
userId Int @unique
defaultBranchId Int @map("default_branch_id")
branch Branch @relation(fields: [defaultBranchId], references: [id])
hireDate DateTime @map("hire_date")
skills VolunteerOnSkill[]
prerequisites VolunteerOnPrerequisite[]
dateOfBirth DateTime @map("date_of_birth")
pronouns String

@@map("volunteers")
}

model Employee {
id Int @id @default(autoincrement())
userId Int @unique
branchId Int @map("branch_id")
branch Branch @relation(fields: [branchId], references: [id])
postings PostingOnEmployeePoc[]

@@map("employees")
}

model PostingOnSkill {
posting Posting @relation(fields: [postingId], references: [id])
postingId Int @map("postings_id")
skill Skill @relation(fields: [skillId], references: [id])
skillId Int @map("skills_id")

@@id([postingId, skillId])
@@map("postings_on_skills")
}

model PostingOnPrerequisite {
posting Posting @relation(fields: [postingId], references: [id])
postingId Int @map("postings_id")
prerequisite Prerequisite @relation(fields: [prerequisiteId], references: [id])
prerequisiteId Int @map("prerequisites_id")

@@id([postingId, prerequisiteId])
@@map("postings_on_prerequisites")
}

model PostingOnEmployeePoc {
postingId Int @map("posting_id")
posting Posting @relation(fields: [postingId], references: [id])
employeeId Int @map("employee_id")
employee Employee @relation(fields: [employeeId], references: [id])

@@id([postingId, employeeId])
@@map("postings_on_employees_pocs")
}

model VolunteerOnSkill {
volunteer Volunteer @relation(fields: [volunteerId], references: [id])
volunteerId Int @map("volunteer_id")
skill Skill @relation(fields: [skillId], references: [id])
skillId Int @map("skills_id")

@@id([volunteerId, skillId])
@@map("volunteers_on_skills")
}

model VolunteerOnPrerequisite {
volunteer Volunteer @relation(fields: [volunteerId], references: [id])
volunteerId Int @map("volunteers_id")
prerequisite Prerequisite @relation(fields: [prerequisiteId], references: [id])
prerequisiteId Int @map("prerequisites_id")

@@id([volunteerId, prerequisiteId])
@@map("volunteers_on_prerequisites")
}