feat(04-01): add agents table to database schema

- Define agents table with id, name (unique), taskId, sessionId, worktreeId, status
- Status enum: idle, running, waiting_for_input, stopped, crashed
- Foreign key to tasks with onDelete: 'set null' (agent may outlive task)
- Add agentsRelations linking to tasks
- Export Agent and NewAgent types
This commit is contained in:
Lukas May
2026-01-30 19:58:35 +01:00
parent ffe5acceff
commit dfaa51076b

View File

@@ -168,3 +168,32 @@ export const taskDependenciesRelations = relations(taskDependencies, ({ one }) =
export type TaskDependency = InferSelectModel<typeof taskDependencies>;
export type NewTaskDependency = InferInsertModel<typeof taskDependencies>;
// ============================================================================
// AGENTS
// ============================================================================
export const agents = sqliteTable('agents', {
id: text('id').primaryKey(),
name: text('name').notNull().unique(), // Human-readable name (e.g., 'gastown', 'chinatown')
taskId: text('task_id').references(() => tasks.id, { onDelete: 'set null' }), // Task may be deleted
sessionId: text('session_id'), // Claude CLI session ID for resumption (null until first run completes)
worktreeId: text('worktree_id').notNull(), // WorktreeManager worktree ID
status: text('status', {
enum: ['idle', 'running', 'waiting_for_input', 'stopped', 'crashed'],
})
.notNull()
.default('idle'),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});
export const agentsRelations = relations(agents, ({ one }) => ({
task: one(tasks, {
fields: [agents.taskId],
references: [tasks.id],
}),
}));
export type Agent = InferSelectModel<typeof agents>;
export type NewAgent = InferInsertModel<typeof agents>;