feat: add AssetItem.purchaseOrderId (nullable FK)
This commit is contained in:
+25
-16
@@ -78,11 +78,16 @@ enum AssetItemStatus {
|
||||
|
||||
// Hardware inventory — see docs/asset-license-management.md's "Data model
|
||||
// (sơ bộ)" table (serial number, model, ngày mua, bảo hành, trạng thái).
|
||||
// No Vendor/Assignment relation yet — those entities don't exist yet
|
||||
// (see "Việc còn dở" in CLAUDE.md), so this is a standalone entity for now,
|
||||
// same starting shape as Employee before Request grew an FK to it.
|
||||
// warrantyEndDate is nullable: not every asset has known warranty terms at
|
||||
// intake time (smallest sensible assumption — doesn't block creation).
|
||||
// No Assignment relation yet — that entity doesn't exist yet (see "Việc còn
|
||||
// dở" in CLAUDE.md). warrantyEndDate is nullable: not every asset has known
|
||||
// warranty terms at intake time (smallest sensible assumption — doesn't
|
||||
// block creation). purchaseOrderId is a nullable FK to PurchaseOrder — see
|
||||
// docs/asset-license-management.md's "## PurchaseOrder (gộp Receipt)"
|
||||
// Traceability bullet: supply-side traceability ("which PO did this asset
|
||||
// item come in through"). Nullable because not every AssetItem goes through
|
||||
// a formal PO (e.g. historical stock predating the system). Set at
|
||||
// intake/creation time only — no update endpoint for this field yet, same
|
||||
// precedent as License.vendorId being set-at-creation with no PATCH.
|
||||
model AssetItem {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
serialNumber String @unique @map("serial_number")
|
||||
@@ -90,6 +95,8 @@ model AssetItem {
|
||||
purchaseDate DateTime @map("purchase_date") @db.Date
|
||||
warrantyEndDate DateTime? @map("warranty_end_date") @db.Date
|
||||
status AssetItemStatus @default(in_stock)
|
||||
purchaseOrderId String? @map("purchase_order_id") @db.Uuid
|
||||
purchaseOrder PurchaseOrder? @relation(fields: [purchaseOrderId], references: [id])
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
|
||||
@@map("asset_items")
|
||||
@@ -167,18 +174,20 @@ model Vendor {
|
||||
// received) — enforced at the Zod layer (src/lib/purchase-orders.ts), not a
|
||||
// DB constraint, same approach as other cross-field invariants in this
|
||||
// codebase (e.g. Assignment's assetItemId/licenseId XOR, not built yet).
|
||||
// purchaseOrderId back-references on AssetItem/License/Request (traceability,
|
||||
// same doc section) are NOT part of this change — out of scope for this task.
|
||||
// `assetItems` is the back-relation from the AssetItem.purchaseOrderId
|
||||
// retrofit (supply-side traceability, same doc section). License/Request
|
||||
// back-references are NOT part of this change — out of scope for this task.
|
||||
model PurchaseOrder {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
vendorId String @map("vendor_id") @db.Uuid
|
||||
vendor Vendor @relation(fields: [vendorId], references: [id])
|
||||
orderDate DateTime @map("order_date") @db.Timestamptz(6)
|
||||
expectedDate DateTime @map("expected_date") @db.Timestamptz(6)
|
||||
receivedAt DateTime? @map("received_at") @db.Timestamptz(6)
|
||||
receivedById String? @map("received_by") @db.Uuid
|
||||
receivedBy Employee? @relation(fields: [receivedById], references: [id])
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
vendorId String @map("vendor_id") @db.Uuid
|
||||
vendor Vendor @relation(fields: [vendorId], references: [id])
|
||||
orderDate DateTime @map("order_date") @db.Timestamptz(6)
|
||||
expectedDate DateTime @map("expected_date") @db.Timestamptz(6)
|
||||
receivedAt DateTime? @map("received_at") @db.Timestamptz(6)
|
||||
receivedById String? @map("received_by") @db.Uuid
|
||||
receivedBy Employee? @relation(fields: [receivedById], references: [id])
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
assetItems AssetItem[]
|
||||
|
||||
@@map("purchase_orders")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user