Skip to content

Commit f0676eb

Browse files
committed
Re add db migrations
1 parent 0cb92c1 commit f0676eb

File tree

3 files changed

+15249
-1
lines changed

3 files changed

+15249
-1
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
CREATE TYPE "public"."copilot_async_tool_status" AS ENUM('pending', 'running', 'completed', 'failed', 'cancelled', 'resume_enqueued', 'resumed');--> statement-breakpoint
2+
CREATE TYPE "public"."copilot_run_status" AS ENUM('active', 'paused_waiting_for_tool', 'resuming', 'complete', 'error', 'cancelled');--> statement-breakpoint
3+
CREATE TABLE "copilot_async_tool_calls" (
4+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
5+
"run_id" uuid NOT NULL,
6+
"checkpoint_id" uuid,
7+
"tool_call_id" text NOT NULL,
8+
"tool_name" text NOT NULL,
9+
"args" jsonb DEFAULT '{}' NOT NULL,
10+
"status" "copilot_async_tool_status" DEFAULT 'pending' NOT NULL,
11+
"result" jsonb,
12+
"error" text,
13+
"claimed_at" timestamp,
14+
"claimed_by" text,
15+
"completed_at" timestamp,
16+
"created_at" timestamp DEFAULT now() NOT NULL,
17+
"updated_at" timestamp DEFAULT now() NOT NULL
18+
);
19+
--> statement-breakpoint
20+
CREATE TABLE "copilot_run_checkpoints" (
21+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
22+
"run_id" uuid NOT NULL,
23+
"pending_tool_call_id" text NOT NULL,
24+
"conversation_snapshot" jsonb DEFAULT '{}' NOT NULL,
25+
"agent_state" jsonb DEFAULT '{}' NOT NULL,
26+
"provider_request" jsonb DEFAULT '{}' NOT NULL,
27+
"created_at" timestamp DEFAULT now() NOT NULL,
28+
"updated_at" timestamp DEFAULT now() NOT NULL
29+
);
30+
--> statement-breakpoint
31+
CREATE TABLE "copilot_runs" (
32+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
33+
"execution_id" text NOT NULL,
34+
"parent_run_id" uuid,
35+
"chat_id" uuid NOT NULL,
36+
"user_id" text NOT NULL,
37+
"workflow_id" text,
38+
"workspace_id" text,
39+
"stream_id" text NOT NULL,
40+
"agent" text,
41+
"model" text,
42+
"provider" text,
43+
"status" "copilot_run_status" DEFAULT 'active' NOT NULL,
44+
"request_context" jsonb DEFAULT '{}' NOT NULL,
45+
"started_at" timestamp DEFAULT now() NOT NULL,
46+
"completed_at" timestamp,
47+
"created_at" timestamp DEFAULT now() NOT NULL,
48+
"updated_at" timestamp DEFAULT now() NOT NULL,
49+
"error" text
50+
);
51+
--> statement-breakpoint
52+
CREATE TABLE "copilot_workflow_read_hashes" (
53+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
54+
"chat_id" uuid NOT NULL,
55+
"workflow_id" text NOT NULL,
56+
"hash" text NOT NULL,
57+
"created_at" timestamp DEFAULT now() NOT NULL,
58+
"updated_at" timestamp DEFAULT now() NOT NULL
59+
);
60+
--> statement-breakpoint
61+
ALTER TABLE "copilot_async_tool_calls" ADD CONSTRAINT "copilot_async_tool_calls_run_id_copilot_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."copilot_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
62+
ALTER TABLE "copilot_async_tool_calls" ADD CONSTRAINT "copilot_async_tool_calls_checkpoint_id_copilot_run_checkpoints_id_fk" FOREIGN KEY ("checkpoint_id") REFERENCES "public"."copilot_run_checkpoints"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
63+
ALTER TABLE "copilot_run_checkpoints" ADD CONSTRAINT "copilot_run_checkpoints_run_id_copilot_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."copilot_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
64+
ALTER TABLE "copilot_runs" ADD CONSTRAINT "copilot_runs_chat_id_copilot_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."copilot_chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
65+
ALTER TABLE "copilot_runs" ADD CONSTRAINT "copilot_runs_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
66+
ALTER TABLE "copilot_runs" ADD CONSTRAINT "copilot_runs_workflow_id_workflow_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "public"."workflow"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
67+
ALTER TABLE "copilot_runs" ADD CONSTRAINT "copilot_runs_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
68+
ALTER TABLE "copilot_workflow_read_hashes" ADD CONSTRAINT "copilot_workflow_read_hashes_chat_id_copilot_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."copilot_chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
69+
ALTER TABLE "copilot_workflow_read_hashes" ADD CONSTRAINT "copilot_workflow_read_hashes_workflow_id_workflow_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "public"."workflow"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
70+
CREATE INDEX "copilot_async_tool_calls_run_id_idx" ON "copilot_async_tool_calls" USING btree ("run_id");--> statement-breakpoint
71+
CREATE INDEX "copilot_async_tool_calls_checkpoint_id_idx" ON "copilot_async_tool_calls" USING btree ("checkpoint_id");--> statement-breakpoint
72+
CREATE INDEX "copilot_async_tool_calls_tool_call_id_idx" ON "copilot_async_tool_calls" USING btree ("tool_call_id");--> statement-breakpoint
73+
CREATE INDEX "copilot_async_tool_calls_status_idx" ON "copilot_async_tool_calls" USING btree ("status");--> statement-breakpoint
74+
CREATE INDEX "copilot_async_tool_calls_run_status_idx" ON "copilot_async_tool_calls" USING btree ("run_id","status");--> statement-breakpoint
75+
CREATE UNIQUE INDEX "copilot_async_tool_calls_tool_call_id_unique" ON "copilot_async_tool_calls" USING btree ("tool_call_id");--> statement-breakpoint
76+
CREATE INDEX "copilot_run_checkpoints_run_id_idx" ON "copilot_run_checkpoints" USING btree ("run_id");--> statement-breakpoint
77+
CREATE INDEX "copilot_run_checkpoints_pending_tool_call_id_idx" ON "copilot_run_checkpoints" USING btree ("pending_tool_call_id");--> statement-breakpoint
78+
CREATE UNIQUE INDEX "copilot_run_checkpoints_run_pending_tool_unique" ON "copilot_run_checkpoints" USING btree ("run_id","pending_tool_call_id");--> statement-breakpoint
79+
CREATE INDEX "copilot_runs_execution_id_idx" ON "copilot_runs" USING btree ("execution_id");--> statement-breakpoint
80+
CREATE INDEX "copilot_runs_parent_run_id_idx" ON "copilot_runs" USING btree ("parent_run_id");--> statement-breakpoint
81+
CREATE INDEX "copilot_runs_chat_id_idx" ON "copilot_runs" USING btree ("chat_id");--> statement-breakpoint
82+
CREATE INDEX "copilot_runs_user_id_idx" ON "copilot_runs" USING btree ("user_id");--> statement-breakpoint
83+
CREATE INDEX "copilot_runs_workflow_id_idx" ON "copilot_runs" USING btree ("workflow_id");--> statement-breakpoint
84+
CREATE INDEX "copilot_runs_workspace_id_idx" ON "copilot_runs" USING btree ("workspace_id");--> statement-breakpoint
85+
CREATE INDEX "copilot_runs_status_idx" ON "copilot_runs" USING btree ("status");--> statement-breakpoint
86+
CREATE INDEX "copilot_runs_chat_execution_idx" ON "copilot_runs" USING btree ("chat_id","execution_id");--> statement-breakpoint
87+
CREATE INDEX "copilot_runs_execution_started_at_idx" ON "copilot_runs" USING btree ("execution_id","started_at");--> statement-breakpoint
88+
CREATE UNIQUE INDEX "copilot_runs_stream_id_unique" ON "copilot_runs" USING btree ("stream_id");--> statement-breakpoint
89+
CREATE INDEX "copilot_workflow_read_hashes_chat_id_idx" ON "copilot_workflow_read_hashes" USING btree ("chat_id");--> statement-breakpoint
90+
CREATE INDEX "copilot_workflow_read_hashes_workflow_id_idx" ON "copilot_workflow_read_hashes" USING btree ("workflow_id");--> statement-breakpoint
91+
CREATE UNIQUE INDEX "copilot_workflow_read_hashes_chat_workflow_unique" ON "copilot_workflow_read_hashes" USING btree ("chat_id","workflow_id");--> statement-breakpoint
92+
CREATE UNIQUE INDEX "kb_workspace_name_active_unique" ON "knowledge_base" USING btree ("workspace_id","name") WHERE "knowledge_base"."deleted_at" IS NULL;--> statement-breakpoint
93+
CREATE UNIQUE INDEX "workspace_files_workspace_name_active_unique" ON "workspace_files" USING btree ("workspace_id","original_name") WHERE "workspace_files"."deleted_at" IS NULL AND "workspace_files"."context" = 'workspace' AND "workspace_files"."workspace_id" IS NOT NULL;

0 commit comments

Comments
 (0)