refactor(db,persistence): unify EventStore and WorkflowAlertStore onto core/db SQLite

This commit is contained in:
gitea committed 2026-09-30 00:26:49 +08:00
1 parent 5a0c277993
commit 3864f0ffd0
7 files changed
+228 -34

No files matched your search

+4
View File
@@ -37,6 +37,8 @@ describe("Core DB - 数据库连接与结构化迁移机制 (加固测试)", ()
expect(tableNames.has("approval_findings")).toBe(true);
expect(tableNames.has("aipro_logs")).toBe(true);
expect(tableNames.has("cache_entries")).toBe(true);
expect(tableNames.has("observed_events")).toBe(true);
expect(tableNames.has("workflow_error_alerts")).toBe(true);
// 检查加固索引:UPPER(short_id)、findings(rule_id)
const indices = db
@@ -51,6 +53,8 @@ describe("Core DB - 数据库连接与结构化迁移机制 (加固测试)", ()
expect(indexNames.has("idx_findings_rule_id")).toBe(true);
expect(indexNames.has("idx_cache_namespace")).toBe(true);
expect(indexNames.has("idx_cache_expires_at")).toBe(true);
expect(indexNames.has("idx_observed_events_scope")).toBe(true);
expect(indexNames.has("idx_workflow_alerts_scope")).toBe(true);
});
test("cache_entries 具备复合主键 (namespace, key) 约束", () => {
+32
View File
@@ -184,6 +184,38 @@ export const migrations: DatabaseMigration[] = [
}
},
},
{
version: 3,
name: "003_events_and_workflow_alerts_tables",
up(db: Database): void {
db.run(`
CREATE TABLE IF NOT EXISTS observed_events (
scope_key TEXT NOT NULL,
id TEXT NOT NULL,
corp_id TEXT NOT NULL,
kind TEXT NOT NULL,
observed_at INTEGER NOT NULL,
PRIMARY KEY (scope_key, id)
);
`);
db.run("CREATE INDEX IF NOT EXISTS idx_observed_events_scope ON observed_events(scope_key, observed_at);");
db.run(`
CREATE TABLE IF NOT EXISTS workflow_error_alerts (
scope_key TEXT NOT NULL,
id TEXT NOT NULL,
pipeline_id TEXT NOT NULL,
platform_id TEXT NOT NULL,
pipeline_name TEXT,
error_count INTEGER NOT NULL,
state INTEGER NOT NULL DEFAULT 0,
observed_at INTEGER NOT NULL,
PRIMARY KEY (scope_key, id)
);
`);
db.run("CREATE INDEX IF NOT EXISTS idx_workflow_alerts_scope ON workflow_error_alerts(scope_key);");
},
},
];
function seedDefaultPreference(db: Database): void {