feat(db): add good_origin_goods junction table for merged origin goods

This commit is contained in:
yeuimu
2026-08-27 18:09:00 +08:00
parent 043d2463a6
commit 848eed0b6f
3 changed files with 36 additions and 2 deletions
+17
View File
@@ -36,6 +36,7 @@ model OriginGood {
goods Good[]
detail OriginGoodDetail?
variants OriginGoodVariant[]
mergedIntoGoods GoodOriginGood[]
@@index([sdsCategoryId])
@@index([source])
@@ -215,6 +216,7 @@ model Good {
tag Tag? @relation(fields: [tagId], references: [id], onDelete: SetNull, onUpdate: NoAction)
position Position? @relation(fields: [positionId], references: [id], onDelete: SetNull, onUpdate: NoAction)
goodTags GoodTag[]
mergedOriginGoods GoodOriginGood[]
@@index([originGoodId])
@@index([countryId])
@@ -241,6 +243,21 @@ model GoodTag {
@@map("good_tags")
}
// ---------- Good-OriginGood Junction (merged secondary sources, M:N) ----------
// Primary source stays on goods.origin_good_id and is NOT stored here.
model GoodOriginGood {
goodId BigInt @map("good_id")
originGoodId BigInt @map("origin_good_id")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
good Good @relation(fields: [goodId], references: [id], onDelete: Cascade, onUpdate: NoAction)
originGood OriginGood @relation(fields: [originGoodId], references: [id], onDelete: Cascade, onUpdate: NoAction)
@@id([goodId, originGoodId])
@@index([originGoodId])
@@map("good_origin_goods")
}
// ---------- Users (admin authentication) ----------
enum Role {
ADMIN