Skip to content

Commit e3fcc20

Browse files
committed
refactor(dashboard-agent-db): collapse the agent's migrations into one
The datastore's 21 migrations recorded the development history of a feature that has never shipped, including a column added in 0019 and dropped in 0020. Regenerated from the schema with drizzle-kit, so the single file is exactly what `src/schema.ts` declares. Replaying from an empty database gives the same 8 tables, 118 columns, 26 indexes and 9 constraints as the 21 files did; only the physical column order differs, because a column added by ALTER lands at the end.
1 parent 3d3c962 commit e3fcc20

44 files changed

Lines changed: 1328 additions & 18887 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
CREATE SCHEMA "trigger_dashboard_agent";
2+
--> statement-breakpoint
3+
CREATE TABLE "trigger_dashboard_agent"."chat_messages" (
4+
"chat_id" text NOT NULL,
5+
"message_id" text NOT NULL,
6+
"position" integer NOT NULL,
7+
"role" text NOT NULL,
8+
"message" jsonb NOT NULL,
9+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
10+
CONSTRAINT "chat_messages_chat_id_message_id_pk" PRIMARY KEY("chat_id","message_id"),
11+
CONSTRAINT "chat_messages_chat_position_key" UNIQUE("chat_id","position")
12+
);
13+
--> 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
73+
CREATE TABLE "trigger_dashboard_agent"."investigations" (
74+
"id" text PRIMARY KEY NOT NULL,
75+
"chat_id" text NOT NULL,
76+
"project_ref" text NOT NULL,
77+
"environment_ref" text NOT NULL,
78+
"revision" integer DEFAULT 0 NOT NULL,
79+
"state" jsonb NOT NULL,
80+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
81+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
82+
);
83+
--> statement-breakpoint
84+
CREATE TABLE "trigger_dashboard_agent"."watch_batches" (
85+
"environment_id" text NOT NULL,
86+
"cadence_minutes" integer NOT NULL,
87+
"epoch" integer DEFAULT 0 NOT NULL,
88+
"generation" integer DEFAULT 0 NOT NULL,
89+
"status" text DEFAULT 'running' NOT NULL,
90+
"armed_at" timestamp with time zone DEFAULT now() NOT NULL,
91+
"last_tick_at" timestamp with time zone,
92+
CONSTRAINT "watch_batches_environment_id_cadence_minutes_pk" PRIMARY KEY("environment_id","cadence_minutes")
93+
);
94+
--> statement-breakpoint
95+
CREATE TABLE "trigger_dashboard_agent"."watch_submissions" (
96+
"chat_id" text NOT NULL,
97+
"client_request_id" text NOT NULL,
98+
"organization_id" text NOT NULL,
99+
"user_id" text NOT NULL,
100+
"project_id" text NOT NULL,
101+
"environment_id" text NOT NULL,
102+
"draft_hash" text NOT NULL,
103+
"draft" jsonb NOT NULL,
104+
"state" text DEFAULT 'pending' NOT NULL,
105+
"watch_id" text,
106+
"unavailable" boolean DEFAULT false NOT NULL,
107+
"external_notification_status" text DEFAULT 'not_requested' NOT NULL,
108+
"external_notification_reason" text,
109+
"immediate_result" text,
110+
"refusal_code" text,
111+
"refusal_error" text,
112+
"refusal_existing_id" text,
113+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
114+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
115+
CONSTRAINT "watch_submissions_chat_id_client_request_id_pk" PRIMARY KEY("chat_id","client_request_id")
116+
);
117+
--> statement-breakpoint
118+
CREATE TABLE "trigger_dashboard_agent"."watches" (
119+
"id" text PRIMARY KEY NOT NULL,
120+
"chat_id" text NOT NULL,
121+
"identity" text NOT NULL,
122+
"spec" jsonb NOT NULL,
123+
"status" text DEFAULT 'active' NOT NULL,
124+
"delivery_status" text DEFAULT 'not_required' NOT NULL,
125+
"cancel_reason" text,
126+
"resolution" text,
127+
"observed_outcome" jsonb,
128+
"investigate_on_attention" boolean DEFAULT false NOT NULL,
129+
"organization_id" text NOT NULL,
130+
"project_id" text NOT NULL,
131+
"project_ref" text,
132+
"environment_id" text NOT NULL,
133+
"user_id" text NOT NULL,
134+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
135+
"expires_at" timestamp with time zone NOT NULL,
136+
"last_checked_at" timestamp with time zone,
137+
"last_attempted_at" timestamp with time zone,
138+
"fired_at" timestamp with time zone,
139+
"delivery_claimed_at" timestamp with time zone,
140+
"delivery_claim_id" text,
141+
"delivered_at" timestamp with time zone,
142+
"cancelled_at" timestamp with time zone,
143+
"last_result" jsonb,
144+
"tick_count" integer DEFAULT 0 NOT NULL,
145+
"alert_dispatch_key" text,
146+
"retention_at" timestamp with time zone GENERATED ALWAYS AS (greatest(delivered_at, cancelled_at, fired_at, last_checked_at, created_at)) STORED,
147+
"cadence_minutes" integer GENERATED ALWAYS AS (((spec ->> 'checkEveryMinutes')::int)) STORED
148+
);
149+
--> 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');

internal-packages/dashboard-agent-db/drizzle/0000_magenta_lilandra.sql

Lines changed: 0 additions & 25 deletions
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0001_slimy_living_tribunal.sql

Lines changed: 0 additions & 38 deletions
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0002_luxuriant_king_cobra.sql

Lines changed: 0 additions & 37 deletions
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0003_famous_champions.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0004_moaning_omega_sentinel.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0005_aspiring_unus.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0006_wooden_hex.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0007_glamorous_colleen_wing.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

internal-packages/dashboard-agent-db/drizzle/0008_chunky_spot.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)