/** * human-tool 的 sys schema 表(编码规范 §7 / ADR-002)。 */ import { index, jsonb, text, timestamp } from 'drizzle-orm/pg-core'; import { sys } from '@shared/db.ts'; /** 工单两模式 —— 执行 / 验收;落地失败卡是执行工单的 preset,不另立表 */ export const workOrderTable = sys.table( 'work_order', { id: text('id').primaryKey(), taskId: text('task_id').notNull(), recipientId: text('recipient_id').notNull(), mode: text('mode').notNull(), title: text('title').notNull(), payload: jsonb('payload').notNull(), at: timestamp('at', { withTimezone: true }).notNull(), done: jsonb('done'), }, (t) => [index('work_order_task_idx').on(t.taskId, t.at), index('work_order_recipient_idx').on(t.recipientId)], ); /** 对话卡族 —— 决策 / 补全 / 评价 */ export const chatCardTable = sys.table( 'chat_card', { id: text('id').primaryKey(), taskId: text('task_id').notNull(), recipientId: text('recipient_id').notNull(), kind: text('kind').notNull(), payload: jsonb('payload').notNull(), at: timestamp('at', { withTimezone: true }).notNull(), /** 驳回重答:原卡以 supersededBy 闭合 —— 只增不改 */ supersededBy: text('superseded_by'), rejectedReason: text('rejected_reason'), }, (t) => [index('chat_card_task_idx').on(t.taskId, t.at), index('chat_card_recipient_idx').on(t.recipientId)], );