spb/autoscholar
Public
1import { index, integer, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";23export const computeWorkers = pgTable("compute_workers", {4 id: uuid("id").primaryKey().defaultRandom(),5 name: text("name").notNull().unique(),6 tokenHash: text("token_hash").notNull(),7 status: text("status").notNull().default("offline"),8 version: text("version"),9 protocolVersion: integer("protocol_version").notNull().default(1),10 lanIp: text("lan_ip"),11 nodeMeta: jsonb("node_meta").$type<Record<string, unknown>>().notNull().default({}),12 profiles: text("profiles").array().notNull().default(["standard"]),13 capacity: integer("capacity").notNull().default(1),14 running: integer("running").notNull().default(0),15 enrolledAt: timestamp("enrolled_at", { withTimezone: true }).notNull().defaultNow(),16 lastHeartbeatAt: timestamp("last_heartbeat_at", { withTimezone: true }),17 drainRequested: timestamp("drain_requested_at", { withTimezone: true }),18 quarantineReason: text("quarantine_reason"),19 disabledAt: timestamp("disabled_at", { withTimezone: true }),20 tokenRotatedAt: timestamp("token_rotated_at", { withTimezone: true }),21});2223export const workerHeartbeats = pgTable(24 "worker_heartbeats",25 {26 id: uuid("id").primaryKey().defaultRandom(),27 workerId: uuid("worker_id")28 .notNull()29 .references(() => computeWorkers.id, { onDelete: "cascade" }),30 load: jsonb("load").$type<Record<string, unknown>>().notNull().default({}),31 running: integer("running").notNull().default(0),32 createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),33 },34 (t) => [index("worker_heartbeats_worker_idx").on(t.workerId, t.createdAt)],35);3637export const resourceProfiles = pgTable("resource_profiles", {38 id: uuid("id").primaryKey().defaultRandom(),39 slug: text("slug").notNull().unique(),40 name: text("name").notNull(),41 description: text("description").notNull().default(""),42 cpuCores: integer("cpu_cores").notNull(),43 ramGb: integer("ram_gb").notNull(),44 maxRuntimeMinutes: integer("max_runtime_minutes").notNull(),45 defaultBudgetUsd: integer("default_budget_usd").notNull(),46 requires: text("requires").array().notNull().default([]),47});4849export const workerAssignments = pgTable(50 "worker_assignments",51 {52 id: uuid("id").primaryKey().defaultRandom(),53 runId: uuid("run_id").notNull(),54 attemptId: uuid("attempt_id").notNull(),55 workerId: uuid("worker_id")56 .notNull()57 .references(() => computeWorkers.id),58 assignedAt: timestamp("assigned_at", { withTimezone: true }).notNull().defaultNow(),59 releasedAt: timestamp("released_at", { withTimezone: true }),60 releaseReason: text("release_reason"),61 },62 (t) => [index("worker_assignments_run_idx").on(t.runId)],63);64