feat: 建立预约工作流状态历史
This commit is contained in:
1 parent
0381c0a902
commit
e9d3f77639
3 files changed
+93
-4
No files matched your search
@@ -0,0 +1,28 @@
|
||||
ALTER TABLE "Booking" ADD COLUMN "workflowKey" TEXT NOT NULL DEFAULT 'booking.basic';
|
||||
ALTER TABLE "Booking" ADD COLUMN "workflowVersion" TEXT NOT NULL DEFAULT '1.0.0';
|
||||
ALTER TABLE "Booking" ADD COLUMN "currentState" TEXT NOT NULL DEFAULT 'received';
|
||||
|
||||
UPDATE "Booking" SET "currentState" = "status"::text;
|
||||
|
||||
CREATE TABLE "BookingStateTransition" (
|
||||
"id" TEXT NOT NULL,
|
||||
"bookingId" TEXT NOT NULL,
|
||||
"workflowKey" TEXT NOT NULL,
|
||||
"workflowVersion" TEXT NOT NULL,
|
||||
"fromState" TEXT,
|
||||
"toState" TEXT NOT NULL,
|
||||
"actorRole" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "BookingStateTransition_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
ALTER TABLE "BookingStateTransition" ADD CONSTRAINT "BookingStateTransition_bookingId_fkey"
|
||||
FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
CREATE INDEX "BookingStateTransition_bookingId_createdAt_idx"
|
||||
ON "BookingStateTransition"("bookingId", "createdAt");
|
||||
|
||||
INSERT INTO "BookingStateTransition" (
|
||||
"id", "bookingId", "workflowKey", "workflowVersion", "fromState", "toState", "actorRole", "createdAt"
|
||||
)
|
||||
SELECT gen_random_uuid()::text, "id", "workflowKey", "workflowVersion", NULL, "currentState", 'migration', "createdAt"
|
||||
FROM "Booking";
|
||||
@@ -247,15 +247,32 @@ model Booking {
|
||||
note String?
|
||||
adminNote String?
|
||||
status BookingStatus @default(received)
|
||||
workflowKey String @default("booking.basic")
|
||||
workflowVersion String @default("1.0.0")
|
||||
currentState String @default("received")
|
||||
isRead Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
items BookingItem[]
|
||||
tags BookingTag[]
|
||||
stateTransitions BookingStateTransition[]
|
||||
@@index([brandId, status, createdAt])
|
||||
@@index([customerUserId, createdAt])
|
||||
}
|
||||
|
||||
model BookingStateTransition {
|
||||
id String @id @default(uuid())
|
||||
bookingId String
|
||||
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
|
||||
workflowKey String
|
||||
workflowVersion String
|
||||
fromState String?
|
||||
toState String
|
||||
actorRole String
|
||||
createdAt DateTime @default(now())
|
||||
@@index([bookingId, createdAt])
|
||||
}
|
||||
|
||||
model BookingItem {
|
||||
id String @id @default(uuid())
|
||||
bookingId String
|
||||
|
||||
Reference in new issue
Block a user