CREATE TABLE IF NOT EXISTS "harness_event_log" (
	"id" serial PRIMARY KEY NOT NULL,
	"trigger_id" text NOT NULL,
	"delivery_id" text NOT NULL,
	"event_type" text NOT NULL,
	"repo" text NOT NULL,
	"commit_sha" text,
	"branch" text,
	"status" text DEFAULT 'received' NOT NULL,
	"task_id" text,
	"skip_reason" text,
	"error" text,
	"payload" jsonb NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "harness_event_log_delivery_id_unique" UNIQUE("delivery_id")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "harness_event_triggers" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"enabled" boolean DEFAULT true NOT NULL,
	"event_type" text NOT NULL,
	"repo_filter" text,
	"state_filter" text,
	"context_filter" text,
	"task_template" jsonb NOT NULL,
	"consecutive_failures" integer DEFAULT 0 NOT NULL,
	"max_consecutive_failures" integer DEFAULT 3 NOT NULL,
	"disabled_reason" text,
	"webhook_secret" text,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "harness_orchestrator" (
	"id" text PRIMARY KEY DEFAULT 'singleton' NOT NULL,
	"running" boolean DEFAULT false NOT NULL,
	"current_task_id" text,
	"heartbeat" bigint,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "harness_tasks" ADD COLUMN "cancel_requested" boolean DEFAULT false NOT NULL;