CREATE TABLE "kb_draft_retrievals" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tenant_id" uuid NOT NULL,
	"kb_entry_id" uuid NOT NULL,
	"ticket_id" uuid NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "kb_draft_retrievals" ADD CONSTRAINT "kb_draft_retrievals_tenant_id_tenants_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "kb_draft_retrievals" ADD CONSTRAINT "kb_draft_retrievals_kb_entry_id_knowledge_entries_id_fk" FOREIGN KEY ("kb_entry_id") REFERENCES "public"."knowledge_entries"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "kb_draft_retrievals" ADD CONSTRAINT "kb_draft_retrievals_ticket_id_tickets_id_fk" FOREIGN KEY ("ticket_id") REFERENCES "public"."tickets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "kb_draft_retrievals_tenant_entry_idx" ON "kb_draft_retrievals" USING btree ("tenant_id","kb_entry_id");--> statement-breakpoint
CREATE INDEX "kb_draft_retrievals_ticket_id_idx" ON "kb_draft_retrievals" USING btree ("ticket_id");