Add files via upload

This commit is contained in:
公明
2026-07-13 19:06:02 +08:00
committed by GitHub
parent 078f5cb222
commit 386ec7b835
6 changed files with 349 additions and 1 deletions
+34
View File
@@ -58,6 +58,7 @@ type DB struct {
checkpointDone chan struct{}
closeOnce sync.Once
closeErr error
vulnerabilityCreatedHook func(*Vulnerability)
}
// startPassiveCheckpointLoop 启动后台 PASSIVE checkpoint 循环。
@@ -404,6 +405,33 @@ func (db *DB) initTables() error {
FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE SET NULL
);`
createVulnerabilityAlertSubscriptionsTable := `
CREATE TABLE IF NOT EXISTS vulnerability_alert_subscriptions (
user_id TEXT PRIMARY KEY,
enabled INTEGER NOT NULL DEFAULT 0,
min_severity TEXT NOT NULL DEFAULT 'high',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES rbac_users(id) ON DELETE CASCADE
);`
createVulnerabilityAlertDeliveriesTable := `
CREATE TABLE IF NOT EXISTS vulnerability_alert_deliveries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
vulnerability_id TEXT NOT NULL,
user_id TEXT NOT NULL,
platform TEXT NOT NULL,
external_user_id TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
attempts INTEGER NOT NULL DEFAULT 0,
next_attempt_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_error TEXT NOT NULL DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE(vulnerability_id, platform, external_user_id),
FOREIGN KEY (vulnerability_id) REFERENCES vulnerabilities(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES rbac_users(id) ON DELETE CASCADE
);`
// 创建批量任务队列表
createBatchTaskQueuesTable := `
CREATE TABLE IF NOT EXISTS batch_task_queues (
@@ -794,6 +822,12 @@ func (db *DB) initTables() error {
if err := db.initRBACTables(); err != nil {
return fmt.Errorf("创建RBAC表失败: %w", err)
}
if _, err := db.Exec(createVulnerabilityAlertSubscriptionsTable); err != nil {
return fmt.Errorf("创建漏洞提醒订阅表失败: %w", err)
}
if _, err := db.Exec(createVulnerabilityAlertDeliveriesTable); err != nil {
return fmt.Errorf("创建漏洞提醒投递表失败: %w", err)
}
for tableName, ddl := range map[string]string{
"workflow_definitions": createWorkflowDefinitionsTable,