diff --git a/packages/db/migrations/0088_log_audit_at_index.ts b/packages/db/migrations/0088_log_audit_at_index.ts new file mode 100644 index 00000000..2dbcd1c9 --- /dev/null +++ b/packages/db/migrations/0088_log_audit_at_index.ts @@ -0,0 +1,17 @@ +import type { Kysely } from "kysely"; +import { execDdl } from "../src/migration-helpers.ts"; + +// 日志接口:审计来源按时间倒序取前 n 条,原有索引都以 action / actor / target 开头,只能整表排序; +// 补一个按时间的索引(审计会随登录、设置修改一直增长)。 +// 引擎表 openworkflow.workflow_runs 不在这里加索引:引擎自带 (namespace_id, created_at desc) 与 +// (namespace_id, status, created_at desc),日志查询已能沿用。 + +// biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型 +export async function up(db: Kysely): Promise { + await execDdl(db, `create index if not exists audit_event_at_idx on audit_event (at desc);`); +} + +// biome-ignore lint/suspicious/noExplicitAny: 同上 +export async function down(db: Kysely): Promise { + await execDdl(db, `drop index if exists audit_event_at_idx;`); +}