From 14cb2c4c7ead34499b5c8606ebf3c5303d97c2c3 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Oct 2026 19:34:07 +0800 Subject: [PATCH] =?UTF-8?q?perf(db):=20=E5=AE=A1=E8=AE=A1=E6=8C=89?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=80=92=E5=BA=8F=E7=B4=A2=E5=BC=95(?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=200088)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 日志接口审计来源按时间倒序取前 n 条,原有索引都不以 at 开头。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei --- .../db/migrations/0088_log_audit_at_index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/db/migrations/0088_log_audit_at_index.ts 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;`); +}