refactor: unify kubernetes_ table prefix, merge CI/CD models, LLM session support
- Rename container_clusters → kubernetes_clusters, container_topology_layouts → kubernetes_topology_layouts - LLM: add session_id to chat history for multi-turn conversation support - CI/CD: add pipeline_id, deploy_type, artifact_url, k8s_cluster_id to AppRelease - Cleanup: remove deprecated playbook handler, simplify automation models - Database: optimize auto-migrate model list - Frontend: AIOps assistant improvements, api.ts updates
This commit is contained in:
1 parent
9365c1e9db
commit
732974d152
14 files changed
+121
-474
No files matched your search
@@ -59,10 +59,10 @@ func (Script) TableName() string {
|
||||
return "ops_scripts"
|
||||
}
|
||||
|
||||
// TaskExecution 任务执行记录
|
||||
// TaskExecution 任务执行记录(cron / script,不含 Ansible;Ansible 走 AnsibleJob)
|
||||
type TaskExecution struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TaskType string `gorm:"size:32;not null" json:"task_type"` // cron, script, playbook
|
||||
TaskType string `gorm:"size:32;not null" json:"task_type"` // cron, script
|
||||
TaskID uint `json:"task_id"`
|
||||
TaskName string `gorm:"size:128" json:"task_name"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, running, success, failed, cancelled
|
||||
@@ -83,42 +83,6 @@ func (TaskExecution) TableName() string {
|
||||
return "ops_task_executions"
|
||||
}
|
||||
|
||||
// Playbook Ansible Playbook模型
|
||||
type Playbook struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Content string `gorm:"type:text;not null" json:"content"`
|
||||
Category string `gorm:"size:64" json:"category"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON 数组字符串,如 ["deploy","docker"]
|
||||
Variables string `gorm:"type:text" json:"variables"`
|
||||
Inventory string `gorm:"type:text" json:"inventory"`
|
||||
Timeout int `gorm:"default:600" json:"timeout"`
|
||||
RunCount int `gorm:"default:0" json:"run_count"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
UpdatedBy uint `json:"updated_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Playbook) TableName() string {
|
||||
return "ops_playbooks"
|
||||
}
|
||||
|
||||
// CreatePlaybookRequest 创建Playbook请求
|
||||
type CreatePlaybookRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
Category string `json:"category"`
|
||||
Tags string `json:"tags"` // JSON 数组字符串
|
||||
Variables string `json:"variables"`
|
||||
Inventory string `json:"inventory"`
|
||||
Timeout int `json:"timeout"`
|
||||
}
|
||||
|
||||
// CreateCronJobRequest 创建定时任务请求
|
||||
type CreateCronJobRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
|
||||
@@ -32,7 +32,7 @@ func (Pipeline) TableName() string {
|
||||
return "ops_pipelines"
|
||||
}
|
||||
|
||||
// PipelineRun 流水线运行记录
|
||||
// PipelineRun 流水线运行记录(CI 执行)
|
||||
type PipelineRun struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PipelineID uint `gorm:"not null" json:"pipeline_id"`
|
||||
@@ -42,6 +42,8 @@ type PipelineRun struct {
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
||||
ArtifactURL string `gorm:"size:500" json:"artifact_url"` // 构建产物地址
|
||||
Duration int `json:"duration"` // 秒
|
||||
Stages string `gorm:"type:text" json:"stages"` // JSON
|
||||
Logs string `gorm:"type:longtext" json:"logs"`
|
||||
@@ -57,16 +59,19 @@ type PipelineRun struct {
|
||||
|
||||
// TableName 表名
|
||||
func (PipelineRun) TableName() string {
|
||||
return "pipeline_runs"
|
||||
return "ops_pipeline_runs"
|
||||
}
|
||||
|
||||
// AppRelease 应用发布模型
|
||||
// AppRelease 应用发布模型(CD:从 CI 产物部署到目标环境)
|
||||
type AppRelease struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PipelineID *uint `json:"pipeline_id"` // 来源流水线
|
||||
PipelineRunID *uint `json:"pipeline_run_id"` // 来源 CI 执行记录
|
||||
AppName string `gorm:"size:128;not null" json:"app_name"`
|
||||
Version string `gorm:"size:64;not null" json:"version"`
|
||||
Environment string `gorm:"size:32;not null" json:"environment"` // dev, test, staging, prod
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, building, deploying, success, failed, rolled_back
|
||||
DeployType string `gorm:"size:32;default:server" json:"deploy_type"` // server, kubernetes
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected, deploying, success, failed, rolled_back
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
@@ -75,7 +80,10 @@ type AppRelease struct {
|
||||
DeployedAt *time.Time `json:"deployed_at"`
|
||||
RollbackAt *time.Time `json:"rollback_at"`
|
||||
Duration int `json:"duration"`
|
||||
Servers string `gorm:"type:text" json:"servers"` // JSON
|
||||
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
||||
K8sClusterID *uint `json:"k8s_cluster_id"` // Kubernetes 部署目标集群
|
||||
K8sNamespace string `gorm:"size:128" json:"k8s_namespace"` // Kubernetes 部署目标命名空间
|
||||
Servers string `gorm:"type:text" json:"servers"` // JSON(传统服务器部署目标)
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
@@ -107,13 +115,19 @@ type TriggerPipelineRequest struct {
|
||||
|
||||
// CreateAppReleaseRequest 创建应用发布请求
|
||||
type CreateAppReleaseRequest struct {
|
||||
AppName string `json:"app_name" binding:"required"`
|
||||
Version string `json:"version" binding:"required"`
|
||||
Environment string `json:"environment" binding:"required,oneof=dev test staging prod"`
|
||||
CommitID string `json:"commit_id"`
|
||||
CommitMsg string `json:"commit_msg"`
|
||||
Servers []uint `json:"servers"`
|
||||
Description string `json:"description"`
|
||||
PipelineID *uint `json:"pipeline_id"`
|
||||
PipelineRunID *uint `json:"pipeline_run_id"`
|
||||
AppName string `json:"app_name" binding:"required"`
|
||||
Version string `json:"version" binding:"required"`
|
||||
Environment string `json:"environment" binding:"required,oneof=dev test staging prod"`
|
||||
DeployType string `json:"deploy_type" binding:"omitempty,oneof=server kubernetes"`
|
||||
CommitID string `json:"commit_id"`
|
||||
CommitMsg string `json:"commit_msg"`
|
||||
ImageTag string `json:"image_tag"`
|
||||
K8sClusterID *uint `json:"k8s_cluster_id"`
|
||||
K8sNamespace string `json:"k8s_namespace"`
|
||||
Servers []uint `json:"servers"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// PipelineStats 流水线统计
|
||||
|
||||
@@ -32,7 +32,7 @@ type KubernetesCluster struct {
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesCluster) TableName() string {
|
||||
return "container_clusters"
|
||||
return "kubernetes_clusters"
|
||||
}
|
||||
|
||||
// KubernetesNode K8s节点模型
|
||||
@@ -198,5 +198,5 @@ type TopologyLayout struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (TopologyLayout) TableName() string {
|
||||
return "container_topology_layouts"
|
||||
return "kubernetes_topology_layouts"
|
||||
}
|
||||
@@ -19,7 +19,7 @@ type LLMConfig struct {
|
||||
}
|
||||
|
||||
// TableName 表名 // Logan.Li
|
||||
func (LLMConfig) TableName() string { return "sys_llm_configs" }
|
||||
func (LLMConfig) TableName() string { return "ai_llm_configs" }
|
||||
|
||||
// SaveLLMConfigRequest 保存 LLM 配置请求 // Logan.Li
|
||||
type SaveLLMConfigRequest struct {
|
||||
@@ -41,7 +41,8 @@ type ChatMessage struct {
|
||||
|
||||
// ChatRequest AI 对话请求 // Logan.Li
|
||||
type ChatRequest struct {
|
||||
Messages []ChatMessage `json:"messages" binding:"required,min=1,dive"`
|
||||
Messages []ChatMessage `json:"messages" binding:"required,min=1,dive"`
|
||||
SessionID string `json:"session_id"` // 前端生成,用于隔离多轮对话
|
||||
}
|
||||
|
||||
// ChatResponse AI 对话响应 // Logan.Li
|
||||
@@ -51,14 +52,15 @@ type ChatResponse struct {
|
||||
TokensUsed int `json:"tokens_used"`
|
||||
}
|
||||
|
||||
// ChatHistory 对话历史记录(按用户隔离) // Logan.Li
|
||||
// ChatHistory 对话历史记录(按用户隔离,session_id 区分多轮对话) // Logan.Li
|
||||
// 仅持久化成功完成的对话(用户消息 + 助手回复成对写入),错误气泡为瞬时 UI 不入库
|
||||
type ChatHistory struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
UserID uint `gorm:"index;not null" json:"user_id"` // 所属用户(JWT 中间件注入)
|
||||
Role string `gorm:"size:16;not null" json:"role"` // user / assistant
|
||||
Content string `gorm:"type:text;not null" json:"content"` // 消息内容
|
||||
Model string `gorm:"size:100" json:"model"` // 生成回复所用模型(仅 assistant 行有意义)
|
||||
UserID uint `gorm:"index;not null" json:"user_id"` // 所属用户(JWT 中间件注入)
|
||||
SessionID string `gorm:"size:64;index;not null;default:''" json:"session_id"` // 对话会话 ID(前端 UUID)
|
||||
Role string `gorm:"size:16;not null" json:"role"` // user / assistant
|
||||
Content string `gorm:"type:text;not null" json:"content"` // 消息内容
|
||||
Model string `gorm:"size:100" json:"model"` // 生成回复所用模型(仅 assistant 行有意义)
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user