Skip to content

Commit 49051f5

Browse files
committed
fix(dashboard-agent-db): stop rewriting the published migration history
0000 and 0001 already shipped, so the agent's new tables land in a third migration instead of a squashed first one.
1 parent dfcee8b commit 49051f5

7 files changed

Lines changed: 1889 additions & 1223 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE SCHEMA IF NOT EXISTS "trigger_dashboard_agent";
2+
--> statement-breakpoint
3+
CREATE TABLE IF NOT EXISTS "trigger_dashboard_agent"."chat_sessions" (
4+
"chat_id" text PRIMARY KEY NOT NULL,
5+
"public_access_token" text NOT NULL,
6+
"last_event_id" text,
7+
"run_id" text,
8+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
9+
);
10+
--> statement-breakpoint
11+
CREATE TABLE IF NOT EXISTS "trigger_dashboard_agent"."chats" (
12+
"id" text PRIMARY KEY NOT NULL,
13+
"organization_id" text NOT NULL,
14+
"user_id" text NOT NULL,
15+
"title" text DEFAULT 'New chat' NOT NULL,
16+
"messages" jsonb DEFAULT '[]'::jsonb NOT NULL,
17+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
18+
"pinned_at" timestamp with time zone,
19+
"deleted_at" timestamp with time zone,
20+
"last_message_at" timestamp with time zone,
21+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
22+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
23+
);
24+
--> statement-breakpoint
25+
CREATE INDEX IF NOT EXISTS "chats_org_user_last_msg_idx" ON "trigger_dashboard_agent"."chats" USING btree ("organization_id","user_id","last_message_at" DESC NULLS LAST) WHERE "trigger_dashboard_agent"."chats"."deleted_at" is null;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CREATE TABLE IF NOT EXISTS "trigger_dashboard_agent"."chat_turn_evals" (
2+
"chat_id" text NOT NULL,
3+
"turn" integer NOT NULL,
4+
"organization_id" text NOT NULL,
5+
"user_id" text NOT NULL,
6+
"agent_run_id" text,
7+
"eval_run_id" text,
8+
"project_ref" text,
9+
"environment" text,
10+
"current_page" text,
11+
"model" text,
12+
"prompt_slug" text,
13+
"prompt_version" integer,
14+
"tools_used" jsonb DEFAULT '[]'::jsonb NOT NULL,
15+
"tool_error" boolean DEFAULT false NOT NULL,
16+
"judge_model" text,
17+
"score_grounded" smallint,
18+
"score_answered" smallint,
19+
"score_concise" smallint,
20+
"passed" boolean,
21+
"intent_category" text,
22+
"outcome" text,
23+
"sentiment" text,
24+
"capability_gap" boolean DEFAULT false NOT NULL,
25+
"docs_gap" boolean DEFAULT false NOT NULL,
26+
"support_opportunity" boolean DEFAULT false NOT NULL,
27+
"feature_request" boolean DEFAULT false NOT NULL,
28+
"topics" jsonb DEFAULT '[]'::jsonb NOT NULL,
29+
"signals" jsonb DEFAULT '[]'::jsonb NOT NULL,
30+
"summary" text,
31+
"user_text" text,
32+
"judge" jsonb,
33+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
34+
CONSTRAINT "chat_turn_evals_chat_id_turn_pk" PRIMARY KEY("chat_id","turn")
35+
);
36+
--> statement-breakpoint
37+
CREATE INDEX IF NOT EXISTS "chat_turn_evals_org_created_idx" ON "trigger_dashboard_agent"."chat_turn_evals" USING btree ("organization_id","created_at" DESC NULLS LAST);--> statement-breakpoint
38+
CREATE INDEX IF NOT EXISTS "chat_turn_evals_org_opps_idx" ON "trigger_dashboard_agent"."chat_turn_evals" USING btree ("organization_id","created_at" DESC NULLS LAST) WHERE "trigger_dashboard_agent"."chat_turn_evals"."capability_gap" or "trigger_dashboard_agent"."chat_turn_evals"."docs_gap" or "trigger_dashboard_agent"."chat_turn_evals"."support_opportunity" or "trigger_dashboard_agent"."chat_turn_evals"."feature_request";

internal-packages/dashboard-agent-db/drizzle/0000_loose_franklin_storm.sql renamed to internal-packages/dashboard-agent-db/drizzle/0002_watches_and_chat_messages.sql

