import { index, integer, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"; export const computeWorkers = pgTable("compute_workers", { id: uuid("id").primaryKey().defaultRandom(), name: text("name").notNull().unique(), tokenHash: text("token_hash").notNull(), status: text("status").notNull().default("offline"), version: text("version"), protocolVersion: integer("protocol_version").notNull().default(1), lanIp: text("lan_ip"), nodeMeta: jsonb("node_meta").$type>().notNull().default({}), profiles: text("profiles").array().notNull().default(["standard"]), capacity: integer("capacity").notNull().default(1), running: integer("running").notNull().default(0), enrolledAt: timestamp("enrolled_at", { withTimezone: true }).notNull().defaultNow(), lastHeartbeatAt: timestamp("last_heartbeat_at", { withTimezone: true }), drainRequested: timestamp("drain_requested_at", { withTimezone: true }), quarantineReason: text("quarantine_reason"), disabledAt: timestamp("disabled_at", { withTimezone: true }), tokenRotatedAt: timestamp("token_rotated_at", { withTimezone: true }), }); export const workerHeartbeats = pgTable( "worker_heartbeats", { id: uuid("id").primaryKey().defaultRandom(), workerId: uuid("worker_id") .notNull() .references(() => computeWorkers.id, { onDelete: "cascade" }), load: jsonb("load").$type>().notNull().default({}), running: integer("running").notNull().default(0), createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), }, (t) => [index("worker_heartbeats_worker_idx").on(t.workerId, t.createdAt)], ); export const resourceProfiles = pgTable("resource_profiles", { id: uuid("id").primaryKey().defaultRandom(), slug: text("slug").notNull().unique(), name: text("name").notNull(), description: text("description").notNull().default(""), cpuCores: integer("cpu_cores").notNull(), ramGb: integer("ram_gb").notNull(), maxRuntimeMinutes: integer("max_runtime_minutes").notNull(), defaultBudgetUsd: integer("default_budget_usd").notNull(), requires: text("requires").array().notNull().default([]), }); export const workerAssignments = pgTable( "worker_assignments", { id: uuid("id").primaryKey().defaultRandom(), runId: uuid("run_id").notNull(), attemptId: uuid("attempt_id").notNull(), workerId: uuid("worker_id") .notNull() .references(() => computeWorkers.id), assignedAt: timestamp("assigned_at", { withTimezone: true }).notNull().defaultNow(), releasedAt: timestamp("released_at", { withTimezone: true }), releaseReason: text("release_reason"), }, (t) => [index("worker_assignments_run_idx").on(t.runId)], );