ai-chatbot/lib/db/migrations/0082_add_client_performance_events.sql
Your Name 68eab912d8
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
perf: optimize agent style rendering
2026-05-20 18:10:43 +08:00

35 lines
1.3 KiB
SQL

CREATE TABLE IF NOT EXISTS "ClientPerformanceEvent" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"userId" uuid REFERENCES "User"("id") ON DELETE SET NULL,
"chatId" uuid REFERENCES "Chat"("id") ON DELETE SET NULL,
"projectId" varchar(64),
"eventType" varchar(64) NOT NULL,
"section" varchar(32) DEFAULT 'unknown' NOT NULL,
"action" varchar(64),
"path" varchar(256),
"durationMs" integer DEFAULT 0 NOT NULL,
"blockingDurationMs" integer DEFAULT 0 NOT NULL,
"domNodeCount" integer DEFAULT 0 NOT NULL,
"visibleImageCount" integer DEFAULT 0 NOT NULL,
"loadedImageCount" integer DEFAULT 0 NOT NULL,
"viewport" jsonb,
"browser" varchar(128),
"metadata" jsonb,
"requesterIp" varchar(64),
"requesterUserAgent" text,
"occurredAt" timestamp,
"createdAt" timestamp DEFAULT now() NOT NULL
);
CREATE INDEX IF NOT EXISTS "ClientPerformanceEvent_createdAt_idx"
ON "ClientPerformanceEvent" ("createdAt" DESC);
CREATE INDEX IF NOT EXISTS "ClientPerformanceEvent_section_createdAt_idx"
ON "ClientPerformanceEvent" ("section", "createdAt" DESC);
CREATE INDEX IF NOT EXISTS "ClientPerformanceEvent_userId_createdAt_idx"
ON "ClientPerformanceEvent" ("userId", "createdAt" DESC);
CREATE INDEX IF NOT EXISTS "ClientPerformanceEvent_projectId_createdAt_idx"
ON "ClientPerformanceEvent" ("projectId", "createdAt" DESC);