package model import "time" // User 系统用户 type User struct { ID uint `gorm:"primaryKey" json:"id"` Username string `gorm:"uniqueIndex" json:"username"` Password string `json:"-"` // argon2id 哈希,绝不返回给前端 Nickname string `json:"nickname"` Role string `gorm:"default:user" json:"role"` // admin | user CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } // Pipeline 流水线定义 type Pipeline struct { ID uint `gorm:"primaryKey" json:"id"` Name string `gorm:"index" json:"name"` Description string `json:"description"` Type string `gorm:"default:native" json:"type"` // native | jenkins | tekton SourceRepo string `json:"sourceRepo"` SourceBranch string `gorm:"default:main" json:"sourceBranch"` GitopsRepo string `json:"gitopsRepo"` GitopsPath string `json:"gitopsPath"` DeployType string `gorm:"default:host" json:"deployType"` // host | k8s | gitops Env string `gorm:"default:staging" json:"env"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } // PipelineNode 画布节点(JSON 字段名与前端 React Flow 对齐) type PipelineNode struct { ID uint `gorm:"primaryKey" json:"dbId"` PipelineID uint `gorm:"index" json:"pipelineId"` NodeID string `gorm:"index" json:"nodeId"` Type string `json:"type"` Name string `json:"name"` PositionX float64 `json:"positionX"` PositionY float64 `json:"positionY"` Width float64 `json:"width"` Height float64 `json:"height"` Category string `json:"category"` // source|build|test|security|deploy|gitops|custom Config map[string]interface{} `gorm:"serializer:json" json:"config"` } // PipelineEdge 画布连线 type PipelineEdge struct { ID uint `gorm:"primaryKey" json:"dbId"` PipelineID uint `gorm:"index" json:"pipelineId"` EdgeID string `gorm:"index" json:"edgeId"` Source string `json:"source"` Target string `json:"target"` Label string `json:"label"` Animated bool `json:"animated"` } // PipelineRun 一次流水线运行 type PipelineRun struct { ID uint `gorm:"primaryKey" json:"id"` RunID string `gorm:"uniqueIndex" json:"runId"` // pr- PipelineID uint `gorm:"index" json:"pipelineId"` PipelineName string `json:"pipelineName"` Branch string `gorm:"default:main" json:"branch"` Env string `gorm:"default:staging" json:"env"` DeployType string `gorm:"default:host" json:"deployType"` Type string `gorm:"default:native" json:"type"` TriggerBy string `gorm:"default:system" json:"triggerBy"` TriggerType string `gorm:"default:manual" json:"triggerType"` // manual|webhook|cron|batch Status string `gorm:"default:pending" json:"status"` // pending|running|success|failed|cancelled DurationMs int64 `json:"durationMs"` NodesSnapshot string `json:"nodesSnapshot"` EdgesSnapshot string `json:"edgesSnapshot"` StartedAt time.Time `json:"startedAt"` CompletedAt *time.Time `json:"completedAt"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } // RunStage 运行中的阶段(对应一个节点) type RunStage struct { ID uint `gorm:"primaryKey" json:"id"` RunID uint `gorm:"index" json:"runId"` NodeID string `json:"nodeId"` Name string `json:"name"` PodName string `json:"podName"` Status string `gorm:"default:pending" json:"status"` // pending|running|success|failed|skipped ExitCode *int `json:"exitCode"` StartedAt *time.Time `json:"startedAt"` CompletedAt *time.Time `json:"completedAt"` } // LogEntry 运行日志 type LogEntry struct { ID uint `gorm:"primaryKey" json:"id"` RunID uint `gorm:"index" json:"runId"` StageID uint `json:"stageId"` Level string `gorm:"default:info" json:"level"` // debug|info|warn|error Message string `json:"message"` Source string `gorm:"default:runner" json:"source"` Timestamp time.Time `json:"timestamp"` } // Application GitOps 应用 type Application struct { ID uint `gorm:"primaryKey" json:"id"` Name string `gorm:"uniqueIndex" json:"name"` Repo string `json:"repo"` Branch string `gorm:"default:main" json:"branch"` Path string `json:"path"` Cluster string `gorm:"default:default" json:"cluster"` Namespace string `gorm:"default:default" json:"namespace"` ManifestType string `gorm:"default:plain" json:"manifestType"` // helm|kustomize|plain SyncPolicy string `gorm:"default:manual" json:"syncPolicy"` // manual|automated AutoPrune bool `json:"autoPrune"` SelfHeal bool `json:"selfHeal"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } // Plugin 插件 type Plugin struct { ID uint `gorm:"primaryKey" json:"id"` PluginID string `gorm:"uniqueIndex" json:"pluginId"` Name string `json:"name"` Description string `json:"description"` Version string `json:"version"` Author string `json:"author"` Category string `gorm:"default:general" json:"category"` EntryPath string `json:"entryPath"` Installed bool `gorm:"default:true" json:"installed"` Enabled bool `gorm:"default:true" json:"enabled"` Config map[string]interface{} `gorm:"serializer:json" json:"config"` CreatedAt time.Time `json:"createdAt"` }