feat: 增加品牌工作空间与业务提供项模型

This commit is contained in:
que01 committed 2026-09-19 22:47:10 +08:00
1 parent 4f26dce212
commit 8795086ece
2 files changed
+266

No files matched your search

@@ -0,0 +1,157 @@
-- AlterTable
ALTER TABLE "Service" ADD COLUMN "offeringId" TEXT;
-- CreateTable
CREATE TABLE "BrandTemplateInstallation" (
"id" TEXT NOT NULL,
"brandId" TEXT NOT NULL,
"templateKey" TEXT NOT NULL,
"templateVersion" TEXT NOT NULL DEFAULT '1.0.0',
"installedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "BrandTemplateInstallation_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BrandModule" (
"id" TEXT NOT NULL,
"brandId" TEXT NOT NULL,
"type" TEXT NOT NULL,
"title" TEXT NOT NULL,
"isEnabled" BOOLEAN NOT NULL DEFAULT true,
"sortOrder" INTEGER NOT NULL DEFAULT 0,
"source" TEXT NOT NULL DEFAULT 'core',
"config" JSONB,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "BrandModule_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BrandFieldDefinition" (
"id" TEXT NOT NULL,
"brandId" TEXT NOT NULL,
"scope" TEXT NOT NULL,
"key" TEXT NOT NULL,
"label" TEXT NOT NULL,
"type" TEXT NOT NULL,
"required" BOOLEAN NOT NULL DEFAULT false,
"isVisible" BOOLEAN NOT NULL DEFAULT true,
"sortOrder" INTEGER NOT NULL DEFAULT 0,
"source" TEXT NOT NULL DEFAULT 'custom',
"isOverridden" BOOLEAN NOT NULL DEFAULT false,
"options" JSONB,
"visibleWhen" JSONB,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "BrandFieldDefinition_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Offering" (
"id" TEXT NOT NULL,
"brandId" TEXT NOT NULL,
"kind" TEXT NOT NULL DEFAULT 'service',
"name" TEXT NOT NULL,
"summary" TEXT,
"description" TEXT,
"coverUrl" TEXT,
"priceText" TEXT,
"priceAmount" INTEGER,
"isEnabled" BOOLEAN NOT NULL DEFAULT true,
"sortOrder" INTEGER NOT NULL DEFAULT 0,
"config" JSONB,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Offering_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "InquiryForm" (
"id" TEXT NOT NULL,
"brandId" TEXT NOT NULL,
"offeringId" TEXT,
"name" TEXT NOT NULL,
"version" INTEGER NOT NULL DEFAULT 1,
"isEnabled" BOOLEAN NOT NULL DEFAULT true,
"fieldsSnapshot" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "InquiryForm_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "InquirySubmission" (
"id" TEXT NOT NULL,
"brandId" TEXT NOT NULL,
"inquiryFormId" TEXT NOT NULL,
"formVersion" INTEGER NOT NULL,
"fieldsSnapshot" JSONB NOT NULL,
"values" JSONB NOT NULL,
"activeFields" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "InquirySubmission_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "BrandTemplateInstallation_brandId_idx" ON "BrandTemplateInstallation"("brandId");
-- CreateIndex
CREATE UNIQUE INDEX "BrandTemplateInstallation_brandId_templateKey_key" ON "BrandTemplateInstallation"("brandId", "templateKey");
-- CreateIndex
CREATE INDEX "BrandModule_brandId_isEnabled_sortOrder_idx" ON "BrandModule"("brandId", "isEnabled", "sortOrder");
-- CreateIndex
CREATE INDEX "BrandFieldDefinition_brandId_scope_sortOrder_idx" ON "BrandFieldDefinition"("brandId", "scope", "sortOrder");
-- CreateIndex
CREATE UNIQUE INDEX "BrandFieldDefinition_brandId_scope_key_key" ON "BrandFieldDefinition"("brandId", "scope", "key");
-- CreateIndex
CREATE INDEX "Offering_brandId_isEnabled_sortOrder_idx" ON "Offering"("brandId", "isEnabled", "sortOrder");
-- CreateIndex
CREATE UNIQUE INDEX "Offering_brandId_name_key" ON "Offering"("brandId", "name");
-- CreateIndex
CREATE INDEX "InquiryForm_brandId_isEnabled_idx" ON "InquiryForm"("brandId", "isEnabled");
-- CreateIndex
CREATE INDEX "InquirySubmission_brandId_createdAt_idx" ON "InquirySubmission"("brandId", "createdAt");
-- CreateIndex
CREATE INDEX "InquirySubmission_inquiryFormId_formVersion_idx" ON "InquirySubmission"("inquiryFormId", "formVersion");
-- AddForeignKey
ALTER TABLE "Service" ADD CONSTRAINT "Service_offeringId_fkey" FOREIGN KEY ("offeringId") REFERENCES "Offering"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BrandTemplateInstallation" ADD CONSTRAINT "BrandTemplateInstallation_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BrandModule" ADD CONSTRAINT "BrandModule_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BrandFieldDefinition" ADD CONSTRAINT "BrandFieldDefinition_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Offering" ADD CONSTRAINT "Offering_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "InquiryForm" ADD CONSTRAINT "InquiryForm_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "InquiryForm" ADD CONSTRAINT "InquiryForm_offeringId_fkey" FOREIGN KEY ("offeringId") REFERENCES "Offering"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "InquirySubmission" ADD CONSTRAINT "InquirySubmission_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "InquirySubmission" ADD CONSTRAINT "InquirySubmission_inquiryFormId_fkey" FOREIGN KEY ("inquiryFormId") REFERENCES "InquiryForm"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+109
View File
@@ -52,6 +52,12 @@ model BrandProfile {
customerUsers CustomerUser[]
tags Tag[]
trustContents TrustContent[]
templateInstallations BrandTemplateInstallation[]
modules BrandModule[]
fieldDefinitions BrandFieldDefinition[]
offerings Offering[]
inquiryForms InquiryForm[]
inquirySubmissions InquirySubmission[]
}
model Service {
@@ -72,10 +78,113 @@ model Service {
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
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
templateKey String
templateVersion String @default("1.0.0")
installedAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([brandId, templateKey])
@@index([brandId])
}
model BrandModule {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
type String
title String
isEnabled Boolean @default(true)
sortOrder Int @default(0)
source String @default("core")
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([brandId, isEnabled, sortOrder])
}
model BrandFieldDefinition {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
scope String
key String
label String
type String
required Boolean @default(false)
isVisible Boolean @default(true)
sortOrder Int @default(0)
source String @default("custom")
isOverridden Boolean @default(false)
options Json?
visibleWhen Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([brandId, scope, key])
@@index([brandId, scope, sortOrder])
}
model Offering {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
kind String @default("service")
name String
summary String?
description String?
coverUrl String?
priceText String?
priceAmount Int?
isEnabled Boolean @default(true)
sortOrder Int @default(0)
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
services Service[]
inquiryForms InquiryForm[]
@@unique([brandId, name])
@@index([brandId, isEnabled, sortOrder])
}
model InquiryForm {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
name String
version Int @default(1)
isEnabled Boolean @default(true)
fieldsSnapshot Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
submissions InquirySubmission[]
@@index([brandId, isEnabled])
}
model InquirySubmission {
id String @id @default(uuid())
brandId String
inquiryFormId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
inquiryForm InquiryForm @relation(fields: [inquiryFormId], references: [id], onDelete: Restrict)
formVersion Int
fieldsSnapshot Json
values Json
activeFields Json
createdAt DateTime @default(now())
@@index([brandId, createdAt])
@@index([inquiryFormId, formVersion])
}
model TrustContent {
id String @id @default(uuid())
brandId String