From 4c69bcf2c1c3494c590010a27f69a48c0ca906ba Mon Sep 17 00:00:00 2001 From: Toan Hoang Minh Date: Fri, 31 Jul 2026 14:53:57 +0700 Subject: [PATCH] feat: add Employee Prisma model + migration Employee directory entity per docs/asset-license-management.md's data model table (id, name, department, manager). department stays a plain String for now (not a separate Department entity). managerId is a nullable self-relation (EmployeeManager) - top-level employees have managerId = null. --- .../20260731075337_add_employee/migration.sql | 13 +++++++++++++ prisma/schema.prisma | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 prisma/migrations/20260731075337_add_employee/migration.sql diff --git a/prisma/migrations/20260731075337_add_employee/migration.sql b/prisma/migrations/20260731075337_add_employee/migration.sql new file mode 100644 index 0000000..31c0c75 --- /dev/null +++ b/prisma/migrations/20260731075337_add_employee/migration.sql @@ -0,0 +1,13 @@ +-- CreateTable +CREATE TABLE "employees" ( + "id" UUID NOT NULL, + "name" TEXT NOT NULL, + "department" TEXT NOT NULL, + "manager_id" UUID, + "created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "employees_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "employees" ADD CONSTRAINT "employees_manager_id_fkey" FOREIGN KEY ("manager_id") REFERENCES "employees"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index eb3c65e..18c65c7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -39,6 +39,23 @@ model Request { @@map("requests") } +// Employee directory — see docs/asset-license-management.md's "Data model +// (sơ bộ)" table (id, tên, phòng ban, manager). `department` is deliberately +// a plain String for now, not a separate Department entity — that's a +// possible future normalization, not built yet. `managerId` is a nullable +// self-relation: top-level employees (no manager) have `managerId = null`. +model Employee { + id String @id @default(uuid()) @db.Uuid + name String + department String + managerId String? @map("manager_id") @db.Uuid + manager Employee? @relation("EmployeeManager", fields: [managerId], references: [id]) + reports Employee[] @relation("EmployeeManager") + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) + + @@map("employees") +} + // Minimal internal auth accounts — NOT company SSO (deliberately ruled out, // see CLAUDE.md / auth decision notes). A handful of trusted IT staff // accounts, created by hand via scripts/create-user.ts, no self-registration.