feat: relate Request.employee_id to Employee via FK
Retrofits Request.employeeId from a free-text String with no referential integrity to a real relation: employeeId String @db.Uuid + employee Employee @relation(...), plus the inverse Employee.requests back-relation field. Migration alters requests.employee_id from TEXT to UUID with an FK constraint (drop+recreate, confirmed empty table - no production/dev data existed to migrate).
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Changed the type of `employee_id` on the `requests` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "requests" DROP COLUMN "employee_id",
|
||||
ADD COLUMN "employee_id" UUID NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "requests" ADD CONSTRAINT "requests_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -27,7 +27,13 @@ enum RequestType {
|
||||
|
||||
model Request {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
employeeId String @map("employee_id")
|
||||
// Was a free-text String with no referential integrity — retrofitted to a
|
||||
// real FK once Employee records existed to point to (see Employee model
|
||||
// above). No production data existed at the time of this change (`requests`
|
||||
// table was empty), so this was a plain column-type migration, not a
|
||||
// backfill.
|
||||
employeeId String @map("employee_id") @db.Uuid
|
||||
employee Employee @relation(fields: [employeeId], references: [id])
|
||||
type RequestType
|
||||
reason String
|
||||
// Only the 'Draft' state is implemented so far. Deliberately kept as a
|
||||
@@ -51,6 +57,7 @@ model Employee {
|
||||
managerId String? @map("manager_id") @db.Uuid
|
||||
manager Employee? @relation("EmployeeManager", fields: [managerId], references: [id])
|
||||
reports Employee[] @relation("EmployeeManager")
|
||||
requests Request[]
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
|
||||
@@map("employees")
|
||||
|
||||
Reference in New Issue
Block a user