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")
);

View File

@@ -0,0 +1,519 @@
{
"id": "629b632c-cf1f-46ff-bb2f-e47d2343ddbd",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.harness_agent_configs": {
"name": "harness_agent_configs",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"runtime": {
"name": "runtime",
"type": "text",
"primaryKey": false,
"notNull": true
},
"model_id": {
"name": "model_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true
},
"max_tokens": {
"name": "max_tokens",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"env": {
"name": "env",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.harness_credentials": {
"name": "harness_credentials",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true
},
"label": {
"name": "label",
"type": "text",
"primaryKey": false,
"notNull": true
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": true
},
"base_url": {
"name": "base_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.harness_curated_models": {
"name": "harness_curated_models",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true
},
"enabled": {
"name": "enabled",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": true
},
"context_window": {
"name": "context_window",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"cost_per_1k_input": {
"name": "cost_per_1k_input",
"type": "real",
"primaryKey": false,
"notNull": false
},
"cost_per_1k_output": {
"name": "cost_per_1k_output",
"type": "real",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.harness_iterations": {
"name": "harness_iterations",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"task_id": {
"name": "task_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"n": {
"name": "n",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'pending'"
},
"diagnosis": {
"name": "diagnosis",
"type": "text",
"primaryKey": false,
"notNull": false
},
"agent_output": {
"name": "agent_output",
"type": "text",
"primaryKey": false,
"notNull": false
},
"evals": {
"name": "evals",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"diff_stats": {
"name": "diff_stats",
"type": "text",
"primaryKey": false,
"notNull": false
},
"started_at": {
"name": "started_at",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"completed_at": {
"name": "completed_at",
"type": "bigint",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.harness_model_usage": {
"name": "harness_model_usage",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"model_id": {
"name": "model_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true
},
"task_id": {
"name": "task_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"task_slug": {
"name": "task_slug",
"type": "text",
"primaryKey": false,
"notNull": true
},
"iteration": {
"name": "iteration",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"input_tokens": {
"name": "input_tokens",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"output_tokens": {
"name": "output_tokens",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"duration_ms": {
"name": "duration_ms",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"timestamp": {
"name": "timestamp",
"type": "bigint",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.harness_tasks": {
"name": "harness_tasks",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"slug": {
"name": "slug",
"type": "text",
"primaryKey": false,
"notNull": true
},
"goal": {
"name": "goal",
"type": "text",
"primaryKey": false,
"notNull": true
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'pending'"
},
"iteration": {
"name": "iteration",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"max_iterations": {
"name": "max_iterations",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 6
},
"started_at": {
"name": "started_at",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"completed_at": {
"name": "completed_at",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"project": {
"name": "project",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'—'"
},
"evals": {
"name": "evals",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"pr": {
"name": "pr",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"spec": {
"name": "spec",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1774124029586,
"tag": "0000_sparkling_gressill",
"breakpoints": true
}
]
}

View File

@@ -1,4 +1,16 @@
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
import {
pgTable,
serial,
text,
timestamp,
boolean,
integer,
real,
jsonb,
bigint,
} from "drizzle-orm/pg-core";
// ─── EXISTING ───────────────────────────────────────────────
export const users = pgTable("users", {
id: serial("id").primaryKey(),
@@ -7,3 +19,101 @@ export const users = pgTable("users", {
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// ─── HARNESS: CREDENTIALS ──────────────────────────────────
export const credentials = pgTable("harness_credentials", {
id: text("id").primaryKey(),
provider: text("provider").notNull(),
label: text("label").notNull(),
token: text("token").notNull(),
baseUrl: text("base_url"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// ─── HARNESS: CURATED MODELS ───────────────────────────────
export const curatedModels = pgTable("harness_curated_models", {
id: text("id").primaryKey(),
name: text("name").notNull(),
provider: text("provider").notNull(),
enabled: boolean("enabled").default(true).notNull(),
contextWindow: integer("context_window"),
costPer1kInput: real("cost_per_1k_input"),
costPer1kOutput: real("cost_per_1k_output"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// ─── HARNESS: MODEL USAGE ──────────────────────────────────
export const modelUsage = pgTable("harness_model_usage", {
id: serial("id").primaryKey(),
modelId: text("model_id").notNull(),
provider: text("provider").notNull(),
taskId: text("task_id").notNull(),
taskSlug: text("task_slug").notNull(),
iteration: integer("iteration").notNull(),
inputTokens: integer("input_tokens").notNull(),
outputTokens: integer("output_tokens").notNull(),
durationMs: integer("duration_ms").notNull(),
timestamp: bigint("timestamp", { mode: "number" }).notNull(),
});
// ─── HARNESS: AGENT CONFIGS ────────────────────────────────
export const agentConfigs = pgTable("harness_agent_configs", {
id: text("id").primaryKey(),
name: text("name").notNull(),
runtime: text("runtime").notNull(), // "claude-code" | "codex" | "opencode"
modelId: text("model_id").notNull(),
provider: text("provider").notNull(),
maxTokens: integer("max_tokens"),
env: jsonb("env").$type<Record<string, string>>(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// ─── HARNESS: TASKS ────────────────────────────────────────
export const tasks = pgTable("harness_tasks", {
id: text("id").primaryKey(),
slug: text("slug").notNull(),
goal: text("goal").notNull(),
status: text("status").notNull().default("pending"), // pending | running | completed | failed
iteration: integer("iteration").notNull().default(0),
maxIterations: integer("max_iterations").notNull().default(6),
startedAt: bigint("started_at", { mode: "number" }),
completedAt: bigint("completed_at", { mode: "number" }),
project: text("project").notNull().default("—"),
evals: jsonb("evals").$type<Record<string, unknown>>().default({}).notNull(),
pr: jsonb("pr").$type<{ number: number; title: string; status: string }>(),
spec: jsonb("spec").$type<{
slug: string;
goal: string;
project: string;
agentId: string;
maxIterations: number;
criteria: { label: string; target: string }[];
constraints: string[];
knowledgeRefs: string[];
}>().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// ─── HARNESS: ITERATIONS ───────────────────────────────────
export const iterations = pgTable("harness_iterations", {
id: serial("id").primaryKey(),
taskId: text("task_id").notNull(),
n: integer("n").notNull(),
status: text("status").notNull().default("pending"), // pending | running | passed | failed
diagnosis: text("diagnosis"),
agentOutput: text("agent_output"),
evals: jsonb("evals").$type<Record<string, unknown>>(),
diffStats: text("diff_stats"),
startedAt: bigint("started_at", { mode: "number" }),
completedAt: bigint("completed_at", { mode: "number" }),
});