feat(api): add product_families schema and migration
This commit is contained in:
@@ -30,9 +30,15 @@ model OriginGood {
|
||||
goodPrice Decimal? @map("good_price") @db.Decimal(12, 2)
|
||||
delisted Boolean @default(false)
|
||||
source OriginGoodSource @default(SDS)
|
||||
familyId BigInt? @map("family_id")
|
||||
skuCode String? @map("sku_code")
|
||||
logisticsLabel String? @map("logistics_label")
|
||||
craftLabel String? @map("craft_label")
|
||||
warehouseLabel String? @map("warehouse_label")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
|
||||
|
||||
family ProductFamily? @relation(fields: [familyId], references: [id], onDelete: SetNull, onUpdate: NoAction)
|
||||
goods Good[]
|
||||
detail OriginGoodDetail?
|
||||
variants OriginGoodVariant[]
|
||||
@@ -40,6 +46,10 @@ model OriginGood {
|
||||
|
||||
@@index([sdsCategoryId])
|
||||
@@index([source])
|
||||
@@index([familyId])
|
||||
@@index([skuCode])
|
||||
@@index([logisticsLabel])
|
||||
@@index([craftLabel])
|
||||
@@map("origin_goods")
|
||||
}
|
||||
|
||||
@@ -118,6 +128,7 @@ model Country {
|
||||
|
||||
goods Good[]
|
||||
positions Position[]
|
||||
families ProductFamily[]
|
||||
|
||||
@@map("countries")
|
||||
}
|
||||
@@ -136,6 +147,7 @@ model Category {
|
||||
children Category[] @relation("CategoryToCategory")
|
||||
goods Good[]
|
||||
positions Position[]
|
||||
families ProductFamily[]
|
||||
|
||||
@@index([parentCategoryId])
|
||||
@@map("categories")
|
||||
@@ -258,6 +270,56 @@ model GoodOriginGood {
|
||||
@@map("good_origin_goods")
|
||||
}
|
||||
|
||||
// ---------- Product Families (SPU layer over origin goods) ----------
|
||||
// 设计文档:docs/superpowers/specs/2026-08-28-product-family-merge-design.md
|
||||
// primaryOriginGoodId 刻意不建 FK:避免与 origin_goods 相互依赖,主链接被同步删除时由服务层清理。
|
||||
model ProductFamily {
|
||||
id BigInt @id @default(autoincrement()) @map("family_id")
|
||||
familyCode String? @unique @map("family_code")
|
||||
familyName String @map("family_name")
|
||||
familyImage String? @map("family_image")
|
||||
countryId BigInt? @map("country_id")
|
||||
categoryId BigInt? @map("category_id")
|
||||
primaryOriginGoodId BigInt? @map("primary_origin_good_id")
|
||||
detail Json?
|
||||
sizeChart Json? @map("size_chart")
|
||||
packageSpecs Json? @map("package_specs")
|
||||
priceMatrix Json? @map("price_matrix")
|
||||
autoManaged Boolean @default(true) @map("auto_managed")
|
||||
stale Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
|
||||
|
||||
originGoods OriginGood[]
|
||||
priceOverrides FamilyPriceOverride[]
|
||||
country Country? @relation(fields: [countryId], references: [id], onDelete: SetNull, onUpdate: NoAction)
|
||||
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull, onUpdate: NoAction)
|
||||
|
||||
@@index([countryId])
|
||||
@@index([categoryId])
|
||||
@@map("product_families")
|
||||
}
|
||||
|
||||
// ---------- Family Price Overrides (manual per-cell price) ----------
|
||||
// 独立于推导矩阵:重算只重建推导部分,本表永不被动覆盖。
|
||||
model FamilyPriceOverride {
|
||||
id BigInt @id @default(autoincrement()) @map("family_price_override_id")
|
||||
familyId BigInt @map("family_id")
|
||||
sizeId String @map("size_id")
|
||||
colorId String @map("color_id")
|
||||
craft String
|
||||
logistics String
|
||||
price Decimal @db.Decimal(12, 2)
|
||||
note String?
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
|
||||
|
||||
family ProductFamily @relation(fields: [familyId], references: [id], onDelete: Cascade, onUpdate: NoAction)
|
||||
|
||||
@@unique([familyId, sizeId, colorId, craft, logistics])
|
||||
@@map("family_price_overrides")
|
||||
}
|
||||
|
||||
// ---------- Users (admin authentication) ----------
|
||||
enum Role {
|
||||
ADMIN
|
||||
|
||||
Reference in New Issue
Block a user