Lines changed: 33 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
CREATE SCHEMA "trigger_dashboard_agent";
2-
--> statement-breakpoint
31
CREATE TABLE "trigger_dashboard_agent"."chat_messages" (
42
"chat_id" text NOT NULL,
53
"message_id" text NOT NULL,
@@ -11,65 +9,6 @@ CREATE TABLE "trigger_dashboard_agent"."chat_messages" (
119
CONSTRAINT "chat_messages_chat_position_key" UNIQUE("chat_id","position")
1210
);
1311
--> statement-breakpoint
14-
CREATE TABLE "trigger_dashboard_agent"."chat_sessions" (
15-
"chat_id" text PRIMARY KEY NOT NULL,
16-
"public_access_token" text NOT NULL,
17-
"last_event_id" text,
18-
"run_id" text,
19-
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
20-
);
21-
--> statement-breakpoint
22-
CREATE TABLE "trigger_dashboard_agent"."chat_turn_evals" (
23-
"chat_id" text NOT NULL,
24-
"turn" integer NOT NULL,
25-
"organization_id" text NOT NULL,
26-
"user_id" text NOT NULL,
27-
"agent_run_id" text,
28-
"eval_run_id" text,
29-
"project_ref" text,
30-
"environment" text,
31-
"current_page" text,
32-
"model" text,
33-
"prompt_slug" text,
34-
"prompt_version" integer,
35-
"tools_used" jsonb DEFAULT '[]'::jsonb NOT NULL,
36-
"tool_error" boolean DEFAULT false NOT NULL,
37-
"judge_model" text,
38-
"score_grounded" smallint,
39-
"score_answered" smallint,
40-
"score_concise" smallint,
41-
"passed" boolean,
42-
"intent_category" text,
43-
"outcome" text,
44-
"sentiment" text,
45-
"capability_gap" boolean DEFAULT false NOT NULL,
46-
"docs_gap" boolean DEFAULT false NOT NULL,
47-
"support_opportunity" boolean DEFAULT false NOT NULL,
48-
"feature_request" boolean DEFAULT false NOT NULL,
49-
"topics" jsonb DEFAULT '[]'::jsonb NOT NULL,
50-
"signals" jsonb DEFAULT '[]'::jsonb NOT NULL,
51-
"summary" text,
52-
"user_text" text,
53-
"judge" jsonb,
54-
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
55-
CONSTRAINT "chat_turn_evals_chat_id_turn_pk" PRIMARY KEY("chat_id","turn")
56-
);
57-
--> statement-breakpoint
58-
CREATE TABLE "trigger_dashboard_agent"."chats" (
59-
"id" text PRIMARY KEY NOT NULL,
60-
"organization_id" text NOT NULL,
61-
"user_id" text NOT NULL,
62-
"title" text DEFAULT 'New chat' NOT NULL,
63-
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
64-
"pinned_at" timestamp with time zone,
65-
"last_read_at" timestamp with time zone,
66-
"deleted_at" timestamp with time zone,
67-
"last_message_at" timestamp with time zone,
68-
"next_message_position" integer DEFAULT 1 NOT NULL,
69-
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
70-
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
71-
);
72-
--> statement-breakpoint
7312
CREATE TABLE "trigger_dashboard_agent"."investigations" (
7413
"id" text PRIMARY KEY NOT NULL,
7514
"chat_id" text NOT NULL,
@@ -147,20 +86,36 @@ CREATE TABLE "trigger_dashboard_agent"."watches" (
14786
"cadence_minutes" integer GENERATED ALWAYS AS (((spec ->> 'checkEveryMinutes')::int)) STORED
14887
);
14988
--> statement-breakpoint
150-
CREATE INDEX "chat_messages_chat_user_role_idx" ON "trigger_dashboard_agent"."chat_messages" USING btree ("chat_id","message_id") WHERE "trigger_dashboard_agent"."chat_messages"."role" = 'user';--> statement-breakpoint
151-
CREATE INDEX "chat_turn_evals_org_created_idx" ON "trigger_dashboard_agent"."chat_turn_evals" USING btree ("organization_id","created_at" DESC NULLS LAST);--> statement-breakpoint
152-
CREATE INDEX "chat_turn_evals_created_idx" ON "trigger_dashboard_agent"."chat_turn_evals" USING btree ("created_at");--> statement-breakpoint
153-
CREATE INDEX "chat_turn_evals_org_opps_idx" ON "trigger_dashboard_agent"."chat_turn_evals" USING btree ("organization_id","created_at" DESC NULLS LAST) WHERE "trigger_dashboard_agent"."chat_turn_evals"."capability_gap" or "trigger_dashboard_agent"."chat_turn_evals"."docs_gap" or "trigger_dashboard_agent"."chat_turn_evals"."support_opportunity" or "trigger_dashboard_agent"."chat_turn_evals"."feature_request";--> statement-breakpoint
154-
CREATE INDEX "chats_org_user_last_msg_idx" ON "trigger_dashboard_agent"."chats" USING btree ("organization_id","user_id","last_message_at" DESC NULLS LAST) WHERE "trigger_dashboard_agent"."chats"."deleted_at" is null;--> statement-breakpoint
155-
CREATE INDEX "investigations_chat_idx" ON "trigger_dashboard_agent"."investigations" USING btree ("chat_id");--> statement-breakpoint
156-
CREATE INDEX "investigations_open_updated_idx" ON "trigger_dashboard_agent"."investigations" USING btree ("updated_at") WHERE "trigger_dashboard_agent"."investigations"."state"->>'outcome' = 'in_progress';--> statement-breakpoint
157-
CREATE INDEX "watch_submissions_created_idx" ON "trigger_dashboard_agent"."watch_submissions" USING btree ("created_at");--> statement-breakpoint
158-
CREATE INDEX "watches_chat_idx" ON "trigger_dashboard_agent"."watches" USING btree ("chat_id");--> statement-breakpoint
159-
CREATE UNIQUE INDEX "watches_chat_active_identity_key" ON "trigger_dashboard_agent"."watches" USING btree ("chat_id","project_id","environment_id","identity") WHERE "trigger_dashboard_agent"."watches"."status" = 'active';--> statement-breakpoint
160-
CREATE INDEX "watches_status_expires_idx" ON "trigger_dashboard_agent"."watches" USING btree ("status","expires_at");--> statement-breakpoint
161-
CREATE INDEX "watches_pending_delivery_idx" ON "trigger_dashboard_agent"."watches" USING btree ("fired_at","last_checked_at") WHERE "trigger_dashboard_agent"."watches"."delivery_status" in ('pending', 'delivering');--> statement-breakpoint
162-
CREATE INDEX "watches_org_user_wake_idx" ON "trigger_dashboard_agent"."watches" USING btree ("organization_id","user_id",coalesce("fired_at", "last_checked_at") desc) WHERE "trigger_dashboard_agent"."watches"."delivery_status" = 'delivered' and "trigger_dashboard_agent"."watches"."status" in ('fired', 'expired');--> statement-breakpoint
163-
CREATE INDEX "watches_org_user_active_idx" ON "trigger_dashboard_agent"."watches" USING btree ("organization_id","user_id") WHERE "trigger_dashboard_agent"."watches"."status" = 'active';--> statement-breakpoint
164-
CREATE INDEX "watches_active_env_cadence_idx" ON "trigger_dashboard_agent"."watches" USING btree ("environment_id","cadence_minutes",coalesce("last_attempted_at", "last_checked_at", "created_at"),"expires_at") WHERE "trigger_dashboard_agent"."watches"."status" = 'active';--> statement-breakpoint
165-
CREATE INDEX "watches_env_cadence_delivery_idx" ON "trigger_dashboard_agent"."watches" USING btree ("environment_id","cadence_minutes","delivery_status",coalesce("fired_at", "last_checked_at")) WHERE "trigger_dashboard_agent"."watches"."status" in ('fired', 'expired') and "trigger_dashboard_agent"."watches"."delivery_status" in ('pending', 'delivering');--> statement-breakpoint
166-
CREATE INDEX "watches_retention_idx" ON "trigger_dashboard_agent"."watches" USING btree ("retention_at") WHERE "trigger_dashboard_agent"."watches"."status" in ('fired', 'expired', 'cancelled') and "trigger_dashboard_agent"."watches"."delivery_status" in ('not_required', 'delivered');
89+
ALTER TABLE "trigger_dashboard_agent"."chats" DROP COLUMN IF EXISTS "messages";
90+
--> statement-breakpoint
91+
ALTER TABLE "trigger_dashboard_agent"."chats" ADD COLUMN IF NOT EXISTS "last_read_at" timestamp with time zone;
92+
--> statement-breakpoint
93+
ALTER TABLE "trigger_dashboard_agent"."chats" ADD COLUMN IF NOT EXISTS "next_message_position" integer DEFAULT 1 NOT NULL;
94+
--> statement-breakpoint
95+
CREATE INDEX "chat_messages_chat_user_role_idx" ON "trigger_dashboard_agent"."chat_messages" USING btree ("chat_id","message_id") WHERE "trigger_dashboard_agent"."chat_messages"."role" = 'user';
96+
--> statement-breakpoint
97+
CREATE INDEX "chat_turn_evals_created_idx" ON "trigger_dashboard_agent"."chat_turn_evals" USING btree ("created_at");
98+
--> statement-breakpoint
99+
CREATE INDEX "investigations_chat_idx" ON "trigger_dashboard_agent"."investigations" USING btree ("chat_id");
100+
--> statement-breakpoint
101+
CREATE INDEX "investigations_open_updated_idx" ON "trigger_dashboard_agent"."investigations" USING btree ("updated_at") WHERE "trigger_dashboard_agent"."investigations"."state"->>'outcome' = 'in_progress';
102+
--> statement-breakpoint
103+
CREATE INDEX "watch_submissions_created_idx" ON "trigger_dashboard_agent"."watch_submissions" USING btree ("created_at");
104+
--> statement-breakpoint
105+
CREATE INDEX "watches_chat_idx" ON "trigger_dashboard_agent"."watches" USING btree ("chat_id");
106+
--> statement-breakpoint
107+
CREATE UNIQUE INDEX "watches_chat_active_identity_key" ON "trigger_dashboard_agent"."watches" USING btree ("chat_id","project_id","environment_id","identity") WHERE "trigger_dashboard_agent"."watches"."status" = 'active';
108+
--> statement-breakpoint
109+
CREATE INDEX "watches_status_expires_idx" ON "trigger_dashboard_agent"."watches" USING btree ("status","expires_at");
110+
--> statement-breakpoint
111+
CREATE INDEX "watches_pending_delivery_idx" ON "trigger_dashboard_agent"."watches" USING btree ("fired_at","last_checked_at") WHERE "trigger_dashboard_agent"."watches"."delivery_status" in ('pending', 'delivering');
112+
--> statement-breakpoint
113+
CREATE INDEX "watches_org_user_wake_idx" ON "trigger_dashboard_agent"."watches" USING btree ("organization_id","user_id",coalesce("fired_at", "last_checked_at") desc) WHERE "trigger_dashboard_agent"."watches"."delivery_status" = 'delivered' and "trigger_dashboard_agent"."watches"."status" in ('fired', 'expired');
114+
--> statement-breakpoint
115+
CREATE INDEX "watches_org_user_active_idx" ON "trigger_dashboard_agent"."watches" USING btree ("organization_id","user_id") WHERE "trigger_dashboard_agent"."watches"."status" = 'active';
116+
--> statement-breakpoint
117+
CREATE INDEX "watches_active_env_cadence_idx" ON "trigger_dashboard_agent"."watches" USING btree ("environment_id","cadence_minutes",coalesce("last_attempted_at", "last_checked_at", "created_at"),"expires_at") WHERE "trigger_dashboard_agent"."watches"."status" = 'active';
118+
--> statement-breakpoint
119+
CREATE INDEX "watches_env_cadence_delivery_idx" ON "trigger_dashboard_agent"."watches" USING btree ("environment_id","cadence_minutes","delivery_status",coalesce("fired_at", "last_checked_at")) WHERE "trigger_dashboard_agent"."watches"."status" in ('fired', 'expired') and "trigger_dashboard_agent"."watches"."delivery_status" in ('pending', 'delivering');
120+
--> statement-breakpoint
121+
CREATE INDEX "watches_retention_idx" ON "trigger_dashboard_agent"."watches" USING btree ("retention_at") WHERE "trigger_dashboard_agent"."watches"."status" in ('fired', 'expired', 'cancelled') and "trigger_dashboard_agent"."watches"."delivery_status" in ('not_required', 'delivered');

0 commit comments

Comments
 (0)