ai-chatbot/lib/db/migrations/0074_add_enhance_pro_tasks.sql
Your Name b8a59fe2a4
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
fix: harden enhance pro task charging
2026-04-27 18:38:42 +08:00

28 lines
1007 B
SQL

CREATE TABLE IF NOT EXISTS "EnhanceProTask" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"userId" uuid NOT NULL REFERENCES "User"("id") ON DELETE cascade,
"chatId" uuid REFERENCES "Chat"("id") ON DELETE cascade,
"messageId" uuid,
"clientRequestId" varchar(64),
"providerTaskId" varchar(128) NOT NULL,
"taskKeyId" varchar(64),
"status" varchar(16) NOT NULL DEFAULT 'pending',
"prompt" text,
"sourceImageUrl" text NOT NULL,
"request" jsonb NOT NULL,
"result" jsonb,
"error" text,
"pointsCost" integer NOT NULL DEFAULT 0,
"pointsCharged" boolean NOT NULL DEFAULT false,
"chargedAt" timestamp,
"completedAt" timestamp,
"createdAt" timestamp NOT NULL DEFAULT now(),
"updatedAt" timestamp NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX IF NOT EXISTS "EnhanceProTask_providerTaskId_idx"
ON "EnhanceProTask" ("providerTaskId");
CREATE UNIQUE INDEX IF NOT EXISTS "EnhanceProTask_userId_clientRequestId_idx"
ON "EnhanceProTask" ("userId", "clientRequestId");