Files
aiops/backend/internal/models/sql_audit.go
T
attacker 77c33a6fee feat: 服务器批量导入全栈实现 + SQL审计模型修复 + 审批流程增强
服务器批量导入:
- 后端 BatchCreateServers handler: 逐条校验/查重/GB→MB转换/错误明细
- 前端 CSV 解析器 + IP校验 + 模板下载 + 真实API导入
- 删除孤立占位组件 BatchImport.tsx

SQL审计:
- 修复 TableName 字段与 GORM 接口冲突 → TargetTable
- 补全路由注册 + AutoMigrate + 种子数据

审批流程增强 + 告警/菜单微调

// Logan.Li
2026-06-15 02:12:05 +08:00

65 lines
2.8 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
// SQLAuditRecord SQL审计记录 // Logan.Li
type SQLAuditRecord struct {
ID uint `gorm:"primarykey" json:"id"`
SQLContent string `gorm:"type:text;not null" json:"sql_content"`
SQLType string `gorm:"size:50" json:"sql_type"` // DDL/DML/DQL/DCL
DatabaseName string `gorm:"size:255" json:"database_name"`
TargetTable string `gorm:"column:table_name;size:255" json:"table_name"`
RiskLevel string `gorm:"size:20;default:safe" json:"risk_level"` // high/medium/low/safe
RiskRules string `gorm:"type:text" json:"risk_rules"` // JSON 数组
Status string `gorm:"size:20;default:pending" json:"status"` // pending/approved/rejected/executed
Executor string `gorm:"size:255" json:"executor"`
Approver string `gorm:"size:255" json:"approver"`
ExecuteTime *time.Time `json:"execute_time"`
AffectedRows int64 `gorm:"default:0" json:"affected_rows"`
ExecutionTime int64 `gorm:"default:0" json:"execution_time"` // 毫秒
SourceIP string `gorm:"size:100" json:"source_ip"`
Application string `gorm:"size:255" json:"application"`
TicketID string `gorm:"size:100" json:"ticket_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (SQLAuditRecord) TableName() string { return "sql_audit_records" }
// SQLAuditRule SQL审计规则 // Logan.Li
type SQLAuditRule struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:255;not null" json:"name"`
Description string `gorm:"type:text" json:"description"`
Pattern string `gorm:"type:text" json:"pattern"` // 正则/关键词匹配
Enabled bool `gorm:"default:true" json:"enabled"`
Severity string `gorm:"size:20;default:medium" json:"severity"` // high/medium/low
Category string `gorm:"size:100" json:"category"` // DDL/DML/DROP/TRUNCATE/etc
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (SQLAuditRule) TableName() string { return "sql_audit_rules" }
// AnalyzeSQLRequest SQL分析请求 // Logan.Li
type AnalyzeSQLRequest struct {
SQL string `json:"sql"`
DatabaseName string `json:"database_name"`
Application string `json:"application"`
}
// AnalyzeSQLResponse SQL分析响应 // Logan.Li
type AnalyzeSQLResponse struct {
ID int64 `json:"id"`
RiskLevel string `json:"risk_level"`
RiskRules []string `json:"risk_rules"`
SQLType string `json:"sql_type"`
TableName string `json:"table_name"`
}