From af7e556be861b7ebd2ad3d8a708eeefe561ba177 Mon Sep 17 00:00:00 2001 From: Niels Mokkenstorm Date: Mon, 17 Nov 2025 23:55:55 +0100 Subject: [PATCH] feat(server): add database migrations for applications, vacancies, and enhancements --- .../migration.sql | 3 ++ .../migration.sql | 41 +++++++++++++++++++ .../migration.sql | 19 +++++++++ .../migration.sql | 12 ++++++ .../migration.sql | 11 +++++ .../migration.sql | 12 ++++++ .../migration.sql | 30 ++++++++++++++ .../migration.sql | 2 + .../migration.sql | 2 + 9 files changed, 132 insertions(+) create mode 100644 apps/server/prisma/migrations/20251026160424_rename_user_organizations_to_memberships/migration.sql create mode 100644 apps/server/prisma/migrations/20251026203330_refactor_cv_and_vacancy_entities/migration.sql create mode 100644 apps/server/prisma/migrations/20251026203431_add_job_type_entity/migration.sql create mode 100644 apps/server/prisma/migrations/20251026203550_add_vacancy_owner_and_public/migration.sql create mode 100644 apps/server/prisma/migrations/20251026204357_remove_userid_from_vacancy/migration.sql create mode 100644 apps/server/prisma/migrations/20251026204432_add_application_status_enum/migration.sql create mode 100644 apps/server/prisma/migrations/20251026204631_add_application_status_entity/migration.sql create mode 100644 apps/server/prisma/migrations/20251029130211_add_min_max_salary/migration.sql create mode 100644 apps/server/prisma/migrations/20251029135936_migrate_salary_to_min_max/migration.sql diff --git a/apps/server/prisma/migrations/20251026160424_rename_user_organizations_to_memberships/migration.sql b/apps/server/prisma/migrations/20251026160424_rename_user_organizations_to_memberships/migration.sql new file mode 100644 index 0000000..fb79816 --- /dev/null +++ b/apps/server/prisma/migrations/20251026160424_rename_user_organizations_to_memberships/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable: Rename user_organizations table to memberships +ALTER TABLE "user_organizations" RENAME TO "memberships"; + diff --git a/apps/server/prisma/migrations/20251026203330_refactor_cv_and_vacancy_entities/migration.sql b/apps/server/prisma/migrations/20251026203330_refactor_cv_and_vacancy_entities/migration.sql new file mode 100644 index 0000000..5b35afc --- /dev/null +++ b/apps/server/prisma/migrations/20251026203330_refactor_cv_and_vacancy_entities/migration.sql @@ -0,0 +1,41 @@ +/* + Warnings: + + - You are about to drop the column `company` on the `vacancies` table. All the data in the column will be lost. + - You are about to drop the column `jobType` on the `vacancies` table. All the data in the column will be lost. + - Added the required column `companyId` to the `vacancies` table without a default value. This is not possible if the table is not empty. + - Added the required column `roleId` to the `vacancies` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "vacancies" DROP COLUMN "company", +DROP COLUMN "jobType", +ADD COLUMN "companyId" TEXT NOT NULL, +ADD COLUMN "levelId" TEXT, +ADD COLUMN "roleId" TEXT NOT NULL; + +-- CreateTable +CREATE TABLE "_SkillToVacancy" ( + "A" TEXT NOT NULL, + "B" TEXT NOT NULL, + + CONSTRAINT "_SkillToVacancy_AB_pkey" PRIMARY KEY ("A","B") +); + +-- CreateIndex +CREATE INDEX "_SkillToVacancy_B_index" ON "_SkillToVacancy"("B"); + +-- AddForeignKey +ALTER TABLE "vacancies" ADD CONSTRAINT "vacancies_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "vacancies" ADD CONSTRAINT "vacancies_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "roles"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "vacancies" ADD CONSTRAINT "vacancies_levelId_fkey" FOREIGN KEY ("levelId") REFERENCES "levels"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_SkillToVacancy" ADD CONSTRAINT "_SkillToVacancy_A_fkey" FOREIGN KEY ("A") REFERENCES "skills"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_SkillToVacancy" ADD CONSTRAINT "_SkillToVacancy_B_fkey" FOREIGN KEY ("B") REFERENCES "vacancies"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/server/prisma/migrations/20251026203431_add_job_type_entity/migration.sql b/apps/server/prisma/migrations/20251026203431_add_job_type_entity/migration.sql new file mode 100644 index 0000000..b8d1954 --- /dev/null +++ b/apps/server/prisma/migrations/20251026203431_add_job_type_entity/migration.sql @@ -0,0 +1,19 @@ +-- AlterTable +ALTER TABLE "vacancies" ADD COLUMN "jobTypeId" TEXT; + +-- CreateTable +CREATE TABLE "job_types" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "job_types_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "job_types_name_key" ON "job_types"("name"); + +-- AddForeignKey +ALTER TABLE "vacancies" ADD CONSTRAINT "vacancies_jobTypeId_fkey" FOREIGN KEY ("jobTypeId") REFERENCES "job_types"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/server/prisma/migrations/20251026203550_add_vacancy_owner_and_public/migration.sql b/apps/server/prisma/migrations/20251026203550_add_vacancy_owner_and_public/migration.sql new file mode 100644 index 0000000..1d15c31 --- /dev/null +++ b/apps/server/prisma/migrations/20251026203550_add_vacancy_owner_and_public/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - Added the required column `ownerId` to the `vacancies` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "vacancies" ADD COLUMN "isPublic" BOOLEAN NOT NULL DEFAULT false, +ADD COLUMN "ownerId" TEXT NOT NULL; + +-- AddForeignKey +ALTER TABLE "vacancies" ADD CONSTRAINT "vacancies_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/server/prisma/migrations/20251026204357_remove_userid_from_vacancy/migration.sql b/apps/server/prisma/migrations/20251026204357_remove_userid_from_vacancy/migration.sql new file mode 100644 index 0000000..0c4b587 --- /dev/null +++ b/apps/server/prisma/migrations/20251026204357_remove_userid_from_vacancy/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - You are about to drop the column `userId` on the `vacancies` table. All the data in the column will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "public"."vacancies" DROP CONSTRAINT "vacancies_userId_fkey"; + +-- AlterTable +ALTER TABLE "vacancies" DROP COLUMN "userId"; diff --git a/apps/server/prisma/migrations/20251026204432_add_application_status_enum/migration.sql b/apps/server/prisma/migrations/20251026204432_add_application_status_enum/migration.sql new file mode 100644 index 0000000..6c5eca3 --- /dev/null +++ b/apps/server/prisma/migrations/20251026204432_add_application_status_enum/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - The `status` column on the `applications` table would be dropped and recreated. This will lead to data loss if there is data in the column. + +*/ +-- CreateEnum +CREATE TYPE "ApplicationStatus" AS ENUM ('PENDING', 'ACCEPTED', 'REJECTED', 'WITHDRAWN'); + +-- AlterTable +ALTER TABLE "applications" DROP COLUMN "status", +ADD COLUMN "status" "ApplicationStatus" NOT NULL DEFAULT 'PENDING'; diff --git a/apps/server/prisma/migrations/20251026204631_add_application_status_entity/migration.sql b/apps/server/prisma/migrations/20251026204631_add_application_status_entity/migration.sql new file mode 100644 index 0000000..5babd85 --- /dev/null +++ b/apps/server/prisma/migrations/20251026204631_add_application_status_entity/migration.sql @@ -0,0 +1,30 @@ +/* + Warnings: + + - You are about to drop the column `status` on the `applications` table. All the data in the column will be lost. + - Added the required column `statusId` to the `applications` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "applications" DROP COLUMN "status", +ADD COLUMN "statusId" TEXT NOT NULL; + +-- DropEnum +DROP TYPE "public"."ApplicationStatus"; + +-- CreateTable +CREATE TABLE "application_statuses" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "application_statuses_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "application_statuses_name_key" ON "application_statuses"("name"); + +-- AddForeignKey +ALTER TABLE "applications" ADD CONSTRAINT "applications_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "application_statuses"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/server/prisma/migrations/20251029130211_add_min_max_salary/migration.sql b/apps/server/prisma/migrations/20251029130211_add_min_max_salary/migration.sql new file mode 100644 index 0000000..9903a31 --- /dev/null +++ b/apps/server/prisma/migrations/20251029130211_add_min_max_salary/migration.sql @@ -0,0 +1,2 @@ +ALTER TABLE "vacancies" ADD COLUMN "minSalary" INTEGER; +ALTER TABLE "vacancies" ADD COLUMN "maxSalary" INTEGER; diff --git a/apps/server/prisma/migrations/20251029135936_migrate_salary_to_min_max/migration.sql b/apps/server/prisma/migrations/20251029135936_migrate_salary_to_min_max/migration.sql new file mode 100644 index 0000000..b536ff4 --- /dev/null +++ b/apps/server/prisma/migrations/20251029135936_migrate_salary_to_min_max/migration.sql @@ -0,0 +1,2 @@ +-- Drop the salary column since we now use minSalary and maxSalary +ALTER TABLE "vacancies" DROP COLUMN "salary"; \ No newline at end of file -- 2.51.2