Migrate harness from in-memory stores to CloudNativePG
Some checks failed
CI / lint-and-test (push) Successful in 22s
Deploy Production / deploy (push) Failing after 21s
CI / build (push) Failing after 1m51s

Replace all in-memory Map-backed stores (credentials, models, agents,
tasks, iterations, usage) with Drizzle ORM queries against the
homelab-pg PostgreSQL cluster. All store functions are now async.

- Add 6 harness_* tables to @homelab/db schema
- Generate and apply initial Drizzle migration
- Add lazy DB connection proxy to avoid build-time errors
- Wire DATABASE_URL from sealed secret into harness deployment
- Update all API routes, orchestrator, executor, and boot to await
  async store operations
This commit is contained in:
Julia McGhee
2026-03-21 20:17:00 +00:00
parent df351439d6
commit 3fe75a8e04
28 changed files with 1245 additions and 304 deletions

View File

@@ -0,0 +1,85 @@
CREATE TABLE IF NOT EXISTS "harness_agent_configs" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"runtime" text NOT NULL,
"model_id" text NOT NULL,
"provider" text NOT NULL,
"max_tokens" integer,
"env" jsonb,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "harness_credentials" (
"id" text PRIMARY KEY NOT NULL,
"provider" text NOT NULL,
"label" text NOT NULL,
"token" text NOT NULL,
"base_url" text,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "harness_curated_models" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"provider" text NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"context_window" integer,
"cost_per_1k_input" real,
"cost_per_1k_output" real,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "harness_iterations" (
"id" serial PRIMARY KEY NOT NULL,
"task_id" text NOT NULL,
"n" integer NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"diagnosis" text,
"agent_output" text,
"evals" jsonb,
"diff_stats" text,
"started_at" bigint,
"completed_at" bigint
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "harness_model_usage" (
"id" serial PRIMARY KEY NOT NULL,
"model_id" text NOT NULL,
"provider" text NOT NULL,
"task_id" text NOT NULL,
"task_slug" text NOT NULL,
"iteration" integer NOT NULL,
"input_tokens" integer NOT NULL,
"output_tokens" integer NOT NULL,
"duration_ms" integer NOT NULL,
"timestamp" bigint NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "harness_tasks" (
"id" text PRIMARY KEY NOT NULL,
"slug" text NOT NULL,
"goal" text NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"iteration" integer DEFAULT 0 NOT NULL,
"max_iterations" integer DEFAULT 6 NOT NULL,
"started_at" bigint,
"completed_at" bigint,
"project" text DEFAULT '' NOT NULL,
"evals" jsonb DEFAULT '{}'::jsonb NOT NULL,
"pr" jsonb,
"spec" jsonb NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"email" text NOT NULL,
"name" text,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "users_email_unique" UNIQUE("email")
);