Product & BOM / Technical / database-schema.html
🧬 Thực Thể Cơ Sở Dữ Liệu
Sơ đồ ERD thực tế ánh xạ từ các Aggregates sang cơ sở dữ liệu quan hệ (PostgreSQL / MySQL) thông qua ORM Prisma.
💎 Khai Báo Prisma Models
Mã nguồn khai báo schema các model cấu thành thực thể tĩnh R&D và định mức BOM sản xuất.
// Prisma Schema của phân hệ Product & BOM
model Product {
id String @id @default(uuid())
code String @unique
name String
status ProductStatus @default(DRAFT)
structures ProductStructure[]
variants Variant[]
createdAt DateTime @default(now())
}
model ProductStructure {
id String @id @default(uuid())
productId String
product Product @relation(fields: [productId], references: [id])
componentId String
component Component @relation(fields: [componentId], references: [id])
quantity Float @default(1.0)
}
model Component {
id String @id @default(uuid())
code String @unique
name String
frameTypeId String? // Dành cho quy đổi nguyên liệu gỗ/sắt
structures ProductStructure[]
}
model BOM {
id String @id @default(uuid())
variantId String
status BomStatus @default(DRAFT)
bomComponents BomComponent[]
routingSteps BomWorkStep[]
}
🐘 Lệnh Tạo Bảng SQL DDL (PostgreSQL)
Lệnh khởi tạo các bảng cơ sở dữ liệu được biên dịch từ Prisma Schema.
CREATE TABLE "Product" (
"id" VARCHAR(36) NOT NULL PRIMARY KEY,
"code" VARCHAR(100) NOT NULL UNIQUE,
"name" VARCHAR(255) NOT NULL,
"status" VARCHAR(50) DEFAULT 'DRAFT'
);
CREATE TABLE "Component" (
"id" VARCHAR(36) NOT NULL PRIMARY KEY,
"code" VARCHAR(100) NOT NULL UNIQUE,
"frameTypeId" VARCHAR(50)
);