From 69fa00012b3c2e37c1e8fa9311ed885871ddfe40 Mon Sep 17 00:00:00 2001 From: toanhoang Date: Sun, 2 Aug 2026 20:30:38 -0400 Subject: [PATCH] feat: add AssetCategory Prisma model + migration --- .../migration.sql | 12 ++++++++ prisma/schema.prisma | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 prisma/migrations/20260803003026_add_asset_category/migration.sql diff --git a/prisma/migrations/20260803003026_add_asset_category/migration.sql b/prisma/migrations/20260803003026_add_asset_category/migration.sql new file mode 100644 index 0000000..e024140 --- /dev/null +++ b/prisma/migrations/20260803003026_add_asset_category/migration.sql @@ -0,0 +1,12 @@ +-- CreateEnum +CREATE TYPE "AssetCategoryValueGroup" AS ENUM ('high_value', 'low_value'); + +-- CreateTable +CREATE TABLE "asset_categories" ( + "id" UUID NOT NULL, + "name" TEXT NOT NULL, + "value_group" "AssetCategoryValueGroup" NOT NULL, + "created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "asset_categories_pkey" PRIMARY KEY ("id") +); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 63c5938..4ef20bf 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -216,6 +216,35 @@ model PurchaseOrder { @@map("purchase_orders") } +// Fixed, closed set of 2 values tied to the domain (see docs/ +// asset-license-management.md's "## Phân loại tài sản: High-value vs +// Low-value/Consumable" section) — native Postgres enum, same rationale as +// RequestType/AssetItemStatus/LicenseType above. Determines downstream +// rules for entities that will attach to a category later (not built in +// this task): AssetModel.categoryId must point to a `high_value` category, +// ConsumableItem.categoryId must point to a `low_value` category. +enum AssetCategoryValueGroup { + high_value + low_value +} + +// Asset classification catalog — see docs/asset-license-management.md's +// "## Phân loại tài sản" section and the `AssetCategory` row in the "Data +// model (sơ bộ)" table. Standalone entity, no FKs (same starting shape as +// Vendor before it grew relations) — `AssetModel` and +// `AssetCategoryAttributeDef` will attach to this via `categoryId` in +// later tasks (not this one). IT admin defines the concrete categories +// (e.g. "Laptop", "Cáp HDMI") freely; only `valueGroup` is a fixed 2-value +// set. +model AssetCategory { + id String @id @default(uuid()) @db.Uuid + name String + valueGroup AssetCategoryValueGroup @map("value_group") + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) + + @@map("asset_categories") +} + // 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.