feat(db): 0013 tasks tables and 0014 agent_run_event; tasks uses db migrations

tasks_run_meta/tasks_fact/tasks_op_ledger move into packages/db (if not exists, old
tasks_migration tables dropped); packages/tasks/migrations and migrateTasksTables
removed, tests migrate their schema with @umt/db. agent_run_event(run_id, seq, type,
at, payload) with (run_id, seq) primary key; types regenerated, db-sync covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-27 19:15:50 +08:00
1 parent db5352eecd
commit da8e53bbca
13 files changed
+250 -36

No files matched your search

+5 -4
View File
@@ -4,9 +4,9 @@ import { type EnqueueOptions, OutboxRelay, type TaskEngine } from "../src/index.
import { createTestRegistry } from "./fixtures/tasks.ts";
import {
connectDb,
createOutboxTable,
createSideEffectTable,
dropSchemas,
migrateBizSchema,
pgAvailable,
resetSchemas,
setupEngine,
@@ -24,7 +24,7 @@ describe.skipIf(!hasPg)("OutboxRelay", () => {
beforeAll(async () => {
await resetSchemas(schemas);
db = connectDb(schemas.biz);
await createOutboxTable(db);
await migrateBizSchema(db, schemas.biz);
await createSideEffectTable(db);
engine = await setupEngine(db, schemas, createTestRegistry(db));
}, 30_000);
@@ -80,11 +80,12 @@ describe.skipIf(!hasPg)("OutboxRelay", () => {
SELECT count(*) n FROM outbox_event WHERE status = 'dispatched' AND published_at IS NOT NULL AND attempts = 1`.execute(
db,
);
expect(dispatched.rows[0]!.n).toBe("60");
// @umt/db 把 int8 解析为 number(全局 pg 类型解析器),这里统一转成数字比较
expect(Number(dispatched.rows[0]!.n)).toBe(60);
const runs = await sql<{ n: string; keys: string }>`
SELECT count(*) n, count(DISTINCT idempotency_key) keys FROM tasks_run_meta WHERE task_name = 'echo'`.execute(db);
expect(runs.rows[0]).toEqual({ n: "60", keys: "60" });
expect([Number(runs.rows[0]!.n), Number(runs.rows[0]!.keys)]).toEqual([60, 60]);
const traced = await sql<{ trace_id: string }>`
SELECT m.trace_id FROM tasks_run_meta m
JOIN outbox_event o ON m.idempotency_key = 'outbox:' || o.id::text