From 8405afc7359f7dba5d3eddb989ff2518e394df15 Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Wed, 19 Mar 2025 12:08:41 -0400 Subject: [PATCH 1/3] feat: add migration for vendor table and related schema updates - Created a new migration to add the Vendor table and associated columns, including foreign key constraints and unique indexes. - Introduced new enums for task status and attachment types. - Updated existing tables to include necessary columns and constraints, ensuring data integrity. - Cleared existing assignments in VendorTaskAssignment to prevent unique constraint violations. --- .../migration.sql | 247 ++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql diff --git a/packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql b/packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql new file mode 100644 index 0000000000..5a36d6a10b --- /dev/null +++ b/packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql @@ -0,0 +1,247 @@ +/* + Warnings: + + - A unique constraint covering the columns `[taskId,employeeId]` on the table `VendorTaskAssignment` will be added. If there are existing duplicate values, this will fail. + - Added the required column `fileUrl` to the `VendorAttachment` table without a default value. This is not possible if the table is not empty. + - Added the required column `name` to the `VendorAttachment` table without a default value. This is not possible if the table is not empty. + - Added the required column `ownerId` to the `VendorComment` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `VendorComment` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `VendorContact` table without a default value. This is not possible if the table is not empty. + - Added the required column `description` to the `VendorTask` table without a default value. This is not possible if the table is not empty. + - Added the required column `title` to the `VendorTask` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `VendorTask` table without a default value. This is not possible if the table is not empty. + - Added the required column `employeeId` to the `VendorTaskAssignment` table without a default value. This is not possible if the table is not empty. + - Added the required column `taskId` to the `VendorTaskAssignment` table without a default value. This is not possible if the table is not empty. + - Added the required column `fileUrl` to the `VendorTaskAttachment` table without a default value. This is not possible if the table is not empty. + - Added the required column `name` to the `VendorTaskAttachment` table without a default value. This is not possible if the table is not empty. + - Added the required column `taskId` to the `VendorTaskAttachment` table without a default value. This is not possible if the table is not empty. + - Added the required column `content` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty. + - Added the required column `ownerId` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty. + - Added the required column `taskId` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty. + +*/ +-- CreateEnum +CREATE TYPE "RiskLikelihood" AS ENUM ('very_low', 'low', 'medium', 'high', 'very_high'); + +-- CreateEnum +CREATE TYPE "RiskImpact" AS ENUM ('very_low', 'low', 'medium', 'high', 'very_high'); + +-- CreateEnum +CREATE TYPE "VendorTaskStatus" AS ENUM ('open', 'in_progress', 'completed', 'cancelled'); + +-- CreateEnum +CREATE TYPE "VendorAttachmentType" AS ENUM ('file', 'image', 'document', 'other'); + +-- DropForeignKey +ALTER TABLE "Vendor" DROP CONSTRAINT "Vendor_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorAttachment" DROP CONSTRAINT "VendorAttachment_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorAttachment" DROP CONSTRAINT "VendorAttachment_vendorId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorComment" DROP CONSTRAINT "VendorComment_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorComment" DROP CONSTRAINT "VendorComment_vendorId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorContact" DROP CONSTRAINT "VendorContact_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorContact" DROP CONSTRAINT "VendorContact_vendorId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTask" DROP CONSTRAINT "VendorTask_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTask" DROP CONSTRAINT "VendorTask_vendorId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTaskAssignment" DROP CONSTRAINT "VendorTaskAssignment_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTaskAssignment" DROP CONSTRAINT "VendorTaskAssignment_vendorId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTaskAttachment" DROP CONSTRAINT "VendorTaskAttachment_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTaskAttachment" DROP CONSTRAINT "VendorTaskAttachment_vendorId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTaskComment" DROP CONSTRAINT "VendorTaskComment_organizationId_fkey"; + +-- DropForeignKey +ALTER TABLE "VendorTaskComment" DROP CONSTRAINT "VendorTaskComment_vendorId_fkey"; + +-- AlterTable +ALTER TABLE "Vendor" ADD COLUMN "ownerId" TEXT; + +-- AlterTable +ALTER TABLE "VendorAttachment" ADD COLUMN "fileKey" TEXT, +ADD COLUMN "fileUrl" TEXT NOT NULL, +ADD COLUMN "name" TEXT NOT NULL, +ADD COLUMN "ownerId" TEXT, +ADD COLUMN "type" "VendorAttachmentType" NOT NULL DEFAULT 'file', +ADD COLUMN "uploadedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "VendorComment" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "ownerId" TEXT NOT NULL, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; + +-- AlterTable +ALTER TABLE "VendorContact" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; + +-- AlterTable +ALTER TABLE "VendorTask" ADD COLUMN "completedAt" TIMESTAMP(3), +ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "description" TEXT NOT NULL, +ADD COLUMN "dueDate" TIMESTAMP(3), +ADD COLUMN "notifiedAt" TIMESTAMP(3), +ADD COLUMN "ownerId" TEXT, +ADD COLUMN "status" "VendorTaskStatus" NOT NULL DEFAULT 'open', +ADD COLUMN "title" TEXT NOT NULL, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; + +-- AlterTable +ALTER TABLE "VendorTaskAssignment" ADD COLUMN "assignedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "employeeId" TEXT NOT NULL, +ADD COLUMN "taskId" TEXT NOT NULL; + +-- AlterTable +ALTER TABLE "VendorTaskAttachment" ADD COLUMN "fileKey" TEXT, +ADD COLUMN "fileUrl" TEXT NOT NULL, +ADD COLUMN "name" TEXT NOT NULL, +ADD COLUMN "ownerId" TEXT, +ADD COLUMN "taskId" TEXT NOT NULL, +ADD COLUMN "type" "VendorAttachmentType" NOT NULL DEFAULT 'file', +ADD COLUMN "uploadedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "VendorTaskComment" ADD COLUMN "content" TEXT NOT NULL, +ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "ownerId" TEXT NOT NULL, +ADD COLUMN "taskId" TEXT NOT NULL, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; + +-- CreateIndex +CREATE INDEX "Vendor_ownerId_idx" ON "Vendor"("ownerId"); + +-- CreateIndex +CREATE INDEX "VendorAttachment_ownerId_idx" ON "VendorAttachment"("ownerId"); + +-- CreateIndex +CREATE INDEX "VendorComment_ownerId_idx" ON "VendorComment"("ownerId"); + +-- CreateIndex +CREATE INDEX "VendorTask_ownerId_idx" ON "VendorTask"("ownerId"); + +-- CreateIndex +CREATE INDEX "VendorTaskAssignment_taskId_idx" ON "VendorTaskAssignment"("taskId"); + +-- CreateIndex +CREATE INDEX "VendorTaskAssignment_employeeId_idx" ON "VendorTaskAssignment"("employeeId"); + +-- CreateIndex +CREATE UNIQUE INDEX "VendorTaskAssignment_taskId_employeeId_key" ON "VendorTaskAssignment"("taskId", "employeeId"); + +-- CreateIndex +CREATE INDEX "VendorTaskAttachment_taskId_idx" ON "VendorTaskAttachment"("taskId"); + +-- CreateIndex +CREATE INDEX "VendorTaskAttachment_ownerId_idx" ON "VendorTaskAttachment"("ownerId"); + +-- CreateIndex +CREATE INDEX "VendorTaskComment_taskId_idx" ON "VendorTaskComment"("taskId"); + +-- CreateIndex +CREATE INDEX "VendorTaskComment_ownerId_idx" ON "VendorTaskComment"("ownerId"); + +-- AddForeignKey +ALTER TABLE "Vendor" ADD CONSTRAINT "Vendor_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Vendor" ADD CONSTRAINT "Vendor_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorContact" ADD CONSTRAINT "VendorContact_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorContact" ADD CONSTRAINT "VendorContact_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorComment" ADD CONSTRAINT "VendorComment_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorComment" ADD CONSTRAINT "VendorComment_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorComment" ADD CONSTRAINT "VendorComment_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorAttachment" ADD CONSTRAINT "VendorAttachment_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorAttachment" ADD CONSTRAINT "VendorAttachment_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorAttachment" ADD CONSTRAINT "VendorAttachment_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTask" ADD CONSTRAINT "VendorTask_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTask" ADD CONSTRAINT "VendorTask_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTask" ADD CONSTRAINT "VendorTask_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAttachment" ADD CONSTRAINT "VendorTaskAttachment_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAttachment" ADD CONSTRAINT "VendorTaskAttachment_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAttachment" ADD CONSTRAINT "VendorTaskAttachment_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "VendorTask"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAttachment" ADD CONSTRAINT "VendorTaskAttachment_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskComment" ADD CONSTRAINT "VendorTaskComment_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskComment" ADD CONSTRAINT "VendorTaskComment_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskComment" ADD CONSTRAINT "VendorTaskComment_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "VendorTask"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskComment" ADD CONSTRAINT "VendorTaskComment_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAssignment" ADD CONSTRAINT "VendorTaskAssignment_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAssignment" ADD CONSTRAINT "VendorTaskAssignment_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAssignment" ADD CONSTRAINT "VendorTaskAssignment_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "VendorTask"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "VendorTaskAssignment" ADD CONSTRAINT "VendorTaskAssignment_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- Clear existing assignments to prevent unique constraint violations +DELETE FROM "VendorTaskAssignment"; + +-- CreateTable +CREATE TABLE "Vendor" ( + // ... existing code ... +); From f9fa43798c158bedea74ea6b41dde50701ef0366 Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Wed, 19 Mar 2025 12:08:50 -0400 Subject: [PATCH 2/3] feat: enhance vendor schema with new fields and enums - Added new fields to the Vendor model, including category, status, inherentRisk, and residualRisk with default values. - Introduced new enums for VendorCategory, VendorStatus, VendorInherentRisk, VendorResidualRisk, VendorTaskStatus, VendorAttachmentType, and updated related models. - Updated relationships and added cascading delete behavior for improved data integrity. - Enhanced VendorTaskAssignment model with unique constraints and additional indexing for better query performance. --- packages/db/prisma/schema/employee.prisma | 1 + packages/db/prisma/schema/schema.prisma | 68 +++++++++++ packages/db/prisma/schema/vendor.prisma | 141 +++++++++++++--------- 3 files changed, 154 insertions(+), 56 deletions(-) diff --git a/packages/db/prisma/schema/employee.prisma b/packages/db/prisma/schema/employee.prisma index c22488c279..a9ab29cf3c 100644 --- a/packages/db/prisma/schema/employee.prisma +++ b/packages/db/prisma/schema/employee.prisma @@ -41,6 +41,7 @@ model Employee { EmployeePolicyAcceptance EmployeePolicyAcceptance[] employeeTasks EmployeeTask[] RiskTaskAssignment RiskTaskAssignment[] + VendorTaskAssignment VendorTaskAssignment[] @@unique([email, organizationId]) @@index([organizationId]) diff --git a/packages/db/prisma/schema/schema.prisma b/packages/db/prisma/schema/schema.prisma index 987f1131a7..eeea8e2986 100644 --- a/packages/db/prisma/schema/schema.prisma +++ b/packages/db/prisma/schema/schema.prisma @@ -68,6 +68,12 @@ model User { OrganizationPolicy OrganizationPolicy[] OrganizationIntegrationResults OrganizationIntegrationResults[] IntegrationResultsComments OrganizationIntegrationResultsComments[] + Vendor Vendor[] + VendorComment VendorComment[] + VendorAttachment VendorAttachment[] + VendorTask VendorTask[] + VendorTaskAttachment VendorTaskAttachment[] + VendorTaskComment VendorTaskComment[] @@index([email]) @@index([organizationId]) @@ -309,3 +315,65 @@ enum PolicyStatus { archived needs_review } + +enum RiskLikelihood { + very_low + low + medium + high + very_high +} + +enum RiskImpact { + very_low + low + medium + high + very_high +} + +enum VendorCategory { + cloud + infrastructure + software_as_a_service + finance + marketing + sales + hr + other +} + +enum VendorStatus { + not_assessed + in_progress + assessed +} + +enum VendorInherentRisk { + low + medium + high + unknown +} + +enum VendorResidualRisk { + low + medium + high + unknown +} + +enum VendorTaskStatus { + open + in_progress + completed + cancelled +} + +enum VendorAttachmentType { + file + image + document + other +} + diff --git a/packages/db/prisma/schema/vendor.prisma b/packages/db/prisma/schema/vendor.prisma index 69fcaf8c73..75dfdb66ea 100644 --- a/packages/db/prisma/schema/vendor.prisma +++ b/packages/db/prisma/schema/vendor.prisma @@ -2,10 +2,16 @@ model Vendor { id String @id @default(cuid()) name String description String + category VendorCategory @default(other) + status VendorStatus @default(not_assessed) + inherentRisk VendorInherentRisk @default(unknown) + residualRisk VendorResidualRisk @default(unknown) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt organizationId String - organization Organization @relation(fields: [organizationId], references: [id]) + ownerId String? + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + owner User? @relation(fields: [ownerId], references: [id]) contacts VendorContact[] comments VendorComment[] attachments VendorAttachment[] @@ -13,12 +19,9 @@ model Vendor { taskAttachments VendorTaskAttachment[] taskComments VendorTaskComment[] taskAssignments VendorTaskAssignment[] - category VendorCategory @default(other) - status VendorStatus @default(not_assessed) - inherentRisk VendorInherentRisk @default(unknown) - residualRisk VendorResidualRisk @default(unknown) @@index([organizationId]) + @@index([ownerId]) @@index([category]) @@index([status]) @@index([inherentRisk]) @@ -32,8 +35,10 @@ model VendorContact { name String email String phone String - organization Organization @relation(fields: [organizationId], references: [id]) - Vendor Vendor @relation(fields: [vendorId], references: [id]) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade) @@index([organizationId]) @@index([vendorId]) @@ -43,96 +48,120 @@ model VendorComment { id String @id @default(cuid()) vendorId String organizationId String + ownerId String content String - organization Organization @relation(fields: [organizationId], references: [id]) - Vendor Vendor @relation(fields: [vendorId], references: [id]) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade) + vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade) @@index([organizationId]) + @@index([ownerId]) @@index([vendorId]) } model VendorAttachment { - id String @id @default(cuid()) + id String @id @default(cuid()) vendorId String organizationId String - Vendor Vendor? @relation(fields: [vendorId], references: [id]) - Organization Organization @relation(fields: [organizationId], references: [id]) + name String + fileUrl String + fileKey String? + type VendorAttachmentType @default(file) + uploadedAt DateTime @default(now()) + ownerId String? + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + owner User? @relation(fields: [ownerId], references: [id]) + vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade) @@index([organizationId]) + @@index([ownerId]) @@index([vendorId]) } model VendorTask { id String @id @default(cuid()) + title String + description String + status VendorTaskStatus @default(open) + dueDate DateTime? + notifiedAt DateTime? + completedAt DateTime? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt vendorId String + ownerId String? organizationId String - Vendor Vendor? @relation(fields: [vendorId], references: [id]) - Organization Organization @relation(fields: [organizationId], references: [id]) + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + owner User? @relation(fields: [ownerId], references: [id]) + vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade) + assignments VendorTaskAssignment[] + attachments VendorTaskAttachment[] + comments VendorTaskComment[] - @@index([organizationId]) @@index([vendorId]) + @@index([ownerId]) + @@index([organizationId]) } model VendorTaskAttachment { id String @id @default(cuid()) + taskId String vendorId String + name String + fileUrl String + fileKey String? + type VendorAttachmentType @default(file) + uploadedAt DateTime @default(now()) + ownerId String? organizationId String - Vendor Vendor? @relation(fields: [vendorId], references: [id]) - Organization Organization @relation(fields: [organizationId], references: [id]) + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + owner User? @relation(fields: [ownerId], references: [id]) + task VendorTask @relation(fields: [taskId], references: [id], onDelete: Cascade) + vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade) - @@index([organizationId]) + @@index([taskId]) @@index([vendorId]) + @@index([organizationId]) + @@index([ownerId]) } model VendorTaskComment { id String @id @default(cuid()) + taskId String vendorId String + ownerId String organizationId String - Vendor Vendor? @relation(fields: [vendorId], references: [id]) - Organization Organization @relation(fields: [organizationId], references: [id]) - - @@index([organizationId]) + content String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade) + task VendorTask @relation(fields: [taskId], references: [id], onDelete: Cascade) + vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade) + + @@index([taskId]) @@index([vendorId]) + @@index([ownerId]) + @@index([organizationId]) } model VendorTaskAssignment { id String @id @default(cuid()) + assignedAt DateTime @default(now()) + taskId String vendorId String + employeeId String organizationId String - Vendor Vendor? @relation(fields: [vendorId], references: [id]) - Organization Organization @relation(fields: [organizationId], references: [id]) + organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade) + employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade) + task VendorTask @relation(fields: [taskId], references: [id], onDelete: Cascade) + vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade) - @@index([organizationId]) + @@unique([taskId, employeeId]) + @@index([taskId]) @@index([vendorId]) -} - -enum VendorCategory { - cloud - infrastructure - software_as_a_service - finance - marketing - sales - hr - other -} - -enum VendorStatus { - not_assessed - in_progress - assessed -} - -enum VendorInherentRisk { - low - medium - high - unknown -} - -enum VendorResidualRisk { - low - medium - high - unknown + @@index([employeeId]) + @@index([organizationId]) } From 42b23917df7693e38ee5d5d54f1381d208c48042 Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Wed, 19 Mar 2025 12:11:50 -0400 Subject: [PATCH 3/3] cleanup migration --- .../20250319160739_added_vendor_table/migration.sql | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql b/packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql index 5a36d6a10b..77bbc98817 100644 --- a/packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql +++ b/packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql @@ -237,11 +237,3 @@ ALTER TABLE "VendorTaskAssignment" ADD CONSTRAINT "VendorTaskAssignment_taskId_f -- AddForeignKey ALTER TABLE "VendorTaskAssignment" ADD CONSTRAINT "VendorTaskAssignment_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- Clear existing assignments to prevent unique constraint violations -DELETE FROM "VendorTaskAssignment"; - --- CreateTable -CREATE TABLE "Vendor" ( - // ... existing code ... -);