130 lines
5.6 KiB
Go
130 lines
5.6 KiB
Go
package model
|
||
|
||
import "time"
|
||
|
||
// ============================================
|
||
// PipelineStage 流水线阶段定义(JSON)
|
||
// ============================================
|
||
|
||
// PipelineStage 一个阶段包含多个任务
|
||
type PipelineStage struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
Type string `json:"type"` // source/build/deploy/test/custom
|
||
Tasks []PipelineTask `json:"tasks"`
|
||
}
|
||
|
||
// PipelineTask 阶段内的任务
|
||
type PipelineTask struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
Type string `json:"type"` // build/deploy/test/custom
|
||
Icon string `json:"icon,omitempty"`
|
||
Config map[string]string `json:"config,omitempty"`
|
||
Script string `json:"script,omitempty"`
|
||
ScriptType string `json:"script_type,omitempty"` // shell/python
|
||
}
|
||
|
||
// ============================================
|
||
// DeployEnvironment 发布环境分组
|
||
// ============================================
|
||
|
||
type EnvironmentType string
|
||
|
||
const (
|
||
EnvProduction EnvironmentType = "production"
|
||
EnvStaging EnvironmentType = "staging"
|
||
EnvTesting EnvironmentType = "testing"
|
||
EnvDev EnvironmentType = "development"
|
||
)
|
||
|
||
// DeployEnvironment 环境分组表(生产/测试/预发布/开发)
|
||
type DeployEnvironment struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
Name string `gorm:"type:varchar(64);not null;uniqueIndex;comment:环境名称" json:"name"`
|
||
DisplayName string `gorm:"type:varchar(128);not null;comment:显示名称" json:"display_name"`
|
||
Type EnvironmentType `gorm:"type:varchar(16);not null;index;comment:环境类型: production/staging/testing/development" json:"type"`
|
||
Color string `gorm:"type:varchar(16);default:'#3B82F6';comment:标识颜色" json:"color"`
|
||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
}
|
||
|
||
func (DeployEnvironment) TableName() string {
|
||
return "deploy_environments"
|
||
}
|
||
|
||
// ============================================
|
||
// DeployPipelineMember 流水线成员
|
||
// ============================================
|
||
|
||
type MemberRole string
|
||
|
||
const (
|
||
MemberOwner MemberRole = "owner" // 拥有者
|
||
MemberEditor MemberRole = "editor" // 编辑者
|
||
MemberViewer MemberRole = "viewer" // 查看者
|
||
)
|
||
|
||
// DeployPipelineMember 流水线成员表
|
||
// 支持两种授权方式:直接用户授权(username 非空)和用户组授权(group_id 非空)
|
||
type DeployPipelineMember struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
PipelineID uint `gorm:"index:idx_pipeline_user,unique,priority:1;index:idx_pipeline_group,unique,priority:1;not null;comment:流水线ID" json:"pipeline_id"`
|
||
Username *string `gorm:"type:varchar(64);index:idx_pipeline_user,unique,priority:2;comment:用户名(直接授权)" json:"username,omitempty"`
|
||
GroupID *uint `gorm:"index:idx_pipeline_group,unique,priority:2;comment:用户组ID(组授权)" json:"group_id,omitempty"`
|
||
Role MemberRole `gorm:"type:varchar(16);default:'editor';comment:角色: owner/editor/viewer" json:"role"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
|
||
// 关联
|
||
Pipeline *Pipeline `json:"pipeline,omitempty" gorm:"foreignKey:PipelineID"`
|
||
Group *DeployUserGroup `json:"group,omitempty" gorm:"foreignKey:GroupID"`
|
||
}
|
||
|
||
func (DeployPipelineMember) TableName() string {
|
||
return "deploy_pipeline_members"
|
||
}
|
||
|
||
// ============================================
|
||
// DeployUserGroup 发布系统用户组
|
||
// ============================================
|
||
|
||
// DeployUserGroup 用户组(用于流水线权限分组授权)
|
||
type DeployUserGroup struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
Name string `gorm:"type:varchar(64);uniqueIndex;not null;comment:组名称" json:"name"`
|
||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
|
||
// 关联
|
||
Members []DeployUserGroupMember `json:"members,omitempty" gorm:"foreignKey:GroupID"`
|
||
}
|
||
|
||
func (DeployUserGroup) TableName() string {
|
||
return "deploy_user_groups"
|
||
}
|
||
|
||
// ============================================
|
||
// DeployUserGroupMember 用户组成员
|
||
// ============================================
|
||
|
||
// DeployUserGroupMember 用户组成员关联表
|
||
type DeployUserGroupMember struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
GroupID uint `gorm:"uniqueIndex:idx_group_user;not null;comment:组ID" json:"group_id"`
|
||
Username string `gorm:"type:varchar(64);uniqueIndex:idx_group_user;not null;comment:用户名" json:"username"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
|
||
// 关联
|
||
Group *DeployUserGroup `json:"group,omitempty" gorm:"foreignKey:GroupID"`
|
||
}
|
||
|
||
func (DeployUserGroupMember) TableName() string {
|
||
return "deploy_user_group_members"
|
||
}
|