CREATE TYPE "public"."message_role" AS ENUM('system', 'user', 'assistant', 'data');--> statement-breakpoint
CREATE TABLE "chats" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"chat_id" varchar NOT NULL,
"user_id" varchar NOT NULL,
"organization_id" integer NOT NULL,
"title" text,
"ip" text,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp,
CONSTRAINT "chat_user_id" UNIQUE("user_id","chat_id")
);
--> statement-breakpoint
CREATE TABLE "messages" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"chat_id" uuid NOT NULL,
"role" "message_role" NOT NULL,
"content" text NOT NULL,
"reasoning" text,
"data" jsonb,
"annotations" jsonb,
"tool_invocations" jsonb,
"experimental_attachments" jsonb,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp
);
--> statement-breakpoint
ALTER TABLE "chats" ADD CONSTRAINT "chats_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "messages" ADD CONSTRAINT "messages_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;