CREATE TABLE "convoy_events" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"workspace_id" uuid NOT NULL,
	"convoy_id" uuid,
	"convoy_slug" varchar(200) NOT NULL,
	"role" varchar(50) NOT NULL,
	"brief" integer,
	"classification" varchar(30),
	"skip_flags" text[],
	"duration_s" integer,
	"stack_class" varchar(30),
	"repo" varchar(100) NOT NULL,
	"outcome" varchar(20),
	"multitask_group" varchar(64),
	"metadata" jsonb,
	"ts" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "convoy_events" ADD CONSTRAINT "convoy_events_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "convoy_events" ADD CONSTRAINT "convoy_events_convoy_id_objects_id_fk" FOREIGN KEY ("convoy_id") REFERENCES "public"."objects"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "convoy_events_workspace_id_ts_idx" ON "convoy_events" USING btree ("workspace_id","ts" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "convoy_events_convoy_id_ts_idx" ON "convoy_events" USING btree ("convoy_id","ts" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX "convoy_events_convoy_slug_repo_idx" ON "convoy_events" USING btree ("convoy_slug","repo");--> statement-breakpoint
CREATE INDEX "convoy_events_role_idx" ON "convoy_events" USING btree ("role");