feat(api): good family_id column with backfill

This commit is contained in:
yeuimu
2026-08-28 13:34:42 +08:00
parent ba3c6d2d4f
commit b4b9fbbe60
3 changed files with 67 additions and 0 deletions
@@ -0,0 +1,14 @@
-- AlterTable
ALTER TABLE "goods" ADD COLUMN "family_id" BIGINT;
-- CreateIndex
CREATE INDEX "goods_family_id_idx" ON "goods"("family_id");
-- AddForeignKey
ALTER TABLE "goods" ADD CONSTRAINT "goods_family_id_fkey" FOREIGN KEY ("family_id") REFERENCES "product_families"("family_id") ON DELETE SET NULL ON UPDATE NO ACTION;
-- Backfill: Good 的族 = 其主链接所属族(派生数据,后续由服务层联动维护)
UPDATE "goods" SET "family_id" = (
SELECT "o"."family_id" FROM "origin_goods" "o"
WHERE "o"."origin_good_id" = "goods"."origin_good_id"
);
+4
View File
@@ -212,6 +212,7 @@ model Position {
model Good {
id BigInt @id @default(autoincrement()) @map("good_id")
originGoodId BigInt @map("origin_good_id")
familyId BigInt? @map("family_id")
countryId BigInt @map("country_id")
categoryId BigInt @map("category_id")
tagId BigInt? @map("tag_id")
@@ -223,6 +224,7 @@ model Good {
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
originGood OriginGood @relation(fields: [originGoodId], references: [id], onDelete: Restrict, onUpdate: NoAction)
family ProductFamily? @relation(fields: [familyId], references: [id], onDelete: SetNull, onUpdate: NoAction)
country Country @relation(fields: [countryId], references: [id], onDelete: Restrict, onUpdate: NoAction)
category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict, onUpdate: NoAction)
tag Tag? @relation(fields: [tagId], references: [id], onDelete: SetNull, onUpdate: NoAction)
@@ -231,6 +233,7 @@ model Good {
mergedOriginGoods GoodOriginGood[]
@@index([originGoodId])
@@index([familyId])
@@index([countryId])
@@index([categoryId])
@@index([tagId])
@@ -292,6 +295,7 @@ model ProductFamily {
originGoods OriginGood[]
priceOverrides FamilyPriceOverride[]
goods Good[]
country Country? @relation(fields: [countryId], references: [id], onDelete: SetNull, onUpdate: NoAction)
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull, onUpdate: NoAction)