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

Adding DB exercise YCL #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DB_PASSWORD=D1ymf8wyQEGthFR1E9xhCq
DB_USER=LTIdbUser
DB_NAME=LTIdb
DB_PASSWORD=postgres
DB_USER=postgres
DB_NAME=postgres
DB_PORT=5432
DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"

5,591 changes: 4,491 additions & 1,100 deletions backend/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prisma:init": "npx prisma init",
"prisma:generate": "npx prisma generate",
"start:prod": "npm run build && npm start",
"test": "jest"
"test": "jest"
},
"keywords": [],
"author": "",
Expand All @@ -27,18 +27,18 @@
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.9",
"@types/jest": "^29.5.12",
"@types/multer": "^1.4.11",
"@types/node": "^20.12.10",
"eslint": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"prisma": "^5.13.0",
"prisma": "^5.19.1",
"ts-jest": "^29.2.5",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",
"typescript": "^4.9.5",
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.2.5"
"typescript": "^4.9.5"
}
}
59 changes: 59 additions & 0 deletions backend/prisma/migrations/20240911005558_start/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- CreateTable
CREATE TABLE "Candidate" (
"id" SERIAL NOT NULL,
"firstName" VARCHAR(100) NOT NULL,
"lastName" VARCHAR(100) NOT NULL,
"email" VARCHAR(255) NOT NULL,
"phone" VARCHAR(15),
"address" VARCHAR(100),

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

-- CreateTable
CREATE TABLE "Education" (
"id" SERIAL NOT NULL,
"institution" VARCHAR(100) NOT NULL,
"title" VARCHAR(250) NOT NULL,
"startDate" TIMESTAMP(3) NOT NULL,
"endDate" TIMESTAMP(3),
"candidateId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "WorkExperience" (
"id" SERIAL NOT NULL,
"company" VARCHAR(100) NOT NULL,
"position" VARCHAR(100) NOT NULL,
"description" VARCHAR(200),
"startDate" TIMESTAMP(3) NOT NULL,
"endDate" TIMESTAMP(3),
"candidateId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "Resume" (
"id" SERIAL NOT NULL,
"filePath" VARCHAR(500) NOT NULL,
"fileType" VARCHAR(50) NOT NULL,
"uploadDate" TIMESTAMP(3) NOT NULL,
"candidateId" INTEGER NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "Candidate_email_key" ON "Candidate"("email");

-- AddForeignKey
ALTER TABLE "Education" ADD CONSTRAINT "Education_candidateId_fkey" FOREIGN KEY ("candidateId") REFERENCES "Candidate"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "WorkExperience" ADD CONSTRAINT "WorkExperience_candidateId_fkey" FOREIGN KEY ("candidateId") REFERENCES "Candidate"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Resume" ADD CONSTRAINT "Resume_candidateId_fkey" FOREIGN KEY ("candidateId") REFERENCES "Candidate"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
198 changes: 198 additions & 0 deletions backend/prisma/migrations/20240911005655_new_tables/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
Warnings:

- You are about to drop the column `address` on the `Candidate` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "Candidate" DROP COLUMN "address";

-- CreateTable
CREATE TABLE "Company" (
"id" SERIAL NOT NULL,
"name" VARCHAR(255) NOT NULL,

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

-- CreateTable
CREATE TABLE "Employee" (
"id" SERIAL NOT NULL,
"companyId" INTEGER NOT NULL,
"name" VARCHAR(255) NOT NULL,
"email" VARCHAR(255) NOT NULL,
"roleId" INTEGER NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,

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

-- CreateTable
CREATE TABLE "Role" (
"id" SERIAL NOT NULL,
"name" VARCHAR(100) NOT NULL,

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

-- CreateTable
CREATE TABLE "Position" (
"id" SERIAL NOT NULL,
"companyId" INTEGER NOT NULL,
"interviewFlowId" INTEGER NOT NULL,
"title" VARCHAR(255) NOT NULL,
"description" TEXT,
"status" VARCHAR(50),
"isVisible" BOOLEAN NOT NULL DEFAULT true,
"locationId" INTEGER NOT NULL,
"jobDescription" TEXT,
"requirements" TEXT,
"responsibilities" TEXT,
"salaryMin" DOUBLE PRECISION,
"salaryMax" DOUBLE PRECISION,
"employmentTypeId" INTEGER NOT NULL,
"benefits" TEXT,
"companyDescription" TEXT,
"applicationDeadline" TIMESTAMP(3),
"contactInfo" VARCHAR(255),

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

-- CreateTable
CREATE TABLE "Location" (
"id" SERIAL NOT NULL,
"name" VARCHAR(255) NOT NULL,

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

-- CreateTable
CREATE TABLE "EmploymentType" (
"id" SERIAL NOT NULL,
"type" VARCHAR(50) NOT NULL,

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

-- CreateTable
CREATE TABLE "InterviewFlow" (
"id" SERIAL NOT NULL,
"description" TEXT,

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

-- CreateTable
CREATE TABLE "InterviewStep" (
"id" SERIAL NOT NULL,
"interviewFlowId" INTEGER NOT NULL,
"interviewTypeId" INTEGER NOT NULL,
"name" VARCHAR(255) NOT NULL,
"orderIndex" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "InterviewType" (
"id" SERIAL NOT NULL,
"name" VARCHAR(255) NOT NULL,
"description" TEXT,

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

-- CreateTable
CREATE TABLE "Address" (
"id" SERIAL NOT NULL,
"candidateId" INTEGER NOT NULL,
"address" VARCHAR(255) NOT NULL,

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

-- CreateTable
CREATE TABLE "Application" (
"id" SERIAL NOT NULL,
"positionId" INTEGER NOT NULL,
"candidateId" INTEGER NOT NULL,
"applicationDate" TIMESTAMP(3) NOT NULL,
"status" VARCHAR(50),
"notes" TEXT,

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

-- CreateTable
CREATE TABLE "Interview" (
"id" SERIAL NOT NULL,
"applicationId" INTEGER NOT NULL,
"interviewStepId" INTEGER NOT NULL,
"employeeId" INTEGER NOT NULL,
"interviewDate" TIMESTAMP(3) NOT NULL,
"result" VARCHAR(50),
"score" INTEGER,
"notes" TEXT,

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

-- CreateIndex
CREATE UNIQUE INDEX "Employee_email_key" ON "Employee"("email");

-- AddForeignKey
ALTER TABLE "Employee" ADD CONSTRAINT "Employee_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Employee" ADD CONSTRAINT "Employee_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Position" ADD CONSTRAINT "Position_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Position" ADD CONSTRAINT "Position_interviewFlowId_fkey" FOREIGN KEY ("interviewFlowId") REFERENCES "InterviewFlow"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Position" ADD CONSTRAINT "Position_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Position" ADD CONSTRAINT "Position_employmentTypeId_fkey" FOREIGN KEY ("employmentTypeId") REFERENCES "EmploymentType"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "InterviewStep" ADD CONSTRAINT "InterviewStep_interviewFlowId_fkey" FOREIGN KEY ("interviewFlowId") REFERENCES "InterviewFlow"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "InterviewStep" ADD CONSTRAINT "InterviewStep_interviewTypeId_fkey" FOREIGN KEY ("interviewTypeId") REFERENCES "InterviewType"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Address" ADD CONSTRAINT "Address_candidateId_fkey" FOREIGN KEY ("candidateId") REFERENCES "Candidate"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Application" ADD CONSTRAINT "Application_positionId_fkey" FOREIGN KEY ("positionId") REFERENCES "Position"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Application" ADD CONSTRAINT "Application_candidateId_fkey" FOREIGN KEY ("candidateId") REFERENCES "Candidate"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Interview" ADD CONSTRAINT "Interview_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "Application"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Interview" ADD CONSTRAINT "Interview_interviewStepId_fkey" FOREIGN KEY ("interviewStepId") REFERENCES "InterviewStep"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Interview" ADD CONSTRAINT "Interview_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee"("id") ON DELETE RESTRICT ON UPDATE CASCADE;


-- Indexes
CREATE UNIQUE INDEX idx_candidate_email ON candidate(email);
CREATE INDEX idx_education_candidate_id ON education(candidate_id);
CREATE INDEX idx_work_experience_candidate_id ON work_experience(candidate_id);
CREATE INDEX idx_resume_candidate_id ON resume(candidate_id);
CREATE UNIQUE INDEX idx_employee_email ON employee(email);
CREATE INDEX idx_interview_step_order_index ON interview_step(order_index);
CREATE INDEX idx_position_status ON position(status);
CREATE INDEX idx_position_is_visible ON position(is_visible);
CREATE INDEX idx_application_status ON application(status);
CREATE INDEX idx_interview_interview_date ON interview(interview_date);
CREATE INDEX idx_address_candidate_id ON address(candidate_id);
Loading