refactor: 移除旧服务模型统一使用业务提供项

This commit is contained in:
que01 committed 2026-09-21 17:11:45 +08:00
1 parent ca85a583ce
commit 844a3bd715
13 files changed
+92 -146

No files matched your search

@@ -0,0 +1,9 @@
-- Service data was backfilled into Offering before this migration.
ALTER TABLE "BookingItem" DROP CONSTRAINT IF EXISTS "BookingItem_serviceId_fkey";
ALTER TABLE "Booking" DROP CONSTRAINT IF EXISTS "Booking_serviceId_fkey";
ALTER TABLE "Offering" DROP CONSTRAINT IF EXISTS "Service_offeringId_fkey";
ALTER TABLE "BookingItem" DROP COLUMN IF EXISTS "serviceId";
ALTER TABLE "Booking" DROP COLUMN IF EXISTS "serviceId";
DROP INDEX IF EXISTS "Service_brandId_isEnabled_sortOrder_idx";
DROP INDEX IF EXISTS "Service_brandId_name_key";
DROP TABLE IF EXISTS "Service";
-30
View File
@@ -48,7 +48,6 @@ model BrandProfile {
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
services Service[]
bookings Booking[]
customerUsers CustomerUser[]
tags Tag[]
@@ -61,30 +60,6 @@ model BrandProfile {
inquirySubmissions InquirySubmission[]
}
model Service {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id])
name String
description String
categoryKey String @default("standard")
config Json?
coverUrl String?
priceText String?
priceAmount Int?
bookingEnabled Boolean @default(true)
isEnabled Boolean @default(true)
sortOrder Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
bookings Booking[]
bookingItems BookingItem[]
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
@@unique([brandId, name])
@@index([brandId, isEnabled, sortOrder])
}
model BrandTemplateInstallation {
id String @id @default(uuid())
brandId String
@@ -151,7 +126,6 @@ model Offering {
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
services Service[]
inquiryForms InquiryForm[]
bookings Booking[]
bookingItems BookingItem[]
@@ -235,8 +209,6 @@ model Booking {
wechatId String?
contactPreference ContactPreference
fulfillmentType FulfillmentType?
serviceId String?
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
requestedDate DateTime?
@@ -277,8 +249,6 @@ model BookingItem {
id String @id @default(uuid())
bookingId String
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
serviceId String?
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
serviceNameSnapshot String
+6 -7
View File
@@ -19,7 +19,7 @@ async function main(): Promise<void> {
},
});
const services = [
const offerings = [
{
brandId: brand.id,
name: "红烧肉双拼套餐",
@@ -41,16 +41,15 @@ async function main(): Promise<void> {
name: "家庭聚餐私厨",
description: "根据人数、地点和口味人工沟通报价",
priceText: "面议",
bookingEnabled: true,
sortOrder: 3,
},
];
for (const service of services) {
const existing = await prisma.service.findFirst({
where: { brandId: brand.id, name: service.name },
for (const offering of offerings) {
const existing = await prisma.offering.findFirst({
where: { brandId: brand.id, name: offering.name },
});
if (existing) await prisma.service.update({ where: { id: existing.id }, data: service });
else await prisma.service.create({ data: service });
if (existing) await prisma.offering.update({ where: { id: existing.id }, data: offering });
else await prisma.offering.create({ data: { ...offering, kind: "service" } });
}
for (const name of ["普通套餐", "私厨", "配送", "自取", "熟客", "重点跟进"]) {