feat: 系统升级支持数据库自动迁移,避免手动执行升级脚本

This commit is contained in:
meilin.huang
2025-02-13 21:11:23 +08:00
parent efb2b7368c
commit aa393590b2
78 changed files with 1965 additions and 1827 deletions

View File

@@ -8,11 +8,11 @@ import (
type Oauth2Account struct {
model.DeletedModel
AccountId uint64 `json:"accountId" gorm:"column:account_id;index:account_id,unique"`
Identity string `json:"identity" gorm:"column:identity;index:identity,unique"`
AccountId uint64 `json:"accountId" gorm:"not null;column:account_id;index:account_id,unique;comment:账号ID"`
Identity string `json:"identity" gorm:"size:64;column:identity;index:idx_identity,unique;comment:身份标识"`
CreateTime *time.Time `json:"createTime"`
UpdateTime *time.Time `json:"updateTime"`
CreateTime *time.Time `json:"createTime" gorm:"not null;"`
UpdateTime *time.Time `json:"updateTime" gorm:"not null;"`
}
func (Oauth2Account) TableName() string {

View File

@@ -159,7 +159,7 @@ func (app *dataSyncAppImpl) RunCronJob(ctx context.Context, id uint64) error {
break
}
}
return errorx.NewBiz("get column data type")
return errorx.NewBiz("get column data type... ignore~")
})
updSql = fmt.Sprintf("and %s > %s", task.UpdField, updFieldDataType.DataType.SQLValue(task.UpdFieldVal))
@@ -394,7 +394,7 @@ func (app *dataSyncAppImpl) saveLog(log *entity.DataSyncLog) {
func (app *dataSyncAppImpl) InitCronJob() {
defer func() {
if err := recover(); err != nil {
logx.ErrorTrace("the data synchronization task failed to initialize: %s", err.(error))
logx.ErrorTrace("the data synchronization task failed to initialize", err)
}
}()
@@ -410,7 +410,12 @@ func (app *dataSyncAppImpl) InitCronJob() {
cond.Status = entity.DataSyncTaskStatusEnable
jobs := new([]entity.DataSyncTask)
pr, _ := app.GetPageList(cond, pageParam, jobs)
pr, err := app.GetPageList(cond, pageParam, jobs)
if err != nil {
logx.ErrorTrace("the data synchronization task failed to initialize", err)
return
}
total := pr.Total
add := 0

View File

@@ -7,13 +7,13 @@ import (
type Db struct {
model.Model
Code string `orm:"column(code)" json:"code"`
Name string `orm:"column(name)" json:"name"`
GetDatabaseMode DbGetDatabaseMode `json:"getDatabaseMode"` // 获取数据库方式
Database string `orm:"column(database)" json:"database"`
Remark string `json:"remark"`
InstanceId uint64
AuthCertName string `json:"authCertName"`
Code string `json:"code" gorm:"size:32;not null;index:idx_code"`
Name string `json:"name" gorm:"size:255;not null;"`
GetDatabaseMode DbGetDatabaseMode `json:"getDatabaseMode" gorm:"comment:库名获取方式(-1.实时获取、1.指定库名)"` // 获取数据库方式
Database string `json:"database" gorm:"size:2000;"`
Remark string `json:"remark" gorm:"size:255;"`
InstanceId uint64 `json:"instanceId" gorm:"not null;"`
AuthCertName string `json:"authCertName" gorm:"size:255;"`
}
type DbGetDatabaseMode int8

View File

@@ -5,34 +5,35 @@ import (
"time"
)
// DataSyncTask 数据同步
type DataSyncTask struct {
model.Model
// 基本信息
TaskName string `orm:"column(task_name)" json:"taskName"` // 任务名
TaskCron string `orm:"column(task_cron)" json:"taskCron"` // 任务Cron表达式
Status int8 `orm:"column(status)" json:"status"` // 状态 1启用 2禁用
TaskKey string `orm:"column(key)" json:"taskKey"` // 任务唯一标识
RecentState int8 `orm:"column(recent_state)" json:"recentState"` // 最近执行状态 1成功 -1失败
RunningState int8 `orm:"column(running_state)" json:"runningState"` // 运行时状态 1运行中、2待运行、3已停止
TaskName string `json:"taskName" gorm:"not null;size:255;comment:任务名"` // 任务名
TaskCron string `json:"taskCron" gorm:"not null;size:50;comment:任务Cron表达式"` // 任务Cron表达式
Status int8 `json:"status" gorm:"not null;default:1;comment:状态 1启用 2禁用"` // 状态 1启用 2禁用
TaskKey string `json:"taskKey" gorm:"size:100;comment:任务唯一标识"` // 任务唯一标识
RecentState int8 `json:"recentState" gorm:"not null;default:0;comment:最近执行状态 1成功 -1失败"` // 最近执行状态 1成功 -1失败
RunningState int8 `json:"runningState" gorm:"not null;default:2;comment:运行时状态 1运行中、2待运行、3已停止"` // 运行时状态 1运行中、2待运行、3已停止
// 源数据库信息
SrcDbId int64 `orm:"column(src_db_id)" json:"srcDbId"`
SrcDbName string `orm:"column(src_db_name)" json:"srcDbName"`
SrcTagPath string `orm:"column(src_tag_path)" json:"srcTagPath"`
DataSql string `orm:"column(data_sql)" json:"dataSql"` // 数据源查询sql
PageSize int `orm:"column(page_size)" json:"pageSize"` // 配置分页sql查询的条数
UpdField string `orm:"column(upd_field)" json:"updField"` // 更新字段, 选择由哪个字段为更新字段查询数据源的时候会带上这个字段where update_time > {最近更新的最大值}
UpdFieldVal string `orm:"column(upd_field_val)" json:"updFieldVal"` // 更新字段当前值
UpdFieldSrc string `orm:"column(upd_field_src)" json:"updFieldSrc"` // 更新值来源, 如select name as user_name from user; 则updFieldSrc的值为user_name
SrcDbId int64 `json:"srcDbId" gorm:"not null;comment:源数据库ID"` // 源数据库ID
SrcDbName string `json:"srcDbName" gorm:"size:100;comment:源数据库名"` // 源数据库名
SrcTagPath string `json:"srcTagPath" gorm:"size:200;comment:源数据库tag路径"` // 源数据库tag路径
DataSql string `json:"dataSql" gorm:"not null;type:text;comment:数据查询sql"` // 数据源查询sql
PageSize int `json:"pageSize" gorm:"not null;comment:数据同步分页大小"` // 配置分页sql查询的条数
UpdField string `json:"updField" gorm:"not null;size:100;default:'id';comment:更新字段,默认'id'"` // 更新字段, 选择由哪个字段为更新字段查询数据源的时候会带上这个字段where update_time > {最近更新的最大值}
UpdFieldVal string `json:"updFieldVal" gorm:"size:100;comment:当前更新值"` // 更新字段当前值
UpdFieldSrc string `json:"updFieldSrc" gorm:"comment:更新值来源, 如select name as user_name from user; 则updFieldSrc的值为user_name"` // 更新值来源, 如select name as user_name from user; 则updFieldSrc的值为user_name
// 目标数据库信息
TargetDbId int64 `orm:"column(target_db_id)" json:"targetDbId"`
TargetDbName string `orm:"column(target_db_name)" json:"targetDbName"`
TargetTagPath string `orm:"column(target_tag_path)" json:"targetTagPath"`
TargetTableName string `orm:"column(target_table_name)" json:"targetTableName"`
FieldMap string `orm:"column(field_map)" json:"fieldMap"` // 字段映射json
DuplicateStrategy int `orm:"column(duplicate_strategy)" json:"duplicateStrategy"` // 冲突策略 -11忽略2覆盖
TargetDbId int64 `json:"targetDbId" gorm:"not null;comment:目标数据库ID"` // 目标数据库ID
TargetDbName string `json:"targetDbName" gorm:"size:150;comment:目标数据库名"` // 目标数据库名
TargetTagPath string `json:"targetTagPath" gorm:"size:255;comment:目标数据库tag路径"` // 目标数据库tag路径
TargetTableName string `json:"targetTableName" gorm:"size:150;comment:目标数据库表名"` // 目标数据库表名
FieldMap string `json:"fieldMap" gorm:"type:text;comment:字段映射json"` // 字段映射json
DuplicateStrategy int `json:"duplicateStrategy" gorm:"not null;default:-1;comment:唯一键冲突策略 -11忽略2覆盖"` // 冲突策略 -11忽略2覆盖
}
func (d *DataSyncTask) TableName() string {
@@ -41,12 +42,13 @@ func (d *DataSyncTask) TableName() string {
type DataSyncLog struct {
model.IdModel
TaskId uint64 `orm:"column(task_id)" json:"taskId"` // 任务表id
CreateTime *time.Time `orm:"column(create_time)" json:"createTime"`
DataSqlFull string `orm:"column(data_sql_full)" json:"dataSqlFull"` // 执行的完整sql
ResNum int `orm:"column(res_num)" json:"resNum"` // 收到数据条数
ErrText string `orm:"column(err_text)" json:"errText"` // 错误日志
Status int8 `orm:"column(status)" json:"status"` // 状态:1.成功 -1.失败
CreateTime *time.Time `json:"createTime" gorm:"not null;"` // 创建时间
TaskId uint64 `json:"taskId" gorm:"not null;comment:同步任务表id"` // 任务表id
DataSqlFull string `json:"dataSqlFull" gorm:"not null;type:text;comment:执行的完整sql"` // 执行的完整sql
ResNum int `json:"resNum" gorm:"comment:收到数据条数"` // 收到数据条数
ErrText string `json:"errText" gorm:"type:text;comment:日志"` // 日志
Status int8 `json:"status" gorm:"not null;default:1;comment:状态:1.成功 0.失败"` // 状态:1.成功 0.失败
}
func (d *DataSyncLog) TableName() string {

View File

@@ -5,18 +5,19 @@ import (
"mayfly-go/pkg/model"
)
// DbInstance 数据库实例信息
type DbInstance struct {
model.Model
Code string `json:"code"`
Name string `json:"name"`
Type string `json:"type"` // 类型mysql oracle等
Host string `json:"host"`
Code string `json:"code" gorm:"size:32;not null;"`
Name string `json:"name" gorm:"size:32;not null;"`
Type string `json:"type" gorm:"size:32;not null;"` // 类型mysql oracle等
Host string `json:"host" gorm:"size:255;not null;"`
Port int `json:"port"`
Network string `json:"network"`
Extra *string `json:"extra"` // 连接需要的其他额外参数json格式, 如oracle需要sid等
Params *string `json:"params"` // 使用指针类型,可更新为零值(空字符串)
Remark *string `json:"remark"`
Network string `json:"network" gorm:"size:20;"`
Extra *string `json:"extra" gorm:"size:1000;comment:连接需要的额外参数如oracle数据库需要sid等"` // 连接需要的其他额外参数json格式, 如oracle需要sid等
Params *string `json:"params" gorm:"size:255;comment:其他连接参数"` // 使用指针类型,可更新为零值(空字符串)
Remark *string `json:"remark" gorm:"size:255;"`
SshTunnelMachineId int `json:"sshTunnelMachineId"` // ssh隧道机器id
}

View File

@@ -4,12 +4,13 @@ import (
"mayfly-go/pkg/model"
)
// DbSql 用户保存的数据库sql
type DbSql struct {
model.Model `orm:"-"`
DbId uint64 `json:"dbId"`
Db string `json:"db"`
Type int `json:"type"` // 类型
Sql string `json:"sql"`
Name string `json:"name"`
DbId uint64 `json:"dbId" gorm:"not null;"`
Db string `json:"db" gorm:"size:100;not null;"`
Type int `json:"type" gorm:"not null;"` // 类型
Sql string `json:"sql" gorm:"size:4000;comment:sql语句"`
Name string `json:"name" gorm:"size:255;not null;comment:sql模板名"`
}

View File

@@ -8,17 +8,17 @@ import (
type DbSqlExec struct {
model.Model `orm:"-"`
DbId uint64 `json:"dbId"`
Db string `json:"db"`
Table string `json:"table"`
Type int8 `json:"type"` // 类型
Sql string `json:"sql"` // 执行的sql
OldValue string `json:"oldValue"`
Remark string `json:"remark"`
Status int8 `json:"status"` // 执行状态
Res string `json:"res"` // 执行结果
DbId uint64 `json:"dbId" gorm:"not null;"`
Db string `json:"db" gorm:"size:150;not null;"`
Table string `json:"table" gorm:"size:150;"`
Type int8 `json:"type" gorm:"not null;"` // 类型
Sql string `json:"sql" gorm:"size:5000;not null;"` // 执行的sql
OldValue string `json:"oldValue" gorm:"size:5000;"`
Remark string `json:"remark" gorm:"size:255;"`
Status int8 `json:"status"` // 执行状态
Res string `json:"res" gorm:"size:1000;"` // 执行结果
FlowBizKey string `json:"flowBizKey"` // 流程业务key
FlowBizKey string `json:"flowBizKey" gorm:"size:50;index:idx_flow_biz_key;comment:流程关联的业务key"` // 流程业务key
}
const (

View File

@@ -7,34 +7,33 @@ import (
type DbTransferTask struct {
model.Model
RunningState int8 `orm:"column(running_state)" json:"runningState"` // 运行状态
TaskName string `json:"taskName" gorm:"size:255;not null;"` // 任务名称
TaskKey string `json:"taskKey" gorm:"size:100;not null;"` // 定时任务唯一uuid key
CronAble int8 `json:"cronAble" gorm:"default:-1;not null;"` // 是否定时 1是 -1否
Cron string `json:"cron" gorm:"size:32;"` // 定时任务cron表达式
Mode int8 `json:"mode"` // 数据迁移方式1、迁移到数据库 2、迁移到文件
TargetFileDbType string `json:"targetFileDbType" gorm:"size:32;"` // 目标文件数据库类型
FileSaveDays int `json:"fileSaveDays"` // 文件保存天数
Status int8 `json:"status"` // 启用状态 1启用 -1禁用
RunningState int8 `json:"runningState"` // 运行状态
LogId uint64 `json:"logId"`
TaskName string `orm:"column(task_name)" json:"taskName"` // 任务名称
Status int8 `orm:"column(status)" json:"status"` // 启用状态 1启用 -1禁用
CronAble int8 `orm:"column(cron_able)" json:"cronAble"` // 是否定时 1是 -1否
Cron string `orm:"column(cron)" json:"cron"` // 定时任务cron表达式
Mode int8 `orm:"column(mode)" json:"mode"` // 数据迁移方式1、迁移到数据库 2、迁移到文件
TargetFileDbType string `orm:"column(target_file_db_type)" json:"targetFileDbType"` // 目标文件数据库类型
FileSaveDays int `json:"fileSaveDays"` // 文件保存天数
TaskKey string `orm:"column(key)" json:"taskKey"` // 定时任务唯一uuid key
CheckedKeys string `orm:"column(checked_keys)" json:"checkedKeys"` // 选中需要迁移的表
DeleteTable int `orm:"column(delete_table)" json:"deleteTable"` // 创建表前是否删除表
NameCase int `orm:"column(name_case)" json:"nameCase"` // 表名、字段大小写转换 1无 2大写 3小写
Strategy int `orm:"column(strategy)" json:"strategy"` // 迁移策略 1全量 2增量
CheckedKeys string `json:"checkedKeys" gorm:"type:text;"` // 选中需要迁移的表
DeleteTable int8 `json:"deleteTable"` // 创建表前是否删除表
NameCase int8 `json:"nameCase"` // 表名、字段大小写转换 1无 2大写 3小写
Strategy int8 `json:"strategy"` // 迁移策略 1全量 2增量
SrcDbId int64 `orm:"column(src_db_id)" json:"srcDbId"` // 源库id
SrcDbName string `orm:"column(src_db_name)" json:"srcDbName"` // 源库名
SrcTagPath string `orm:"column(src_tag_path)" json:"srcTagPath"` // 源库tagPath
SrcDbType string `orm:"column(src_db_type)" json:"srcDbType"` // 源库类型
SrcInstName string `orm:"column(src_inst_name)" json:"srcInstName"` // 源库实例名
TargetDbId int `orm:"column(target_db_id)" json:"targetDbId"` // 目标库id
TargetDbName string `orm:"column(target_db_name)" json:"targetDbName"` // 目标库名
TargetDbType string `orm:"column(target_tag_path)" json:"targetDbType"` // 目标库类型
TargetInstName string `orm:"column(target_db_type)" json:"targetInstName"` // 目标库实例名
TargetTagPath string `orm:"column(target_inst_name)" json:"targetTagPath"` // 目标库tagPath
SrcDbId int64 `json:"srcDbId" gorm:"not null;"` // 源库id
SrcDbName string `json:"srcDbName" gorm:"size:255;not null;"` // 源库名
SrcTagPath string `json:"srcTagPath" gorm:"size:255;"` // 源库tagPath
SrcDbType string `json:"srcDbType" gorm:"size:32;not null;"` // 源库类型
SrcInstName string `json:"srcInstName" gorm:"size:255;"` // 源库实例名
TargetDbId int `json:"targetDbId" gorm:"not null;"` // 目标库id
TargetDbName string `json:"targetDbName" gorm:"size:255;not null;"` // 目标库名
TargetDbType string `json:"targetDbType" gorm:"size:32;not null;"` // 目标库类型
TargetInstName string `json:"targetInstName" gorm:"size:255;"` // 目标库实例名
TargetTagPath string `json:"targetTagPath" gorm:"size:255;"` // 目标库tagPath
}
func (d *DbTransferTask) TableName() string {

View File

@@ -5,15 +5,16 @@ import (
"time"
)
// DbTransferFile 数据库迁移文件管理
type DbTransferFile struct {
model.IdModel
IsDeleted int8 `orm:"column(is_deleted)" json:"-"` // 是否删除 1是 0否
CreateTime *time.Time `orm:"column(create_time)" json:"createTime"` // 创建时间,默认当前时间戳
Status int8 `orm:"column(status)" json:"status"` // 状态 1、执行中 2、执行成功 3、执行失败
TaskId uint64 `orm:"column(task_id)" json:"taskId"` // 迁移任务ID
LogId uint64 `orm:"column(log_id)" json:"logId"` // 日志ID
FileDbType string `orm:"column(file_db_type)" json:"fileDbType"` // sql文件数据库类型
FileKey string `orm:"column(file_key)" json:"fileKey"` // 文件
IsDeleted int8 `json:"-" gorm:"default:0;"` // 是否删除 1是 0否
CreateTime *time.Time `json:"createTime"` // 创建时间,默认当前时间戳
Status int8 `json:"status" gorm:"default:1;comment:状态 1、执行中 2、执行成功 3、执行失败"` // 状态 1、执行中 2、执行成功 3、执行失败
TaskId uint64 `json:"taskId" gorm:"comment:迁移任务ID"` // 迁移任务ID
LogId uint64 `json:"logId" gorm:"comment:日志ID"` // 日志ID
FileDbType string `json:"fileDbType" gorm:"size:32;comment:sql文件数据库类型"` // sql文件数据库类型
FileKey string `json:"fileKey" gorm:"size:50;comment:文件"` // 文件
}
func (d *DbTransferFile) TableName() string {

View File

@@ -5,9 +5,9 @@ import "mayfly-go/pkg/model"
type File struct {
model.Model
FileKey string `json:"fikeKey"` // 文件key
Filename string `json:"filename"` // 文件名
Path string `json:"path" ` // 文件路径
FileKey string `json:"fikeKey" gorm:"size:32;not null;"` // 文件key
Filename string `json:"filename" gorm:"size:255;not null;"` // 文件名
Path string `json:"path" gorm:"size:500;"` // 文件路径
Size int64 `json:"size"`
}

View File

@@ -14,12 +14,12 @@ import (
type Procdef struct {
model.Model
Name string `json:"name" form:"name"` // 名称
DefKey string `json:"defKey" form:"defKey"` //
Tasks string `json:"tasks"` // 审批节点任务信息
Status ProcdefStatus `json:"status"` // 状态
Condition *string `json:"condition"` // 触发审批的条件计算结果返回1则需要启用该流程
Remark *string `json:"remark"`
Name string `json:"name" form:"name" gorm:"size:150;comment:流程名称"` // 名称
DefKey string `json:"defKey" form:"defKey" gorm:"not null;size:100;comment:流程定义key"` //
Tasks string `json:"tasks" gorm:"not null;size:3000;comment:审批节点任务信息"` // 审批节点任务信息
Status ProcdefStatus `json:"status" gorm:"comment:状态"` // 状态
Condition *string `json:"condition" gorm:"type:text;comment:触发审批的条件计算结果返回1则需要启用该流程"` // 触发审批的条件计算结果返回1则需要启用该流程
Remark *string `json:"remark" gorm:"size:255;"`
}
func (p *Procdef) TableName() string {

View File

@@ -10,19 +10,19 @@ import (
type Procinst struct {
model.Model
ProcdefId uint64 `json:"procdefId"` // 流程定义id
ProcdefName string `json:"procdefName"` // 流程定义名称
ProcdefId uint64 `json:"procdefId" gorm:"not null;index:idx_procdef_id;comment:流程定义id"` // 流程定义id
ProcdefName string `json:"procdefName" gorm:"not null;size:64;comment:流程定义名称"` // 流程定义名称
BizType string `json:"bizType"` // 业务类型
BizKey string `json:"bizKey"` // 业务key
BizForm string `json:"bizForm"` // 业务表单
BizStatus ProcinstBizStatus `json:"bizStatus"` // 业务状态
BizHandleRes string `json:"bizHandleRes"` // 业务处理结果
TaskKey string `json:"taskKey"` // 当前任务key
Status ProcinstStatus `json:"status"` // 状态
Remark string `json:"remark"`
EndTime *time.Time `json:"endTime"`
Duration int64 `json:"duration"` // 持续时间(开始到结束)
BizType string `json:"bizType" gorm:"not null;size:64;comment:关联业务类型"` // 业务类型
BizKey string `json:"bizKey" gorm:"not null;size:64;comment:关联业务key"` // 业务key
BizForm string `json:"bizForm" gorm:"type:text;comment:业务form"` // 业务表单
BizStatus ProcinstBizStatus `json:"bizStatus" gorm:"comment:业务状态"` // 业务状态
BizHandleRes string `json:"bizHandleRes" gorm:"size:4000;comment:关联的业务处理结果"` // 业务处理结果
TaskKey string `json:"taskKey" gorm:"size:100;comment:当前任务key"` // 当前任务key
Status ProcinstStatus `json:"status" gorm:"comment:状态"` // 状态
Remark string `json:"remark" gorm:"size:255;"`
EndTime *time.Time `json:"endTime" gorm:"comment:结束时间"`
Duration int64 `json:"duration" gorm:"comment:流程持续时间(开始到结束)"` // 持续时间(开始到结束)
}
func (a *Procinst) TableName() string {
@@ -68,15 +68,15 @@ const (
type ProcinstTask struct {
model.Model
ProcinstId uint64 `json:"procinstId"` // 流程实例id
TaskKey string `json:"taskKey"` // 当前任务key
TaskName string `json:"taskName"` // 当前任务名称
Assignee string `json:"assignee"` // 分配到该任务的用户
ProcinstId uint64 `json:"procinstId" gorm:"not null;index:idx_procinst_id;comment:流程实例id"` // 流程实例id
TaskKey string `json:"taskKey" gorm:"not null;size:64;comment:任务key"` // 当前任务key
TaskName string `json:"taskName" gorm:"size:64;comment:任务名称"` // 当前任务名称
Assignee string `json:"assignee" gorm:"size:64;comment:分配到该任务的用户"` // 分配到该任务的用户
Status ProcinstTaskStatus `json:"status"` // 状态
Remark string `json:"remark"`
EndTime *time.Time `json:"endTime"`
Duration int64 `json:"duration"` // 持续时间(开始到结束)
Status ProcinstTaskStatus `json:"status" ` // 状态
Remark string `json:"remark" gorm:"size:255;"`
EndTime *time.Time `json:"endTime" gorm:"comment:结束时间"`
Duration int64 `json:"duration" gorm:"comment:任务持续时间(开始到结束)"` // 持续时间(开始到结束)
}
func (a *ProcinstTask) TableName() string {

View File

@@ -8,15 +8,15 @@ type Machine struct {
model.Model
model.ExtraData
Code string `json:"code"`
Name string `json:"name"`
Protocol int `json:"protocol"` // 连接协议 1.ssh 2.rdp
Ip string `json:"ip"` // IP地址
Port int `json:"port"` // 端口号
Status int8 `json:"status"` // 状态 1:启用2:停用
Remark string `json:"remark"` // 备注
SshTunnelMachineId int `json:"sshTunnelMachineId"` // ssh隧道机器id
EnableRecorder int8 `json:"enableRecorder"` // 是否启用终端回放记录
Code string `json:"code" gorm:"size:32;comment:code"` // code
Name string `json:"name" gorm:"size:32"` // 名称
Protocol int `json:"protocol" gorm:"default:1;comment:连接协议 1.ssh 2.rdp"` // 连接协议 1.ssh 2.rdp
Ip string `json:"ip" gorm:"not null;size:100;comment:IP地址"` // IP地址
Port int `json:"port" gorm:"not null;comment:端口号"` // 端口号
Status int8 `json:"status" gorm:"not null;default:1;comment:状态 1:启用2:停用"` // 状态 1:启用2:停用
Remark string `json:"remark" gorm:"comment:备注"` // 备注
SshTunnelMachineId int `json:"sshTunnelMachineId" gorm:"comment:ssh隧道机器id"` // ssh隧道机器id
EnableRecorder int8 `json:"enableRecorder" gorm:"comment:是否启用终端回放记录"` // 是否启用终端回放记录
}
const (

View File

@@ -4,13 +4,13 @@ import (
"mayfly-go/pkg/model"
)
// 机器命令过滤配置
// MachineCmdConf 机器命令过滤配置
type MachineCmdConf struct {
model.Model
Name string `json:"name"`
Cmds model.Slice[string] `json:"cmds"` // 命令配置
Status int8 `json:"execCmds"` // 状态
Stratege string `json:"stratege"` // 策略,空禁用
Remark string `json:"remark"` // 备注
Name string `json:"name" gorm:"size:100;comment:名称"` // 名称
Cmds model.Slice[string] `json:"cmds" gorm:"type:varchar(500);comment:命令配置"` // 命令配置
Status int8 `json:"status" gorm:"comment:状态"` // 状态
Stratege string `json:"stratege" gorm:"size:100;comment:策略"` // 策略,空禁用
Remark string `json:"remark" gorm:"size:50;comment:备注"` // 备注
}

View File

@@ -9,24 +9,24 @@ import (
type MachineCronJob struct {
model.Model
Name string `json:"name" form:"name"`
Key string `json:"key"`
Cron string `json:"cron"` // cron表达式
Script string `json:"script"` // 任务内容
Status int `json:"status" form:"status"`
Remark string `json:"remark"` // 备注
LastExecTime *time.Time `json:"lastExecTime"`
SaveExecResType int `json:"saveExecResType"` // 记录执行结果类型
Name string `json:"name" form:"name" gorm:"not null;size:255;comment:名称"` // 名称
Key string `json:"key" gorm:"not null;size:32;comment:key"` // key
Cron string `json:"cron" gorm:"not null;size:255;comment:cron表达式"` // cron表达式
Script string `json:"script" gorm:"type:text;comment:脚本内容"` // 任务内容
Status int `json:"status" form:"status" gorm:"comment:状态"` // 状态
Remark string `json:"remark" gorm:"size:255;comment:备注"` // 备注
LastExecTime *time.Time `json:"lastExecTime" gorm:"comment:最后执行时间"` // 最后执行时间
SaveExecResType int `json:"saveExecResType" gorm:"comment:保存执行记录类型"` // 记录执行结果类型
}
// 机器任务执行记录
// MachineCronJobExec 机器任务执行记录
type MachineCronJobExec struct {
model.DeletedModel
CronJobId uint64 `json:"cronJobId" form:"cronJobId"`
MachineCode string `json:"machineCode" form:"machineCode"`
Status int `json:"status" form:"status"` // 执行状态
Res string `json:"res"` // 执行结果
CronJobId uint64 `json:"cronJobId" form:"cronJobId" gorm:"not null;"`
MachineCode string `json:"machineCode" form:"machineCode" gorm:"size:50;"`
Status int `json:"status" form:"status"` // 执行状态
Res string `json:"res" gorm:"size:4000;"` // 执行结果
ExecTime time.Time `json:"execTime"`
}

View File

@@ -5,10 +5,8 @@ import "mayfly-go/pkg/model"
type MachineFile struct {
model.Model
Name string `json:"name"`
// 机器id
MachineId uint64 `json:"machineId"`
Type int `json:"type"`
// 路径
Path string `json:"path"`
Name string `json:"name" gorm:"not null;size:50;comment:机器文件配置linux一切皆文件故也可以表示目录"` // 机器文件配置linux一切皆文件故也可以表示目录
MachineId uint64 `json:"machineId" gorm:"not null;comment:机器id"` // 机器id
Type string `json:"type" gorm:"not null;size:32;comment:1目录2文件"` // 1目录2文件
Path string `json:"path" gorm:"not null;size:150;comment:路径"` // 路径
}

View File

@@ -4,10 +4,11 @@ import "mayfly-go/pkg/model"
type MachineScript struct {
model.Model
Name string `json:"name"`
MachineId uint64 `json:"machineId"` // 机器id
Type int `json:"type"`
Description string `json:"description"` // 脚本描述
Params string `json:"params"` // 参数列表json
Script string `json:"script" gorm:"column:script;type:text"` // 脚本内容
Name string `json:"name" gorm:"not null;size:255;comment:脚本名"` // 脚本名
MachineId uint64 `json:"machineId" gorm:"not null;comment:机器id[0:公共]"` // 机器id
Type int `json:"type" gorm:"comment:脚本类型[1: 有结果2无结果3实时交互]"` // 脚本类型[1: 有结果2无结果3实时交互]
Description string `json:"description" gorm:"size:255;comment:脚本描述"` // 脚本描述
Params string `json:"params" gorm:"size:500;comment:脚本入参"` // 参数列表json
Script string `json:"script" gorm:"type:text;comment:脚本内容"` // 脚本内容
}

View File

@@ -8,13 +8,13 @@ import (
type MachineTermOp struct {
model.DeletedModel
MachineId uint64 `json:"machineId"`
Username string `json:"username"`
FileKey string `json:"fileKey"` // 文件key
ExecCmds string `json:"execCmds"` // 执行的命令
MachineId uint64 `json:"machineId" gorm:"not null;comment:机器id"` // 机器id
Username string `json:"username" gorm:"size:60;comment:登录用户名"` // 登录用户名
FileKey string `json:"fileKey" gorm:"size:36;comment:文件"` // 文件key
ExecCmds string `json:"execCmds" gorm:"type:text;comment:执行的命令记录"` // 执行的命令
CreateTime *time.Time `json:"createTime"`
CreatorId uint64 `json:"creatorId"`
Creator string `json:"creator"`
EndTime *time.Time `json:"endTime"`
CreateTime *time.Time `json:"createTime" gorm:"not null;comment:创建时间"` // 创建时间
CreatorId uint64 `json:"creatorId" gorm:"comment:创建人ID"`
Creator string `json:"creator" gorm:"size:50;comment:创建人"` // 创建人
EndTime *time.Time `json:"endTime" gorm:"comment:结束时间"` // 结束时间
}

View File

@@ -9,10 +9,10 @@ import (
type Mongo struct {
model.Model
Code string `orm:"column(code)" json:"code"`
Name string `orm:"column(name)" json:"name"`
Uri string `orm:"column(uri)" json:"uri"`
SshTunnelMachineId int `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
Code string `json:"code" gorm:"size:32;comment:code"` // code
Name string `json:"name" gorm:"not null;size:50;comment:名称"` // 名称
Uri string `json:"uri" gorm:"not null;size:255;comment:连接uri"` // 连接uri
SshTunnelMachineId int `json:"sshTunnelMachineId" gorm:"comment:ssh隧道的机器id"` // ssh隧道机器id
}
// 转换为mongoInfo进行连接

View File

@@ -10,11 +10,11 @@ type Msg struct {
CreateTime *time.Time `json:"createTime"`
CreatorId uint64 `json:"creatorId"`
Creator string `json:"creator"`
Creator string `json:"creator" gorm:"size:50"`
Type int `json:"type"`
Msg string `json:"msg"`
RecipientId int64 `json:"recipientId"` // 接受者id
Type int8 `json:"type"`
Msg string `json:"msg" gorm:"size:2000"`
RecipientId int64 `json:"recipientId"` // 接收人id-1为所有接收
}
func (a *Msg) TableName() string {

View File

@@ -12,13 +12,13 @@ import (
type Redis struct {
model.Model
Code string `orm:"column(code)" json:"code"`
Name string `orm:"column(name)" json:"name"`
Host string `orm:"column(host)" json:"host"`
Mode string `json:"mode"`
Db string `orm:"column(database)" json:"db"`
SshTunnelMachineId int `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
Remark string
Code string `json:"code" gorm:"size:32;not null;"` // code
Name string `json:"name" gorm:"size:255;not null;"` // 名称
Host string `json:"host" gorm:"size:255;not null;"` // 主机地址
Mode string `json:"mode" gorm:"size:32;"` // 模式
Db string `json:"db" gorm:"size:64;comment:库号: 多个库用,分割"` // 库号: 多个库用,分割
SshTunnelMachineId int `json:"sshTunnelMachineId" gorm:"comment:ssh隧道的机器id"` // ssh隧道机器id
Remark string `json:"remark" gorm:"size:255;"`
}
// ToRedisInfo 转换为redisInfo进行连接

View File

@@ -1,7 +1,7 @@
package form
type ResourceForm struct {
Pid int `json:"pid"`
Pid int64 `json:"pid"`
Id int `json:"id"`
Code string `json:"code" binding:"required"`
Name string `json:"name" binding:"required"`

View File

@@ -11,13 +11,13 @@ import (
type Account struct {
model.Model
Name string `json:"name"`
Username string `json:"username"`
Password string `json:"-"`
Status AccountStatus `json:"status"`
Name string `json:"name" gorm:"size:30;not null;"`
Username string `json:"username" gorm:"size:30;not null;"`
Password string `json:"-" gorm:"size:64;not null;"`
Status AccountStatus `json:"status" gorm:"not null;"`
LastLoginTime *time.Time `json:"lastLoginTime"`
LastLoginIp string `json:"lastLoginIp"`
OtpSecret string `json:"-"`
LastLoginIp string `json:"lastLoginIp" gorm:"size:50;"`
OtpSecret string `json:"-" gorm:"size:100;"`
}
func (a *Account) TableName() string {

View File

@@ -13,12 +13,12 @@ const (
type Config struct {
model.Model
Name string `json:"name"` // 配置名
Key string `json:"key"` // 配置key
Params string `json:"params" gorm:"column:params;type:varchar(1500)"`
Value string `json:"value" gorm:"column:value;type:varchar(1500)"`
Remark string `json:"remark"`
Permission string `json:"permission"` // 可操作该配置的权限
Name string `json:"name" gorm:"size:60;not null;"` // 配置名
Key string `json:"key" gorm:"size:60;not null;"` // 配置key
Params string `json:"params" gorm:"size:1500"`
Value string `json:"value" gorm:"size:1500"`
Remark string `json:"remark" gorm:"size:255"`
Permission string `json:"permission" gorm:"size:255;comment:操作权限"` // 可操作该配置的权限
}
func (a *Config) TableName() string {

View File

@@ -4,14 +4,14 @@ import "mayfly-go/pkg/model"
type Resource struct {
model.Model
Pid int `json:"pid"`
UiPath string `json:"ui_path"` // 唯一标识路径
Type int8 `json:"type"` // 1菜单路由2资源按钮等
Status int8 `json:"status"` // 1可用-1不可用
Code string `json:"code"`
Name string `json:"name"`
Pid int64 `json:"pid" gorm:"not null;comment:父节点id;"`
UiPath string `json:"ui_path" gorm:"size:300;not null;comment:唯一标识路径;"` // 唯一标识路径
Type int8 `json:"type" gorm:"not null;comment:1菜单路由2资源按钮等;"` // 1菜单路由2资源按钮等
Status int8 `json:"status" gorm:"not null;comment:状态1:可用,-1:禁用;"` // 1可用-1不可用
Code string `json:"code" gorm:"size:300;comment:菜单路由为path其他为唯一标识;"`
Name string `json:"name" gorm:"size:255;not null;"`
Weight int `json:"weight"`
Meta string `json:"meta"`
Meta string `json:"meta" gorm:"size:500;"`
}
func (a *Resource) TableName() string {

View File

@@ -12,11 +12,11 @@ const (
type Role struct {
model.Model
Status int `json:"status"` // 1可用-1不可用
Name string `json:"name"`
Remark string `json:"remark"`
Code string `json:"code"`
Type int `json:"type"`
Status int `json:"status" gorm:"not null;"` // 1可用-1不可用
Name string `json:"name" gorm:"size:32;not null;"`
Remark string `json:"remark" gorm:"size:255;not null;"`
Code string `json:"code" gorm:"size:64;not null;"`
Type int8 `json:"type" gorm:"not null;comment:类型1:公共角色2:特殊角色;"`
}
func (a *Role) TableName() string {
@@ -27,11 +27,11 @@ func (a *Role) TableName() string {
type RoleResource struct {
model.DeletedModel
RoleId uint64 `json:"roleId"`
ResourceId uint64 `json:"resourceId"`
CreateTime *time.Time `json:"createTime"`
CreatorId uint64 `json:"creatorId"`
Creator string `json:"creator"`
RoleId uint64 `json:"roleId" gorm:"not null;"`
ResourceId uint64 `json:"resourceId" gorm:"not null;"`
CreateTime *time.Time `json:"createTime" gorm:"not null;"`
CreatorId uint64 `json:"creatorId" gorm:"not null;"`
Creator string `json:"creator" gorm:"size:32;not null;"`
}
func (a *RoleResource) TableName() string {
@@ -42,11 +42,11 @@ func (a *RoleResource) TableName() string {
type AccountRole struct {
model.DeletedModel
AccountId uint64 `json:"accountId"`
RoleId uint64 `json:"roleId"`
CreateTime *time.Time `json:"createTime"`
CreatorId uint64 `json:"creatorId"`
Creator string `json:"creator"`
AccountId uint64 `json:"accountId" gorm:"not null;"`
RoleId uint64 `json:"roleId" gorm:"not null;"`
CreateTime *time.Time `json:"createTime" gorm:"not null;"`
CreatorId uint64 `json:"creatorId" gorm:"not null;"`
Creator string `json:"creator" gorm:"size:32;not null;"`
}
func (a *AccountRole) TableName() string {

View File

@@ -8,11 +8,11 @@ import (
type SysLog struct {
model.CreateModel
Type int8 `json:"type"`
Description string `json:"description"`
ReqParam string `json:"reqParam" gorm:"column:req_param;type:varchar(1000)"` // 请求参数
Resp string `json:"resp" gorm:"column:resp;type:varchar(10000)"` // 响应结构
Extra string `json:"extra"` // 日志额外信息
Type int8 `json:"type" gorm:"not null;"`
Description string `json:"description" gorm:"size:255;"`
ReqParam string `json:"reqParam" gorm:"size:2000"` // 请求参数
Resp string `json:"resp" gorm:"type:text;"` // 响应结构
Extra string `json:"extra" gorm:"type:text;"` // 日志额外信息
}
func (a *SysLog) TableName() string {

View File

@@ -8,7 +8,7 @@ import (
// 授权凭证
type AuthCertForm struct {
Id uint64 `json:"id"`
Name string `json:"name" binding:"required"` // 名称
Name string `json:"name"` // 名称
ResourceCode string `json:"resourceCode"` // 资源编号
ResourceType int8 `json:"resourceType"` // 资源类型
Username string `json:"username"` // 用户名

View File

@@ -96,7 +96,7 @@ func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *dt
// 密文加密
if err := resourceAuthCert.CiphertextEncrypt(); err != nil {
return errorx.NewBiz(err.Error())
return err
}
}
@@ -309,9 +309,14 @@ func (r *resourceAuthCertAppImpl) FillAuthCert(resourceType int8, resources ...e
// addAuthCert 添加授权凭证
func (r *resourceAuthCertAppImpl) addAuthCert(ctx context.Context, rac *entity.ResourceAuthCert) error {
if r.CountByCond(&entity.ResourceAuthCert{Name: rac.Name}) > 0 {
return errorx.NewBizI(ctx, imsg.ErrAcNameExist, "acName", rac.Name)
if rac.Name == "" {
rac.Name = stringx.Rand(10)
} else {
if r.CountByCond(&entity.ResourceAuthCert{Name: rac.Name}) > 0 {
return errorx.NewBizI(ctx, imsg.ErrAcNameExist, "acName", rac.Name)
}
}
// 公共凭证
if rac.Type == entity.AuthCertTypePublic {
rac.ResourceCode = "-"

View File

@@ -15,15 +15,15 @@ type ResourceAuthCert struct {
model.Model
model.ExtraData
Name string `json:"name"` // 名称(全局唯一)
Name string `json:"name" gorm:"size:50;comment:账号名称"` // 名称(全局唯一)
ResourceCode string `json:"resourceCode"` // 资源编号
ResourceType int8 `json:"resourceType"` // 资源类型
Type AuthCertType `json:"type"` // 凭证类型
Username string `json:"username"` // 用户名
Ciphertext string `json:"ciphertext"` // 密文
CiphertextType AuthCertCiphertextType `json:"ciphertextType"` // 密文类型
Remark string `json:"remark"` // 备注
ResourceCode string `json:"resourceCode" gorm:"size:36;comment:资源编码"` // 资源编号
ResourceType int8 `json:"resourceType" gorm:"not null;comment:资源类型"` // 资源类型
Type AuthCertType `json:"type" gorm:"comment:凭证类型"` // 凭证类型
Username string `json:"username" gorm:"size:100;comment:用户名"` // 用户名
Ciphertext string `json:"ciphertext" gorm:"size:5000;comment:密文内容"` // 密文
CiphertextType AuthCertCiphertextType `json:"ciphertextType" gorm:"not null;comment:密文类型(-1.公共授权凭证 1.密码 2.秘钥)"` // 密文类型
Remark string `json:"remark" gorm:"size:255;comment:备注"` // 备注
}
// CiphertextEncrypt 密文加密

View File

@@ -6,7 +6,7 @@ import "mayfly-go/pkg/model"
type ResourceOpLog struct {
model.CreateModel
CodePath string `json:"codePath"` // 标签路径
ResourceCode string `json:"resourceCode"` // 资源编号
ResourceType int8 `json:"relateType"` // 资源类型
CodePath string `json:"codePath" gorm:"size:255;not null;"` // 标签路径
ResourceCode string `json:"resourceCode" gorm:"size:50;not null;"` // 资源编号
ResourceType int8 `json:"relateType" gorm:"not null;"` // 资源类型
}

View File

@@ -14,11 +14,11 @@ import (
type TagTree struct {
model.Model
Type TagType `json:"type"` // 类型: -1.普通标签; 其他值则为对应的资源类型
Code string `json:"code"` // 标识编码, 若类型不为-1则为对应资源编码
CodePath string `json:"codePath"` // 标识路径tag1/tag2/tagType1|tagCode/tagType2|yyycode/,非普通标签类型段含有标签类型
Name string `json:"name"` // 名称
Remark string `json:"remark"` // 备注说明
Type TagType `json:"type" gorm:"not null;default:-1;comment:类型: -1.普通标签; 1机器 2db 3redis 4mongo"` // 类型: -1.普通标签; 其他值则为对应的资源类型
Code string `json:"code" gorm:"not null;size:50;comment:标识符"` // 标识编码, 若类型不为-1则为对应资源编码
CodePath string `json:"codePath" gorm:"not null;size:800;comment:标识符路径"` // 标识路径tag1/tag2/tagType1|tagCode/tagType2|yyycode/,非普通标签类型段含有标签类型
Name string `json:"name" gorm:"size:50;comment:名称"` // 名称
Remark string `json:"remark" gorm:"size:255;"` // 备注说明
}
type TagType int8

View File

@@ -6,9 +6,9 @@ import "mayfly-go/pkg/model"
type TagTreeRelate struct {
model.Model
TagId uint64 `json:"tagId"`
RelateId uint64 `json:"relateId"` // 关联的id
RelateType TagRelateType `json:"relateType"` // 关联的类型
TagId uint64 `json:"tagId" gorm:"not null;index:idx_tag_id;comment:标签树id"` // 标签树id
RelateId uint64 `json:"relateId" gorm:"not null;comment:关联的资源id"` // 关联的资源id
RelateType TagRelateType `json:"relateType" gorm:"not null;comment:关联类型"` // 关联的类型
}
type TagRelateType int8

View File

@@ -8,8 +8,8 @@ import (
type Team struct {
model.Model
Name string `json:"name"` // 名称
ValidityStartDate *model.JsonTime `json:"validityStartDate"` // 生效开始时间
ValidityEndDate *model.JsonTime `json:"validityEndDate"` // 生效结束时间
Remark string `json:"remark"` // 备注说明
Name string `json:"name" gorm:"not null;size:36;comment:名称"` // 名称
ValidityStartDate *model.JsonTime `json:"validityStartDate" gorm:"comment:生效开始时间"` // 生效开始时间
ValidityEndDate *model.JsonTime `json:"validityEndDate" gorm:"comment:生效结束时间"` // 生效结束时间
Remark string `json:"remark" gorm:"size:255;"` // 备注说明
}

View File

@@ -6,7 +6,7 @@ import "mayfly-go/pkg/model"
type TeamMember struct {
model.Model
TeamId uint64 `json:"teamId"`
AccountId uint64 `json:"accountId"`
Username string `json:"username"`
TeamId uint64 `json:"teamId" gorm:"not null;"`
AccountId uint64 `json:"accountId" gorm:"not null;"`
Username string `json:"username" gorm:"size:50;not null;"`
}