Add database package with Drizzle schema
Postgres schema via Drizzle ORM for agents, goals, issues, projects, and activity log tables. Includes migration runner, seed script, and Drizzle config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
12
packages/db/src/schema/activity_log.ts
Normal file
12
packages/db/src/schema/activity_log.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { pgTable, uuid, text, timestamp, jsonb } from "drizzle-orm/pg-core";
|
||||
import { agents } from "./agents.js";
|
||||
|
||||
export const activityLog = pgTable("activity_log", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
action: text("action").notNull(),
|
||||
entityType: text("entity_type").notNull(),
|
||||
entityId: uuid("entity_id").notNull(),
|
||||
agentId: uuid("agent_id").references(() => agents.id),
|
||||
details: jsonb("details"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
15
packages/db/src/schema/agents.ts
Normal file
15
packages/db/src/schema/agents.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { type AnyPgColumn, pgTable, uuid, text, integer, timestamp, jsonb } from "drizzle-orm/pg-core";
|
||||
|
||||
export const agents = pgTable("agents", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
name: text("name").notNull(),
|
||||
role: text("role").notNull().default("general"),
|
||||
status: text("status").notNull().default("idle"),
|
||||
budgetCents: integer("budget_cents").notNull().default(0),
|
||||
spentCents: integer("spent_cents").notNull().default(0),
|
||||
lastHeartbeat: timestamp("last_heartbeat", { withTimezone: true }),
|
||||
reportsTo: uuid("reports_to").references((): AnyPgColumn => agents.id),
|
||||
metadata: jsonb("metadata"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
13
packages/db/src/schema/goals.ts
Normal file
13
packages/db/src/schema/goals.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { type AnyPgColumn, pgTable, uuid, text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { agents } from "./agents.js";
|
||||
|
||||
export const goals = pgTable("goals", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
title: text("title").notNull(),
|
||||
description: text("description"),
|
||||
level: text("level").notNull().default("task"),
|
||||
parentId: uuid("parent_id").references((): AnyPgColumn => goals.id),
|
||||
ownerId: uuid("owner_id").references(() => agents.id),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
5
packages/db/src/schema/index.ts
Normal file
5
packages/db/src/schema/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export { agents } from "./agents.js";
|
||||
export { projects } from "./projects.js";
|
||||
export { goals } from "./goals.js";
|
||||
export { issues } from "./issues.js";
|
||||
export { activityLog } from "./activity_log.js";
|
||||
17
packages/db/src/schema/issues.ts
Normal file
17
packages/db/src/schema/issues.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { pgTable, uuid, text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { agents } from "./agents.js";
|
||||
import { projects } from "./projects.js";
|
||||
import { goals } from "./goals.js";
|
||||
|
||||
export const issues = pgTable("issues", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
title: text("title").notNull(),
|
||||
description: text("description"),
|
||||
status: text("status").notNull().default("backlog"),
|
||||
priority: text("priority").notNull().default("medium"),
|
||||
projectId: uuid("project_id").references(() => projects.id),
|
||||
assigneeId: uuid("assignee_id").references(() => agents.id),
|
||||
goalId: uuid("goal_id").references(() => goals.id),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
9
packages/db/src/schema/projects.ts
Normal file
9
packages/db/src/schema/projects.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { pgTable, uuid, text, timestamp } from "drizzle-orm/pg-core";
|
||||
|
||||
export const projects = pgTable("projects", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
Reference in New Issue
Block a user