model

package
v1.2203.0-pre3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2022 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

base.go file contains : - public function of Models; - public const variables.

Index

Constants

View Source
const (

	// used by Model:
	// User, UserGroup
	Enabled  = 0
	Disabled = 1
)
View Source
const (

	// Workflow:工单 20000-29999
	// NOTE: 用户默认可以查看自己创建的工单,无需定义此项动作权限
	OP_WORKFLOW_VIEW_OTHERS = 20100
	OP_WORKFLOW_SAVE        = 20200 // including "CREATE" and "UPDATE"

)
View Source
const (
	SQLWhitelistExactMatch = "exact_match"
	SQLWhitelistFPMatch    = "fp_match"
)
View Source
const (
	TaskStatusInit             = "initialized"
	TaskStatusAudited          = "audited"
	TaskStatusExecuting        = "executing"
	TaskStatusExecuteSucceeded = "exec_succeeded"
	TaskStatusExecuteFailed    = "exec_failed"
)
View Source
const (
	TaskSQLSourceFromFormData       = "form_data"
	TaskSQLSourceFromSQLFile        = "sql_file"
	TaskSQLSourceFromMyBatisXMLFile = "mybatis_xml_file"
	TaskSQLSourceFromAuditPlan      = "audit_plan"
)
View Source
const (
	SQLAuditStatusInitialized = "initialized"
	SQLAuditStatusDoing       = "doing"
	SQLAuditStatusFinished    = "finished"
)
View Source
const (
	SQLExecuteStatusInitialized = "initialized"
	SQLExecuteStatusDoing       = "doing"
	SQLExecuteStatusFailed      = "failed"
	SQLExecuteStatusSucceeded   = "succeeded"
)
View Source
const (
	WorkflowStepTypeSQLReview      = "sql_review"
	WorkflowStepTypeSQLExecute     = "sql_execute"
	WorkflowStepTypeCreateWorkflow = "create_workflow"
	WorkflowStepTypeUpdateWorkflow = "update_workflow"
)
View Source
const (
	WorkflowStatusRunning       = "on_process"
	WorkflowStatusReject        = "rejected"
	WorkflowStatusCancel        = "canceled"
	WorkflowStatusExecScheduled = "exec_scheduled"
	WorkflowStatusExecuting     = "executing"
	WorkflowStatusExecFailed    = "exec_failed"
	WorkflowStatusFinish        = "finished"
)
View Source
const (
	WorkflowStepStateInit    = "initialized"
	WorkflowStepStateApprove = "approved"
	WorkflowStepStateReject  = "rejected"
)
View Source
const (
	DefaultAdminUser = "admin"
)
View Source
const (
	SystemVariableWorkflowExpiredHours = "system_variable_workflow_expired_hours"
)
View Source
const TaskExecResultOK = "OK"

Variables

View Source
var DefaultWorkflowTemplate = "default"
View Source
var MockTime, _ = time.Parse("0000-00-00 00:00:00.0000000", "0000-00-00 00:00:00.0000000")

Functions

func CheckIfOperationCodeValid added in v1.2202.0

func CheckIfOperationCodeValid(opCodes []uint) (err error)

func ConvertRuleToDriverRule added in v1.2112.0

func ConvertRuleToDriverRule(r *Rule) *driver.Rule

func GetConfigurableOperationCodeList added in v1.2202.0

func GetConfigurableOperationCodeList() []uint

func GetDb

func GetDb() *gorm.DB

func GetOperationCodeDesc added in v1.2202.0

func GetOperationCodeDesc(opCode uint) string

func GetRoleIDsFromRoles added in v1.2202.0

func GetRoleIDsFromRoles(roles []*Role) (roleIDs []uint)

func GetRuleMapFromAllArray

func GetRuleMapFromAllArray(allRules ...[]Rule) map[string]Rule

func GetSqlxDb

func GetSqlxDb() *sqlx.DB

func InitMockStorage

func InitMockStorage(db *sql.DB)

func InitStorage

func InitStorage(s *Storage)

func IsDefaultAdminUser added in v1.2202.0

func IsDefaultAdminUser(user string) bool

func IsValidOperationCode added in v1.2202.0

func IsValidOperationCode(opCode uint) bool

func UpdateStorage

func UpdateStorage(newStorage *Storage)

Types

type AuditPlan

type AuditPlan struct {
	Model
	Name             string `json:"name" gorm:"not null;index"`
	CronExpression   string `json:"cron_expression" gorm:"not null"`
	DBType           string `json:"db_type" gorm:"not null"`
	Token            string `json:"token" gorm:"not null"`
	InstanceName     string `json:"instance_name"`
	CreateUserID     uint
	InstanceDatabase string        `json:"instance_database"`
	Type             string        `json:"type"`
	Params           params.Params `json:"params" gorm:"type:varchar(1000)"`

	CreateUser    *User             `gorm:"foreignkey:CreateUserId"`
	Instance      *Instance         `gorm:"foreignkey:InstanceName;association_foreignkey:Name"`
	AuditPlanSQLs []*AuditPlanSQLV2 `gorm:"foreignkey:AuditPlanID"`
}

type AuditPlanListDetail

type AuditPlanListDetail struct {
	Name             string         `json:"name"`
	Cron             string         `json:"cron_expression"`
	DBType           string         `json:"db_type"`
	Token            string         `json:"token"`
	InstanceName     string         `json:"instance_name"`
	InstanceDatabase string         `json:"instance_database"`
	Type             sql.NullString `json:"type"`
	Params           params.Params  `json:"params"`
}

type AuditPlanReportListDetail

type AuditPlanReportListDetail struct {
	ID         string          `json:"id"`
	AuditLevel sql.NullString  `json:"audit_level"`
	Score      sql.NullInt32   `json:"score"`
	PassRate   sql.NullFloat64 `json:"pass_rate"`
	CreateAt   string          `json:"created_at"`
}

type AuditPlanReportSQLListDetail

type AuditPlanReportSQLListDetail struct {
	SQL         string `json:"sql"`
	AuditResult string `json:"audit_result"`
}

type AuditPlanReportSQLV2 added in v1.2202.0

type AuditPlanReportSQLV2 struct {
	Model
	AuditPlanReportID uint   `json:"audit_plan_report_id" gorm:"index"`
	SQL               string `json:"sql" gorm:"type:text;not null"`
	AuditResult       string `json:"audit_result" gorm:"type:text"`

	AuditPlanReport *AuditPlanReportV2 `gorm:"foreignkey:AuditPlanReportID"`
}

func (AuditPlanReportSQLV2) TableName added in v1.2202.0

func (a AuditPlanReportSQLV2) TableName() string

type AuditPlanReportV2 added in v1.2202.0

type AuditPlanReportV2 struct {
	Model
	AuditPlanID uint `json:"audit_plan_id" gorm:"index"`

	AuditPlan           *AuditPlan              `gorm:"foreignkey:AuditPlanID"`
	AuditPlanReportSQLs []*AuditPlanReportSQLV2 `gorm:"foreignkey:AuditPlanReportID"`
	PassRate            float64                 `json:"pass_rate"`
	Score               int32                   `json:"score"`
	AuditLevel          string                  `json:"audit_level"`
}

func (AuditPlanReportV2) TableName added in v1.2202.0

func (a AuditPlanReportV2) TableName() string

type AuditPlanSQLListDetail

type AuditPlanSQLListDetail struct {
	Fingerprint string `json:"fingerprint"`
	SQLContent  string `json:"sql_content"`
	Info        JSON   `json:"info"`
}

type AuditPlanSQLV2 added in v1.2202.0

type AuditPlanSQLV2 struct {
	Model

	// add unique index on fingerprint and audit_plan_id
	// it's done by AutoMigrate() because gorm can't create index on TEXT column directly by tag.
	AuditPlanID uint   `json:"audit_plan_id" gorm:"not null"`
	Fingerprint string `json:"fingerprint" gorm:"type:text;not null"`
	SQLContent  string `json:"sql" gorm:"type:text;not null"`
	Info        JSON   `gorm:"type:json"`
}

func (AuditPlanSQLV2) TableName added in v1.2202.0

func (a AuditPlanSQLV2) TableName() string

type BaseSQL

type BaseSQL struct {
	Model
	TaskId uint `json:"-" gorm:"index"`
	Number uint `json:"number"`

	// Content store single SQL or batch SQLs
	//
	// Content may store batch SQLs When BaseSQL embed to RollbackSQL.
	// Split Content to single SQL before execute RollbackSQL.
	Content         string `json:"sql" gorm:"type:text"`
	Description     string `json:"description" gorm:"type:text"`
	StartBinlogFile string `json:"start_binlog_file"`
	StartBinlogPos  int64  `json:"start_binlog_pos"`
	EndBinlogFile   string `json:"end_binlog_file"`
	EndBinlogPos    int64  `json:"end_binlog_pos"`
	RowAffects      int64  `json:"row_affects"`
	ExecStatus      string `json:"exec_status" gorm:"default:\"initialized\""`
	ExecResult      string `json:"exec_result" gorm:"type:text"`
}

func (*BaseSQL) GetExecStatusDesc

func (s *BaseSQL) GetExecStatusDesc() string

type ExecuteSQL

type ExecuteSQL struct {
	BaseSQL
	AuditStatus string `json:"audit_status" gorm:"default:\"initialized\""`
	AuditResult string `json:"audit_result" gorm:"type:text"`
	// AuditFingerprint generate from SQL and SQL audit result use MD5 hash algorithm,
	// it used for deduplication in one audit task.
	AuditFingerprint string `json:"audit_fingerprint" gorm:"index;type:char(32)"`
	// AuditLevel has four level: error, warn, notice, normal.
	AuditLevel string `json:"audit_level"`
}

func (*ExecuteSQL) GetAuditResultDesc

func (s *ExecuteSQL) GetAuditResultDesc() string

func (*ExecuteSQL) GetAuditStatusDesc

func (s *ExecuteSQL) GetAuditStatusDesc() string

func (ExecuteSQL) TableName

func (s ExecuteSQL) TableName() string

type Instance

type Instance struct {
	Model
	// has created composite index: [id, name] by gorm#AddIndex
	Name               string        `json:"name" gorm:"not null;index" example:""`
	DbType             string        `json:"db_type" gorm:"column:db_type; not null" example:"mysql"`
	Host               string        `json:"host" gorm:"column:db_host; not null" example:"10.10.10.10"`
	Port               string        `json:"port" gorm:"column:db_port; not null" example:"3306"`
	User               string        `json:"user" gorm:"column:db_user; not null" example:"root"`
	Password           string        `json:"-" gorm:"-"`
	SecretPassword     string        `json:"secret_password" gorm:"column:db_password; not null"`
	Desc               string        `json:"desc" example:"this is a instance"`
	WorkflowTemplateId uint          `json:"workflow_template_id"`
	AdditionalParams   params.Params `json:"additional_params" gorm:"type:text"`
	MaintenancePeriod  Periods       `json:"maintenance_period" gorm:"type:text"`

	// relation table
	Roles            []*Role           `json:"-" gorm:"many2many:instance_role;"`
	RuleTemplates    []RuleTemplate    `json:"-" gorm:"many2many:instance_rule_template"`
	WorkflowTemplate *WorkflowTemplate `gorm:"foreignkey:WorkflowTemplateId"`
}

Instance is a table for database info

func (*Instance) AfterFind

func (i *Instance) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*Instance) BeforeSave

func (i *Instance) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

type InstanceDetail

type InstanceDetail struct {
	Name                 string         `json:"name"`
	Desc                 string         `json:"desc"`
	Host                 string         `json:"db_host"`
	Port                 string         `json:"db_port"`
	User                 string         `json:"db_user"`
	MaintenancePeriod    Periods        `json:"maintenance_period" gorm:"text"`
	WorkflowTemplateName sql.NullString `json:"workflow_template_name"`
	RoleNames            RowList        `json:"role_names"`
	RuleTemplateNames    RowList        `json:"rule_template_names"`
}

type JSON added in v1.2202.0

type JSON json.RawMessage

func (*JSON) Scan added in v1.2202.0

func (j *JSON) Scan(value interface{}) error

Scan impl sql.Scanner interface

func (JSON) Value added in v1.2202.0

func (j JSON) Value() (sqlDriver.Value, error)

Value impl sql.driver.Valuer interface

type LDAPConfiguration added in v1.2111.0

type LDAPConfiguration struct {
	Model
	// whether the ldap is enabled
	Enable bool `json:"enable" gorm:"not null"`
	// ldap server's ip
	Host string `json:"host" gorm:"not null"`
	// ldap server's port
	Port string `json:"port" gorm:"not null"`
	// the DN of the ldap administrative user for verification
	ConnectDn string `json:"connect_dn" gorm:"not null"`
	// the password of the ldap administrative user for verification
	ConnectPassword string `json:"-" gorm:"-"`
	// the secret password of the ldap administrative user for verification
	ConnectSecretPassword string `json:"connect_secret_password" gorm:"not null"`
	// base dn used for ldap verification
	BaseDn string `json:"base_dn" gorm:"not null"`
	// the key corresponding to the user name in ldap
	UserNameRdnKey string `json:"ldap_user_name_rdn_key" gorm:"not null"`
	// the key corresponding to the user email in ldap
	UserEmailRdnKey string `json:"ldap_user_email_rdn_key" gorm:"not null"`
}

LDAPConfiguration store ldap server configuration.

func (*LDAPConfiguration) AfterFind added in v1.2111.0

func (i *LDAPConfiguration) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*LDAPConfiguration) BeforeSave added in v1.2111.0

func (i *LDAPConfiguration) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

func (*LDAPConfiguration) TableName added in v1.2111.0

func (i *LDAPConfiguration) TableName() string

type License added in v1.2203.0

type License struct {
	Model
	Content string `json:"content" gorm:"type:text;"`
}

func (*License) TableName added in v1.2203.0

func (l *License) TableName() string

type Model

type Model struct {
	ID        uint       `json:"id" gorm:"primary_key" example:"1"`
	CreatedAt time.Time  `json:"created_at" gorm:"default:current_timestamp" example:"2018-10-21T16:40:23+08:00"`
	UpdatedAt time.Time  `json:"updated_at" gorm:"default:current_timestamp on update current_timestamp" example:"2018-10-21T16:40:23+08:00"`
	DeletedAt *time.Time `json:"-" sql:"index"`
}

type Period added in v1.2203.0

type Period struct {
	StartHour   int `json:"start_hour"`
	StartMinute int `json:"start_minute"`
	EndHour     int `json:"end_hour"`
	EndMinute   int `json:"end_minute"`
}

type Periods added in v1.2203.0

type Periods []*Period

func (*Periods) Copy added in v1.2203.0

func (r *Periods) Copy() Periods

func (*Periods) IsWithinScope added in v1.2203.0

func (r *Periods) IsWithinScope(executeTime time.Time) bool

func (*Periods) Scan added in v1.2203.0

func (r *Periods) Scan(value interface{}) error

Scan impl sql.Scanner interface

func (*Periods) SelfCheck added in v1.2203.0

func (r *Periods) SelfCheck() bool

func (Periods) Value added in v1.2203.0

func (r Periods) Value() (driver.Value, error)

Value impl sql.driver.Valuer interface

type Role

type Role struct {
	Model
	Name       string `gorm:"index"`
	Desc       string
	Stat       uint         `json:"stat" gorm:"not null; default: 0; comment:'0:正常 1:被禁用'"`
	Users      []*User      `gorm:"many2many:user_role;"`
	Instances  []*Instance  `gorm:"many2many:instance_role; comment:'关联实例'"`
	UserGroups []*UserGroup `gorm:"many2many:user_group_roles; comment:'关联用户组'"`
}

NOTE: related model: - RoleOperation

type RoleDetail

type RoleDetail struct {
	Id            int
	Name          string  `json:"name"`
	Desc          string  `json:"desc"`
	UserNames     RowList `json:"user_names"`
	InstanceNames RowList `json:"instance_names"`

	// New fields: Stat, UserGroupNames, OperationsCodes
	// Issue: https://github.com/actiontech/sqle/issues/228
	// Version: >= sqle-v1.2202.0
	Stat            int     `json:"stat"`
	UserGroupNames  RowList `json:"user_group_names"`
	OperationsCodes RowList `json:"operations_codes"`
}

func (*RoleDetail) IsDisabled added in v1.2202.0

func (rd *RoleDetail) IsDisabled() bool

type RoleOperation added in v1.2202.0

type RoleOperation struct {
	Model
	RoleID uint `json:"role_id" gorm:"index"`
	Code   uint `json:"op_code" gorm:"column:op_code; comment:'动作权限'"`
}

NOTE: related model: - model.Role

type RollbackSQL

type RollbackSQL struct {
	BaseSQL
	ExecuteSQLId uint `gorm:"index;column:execute_sql_id"`
}

func (RollbackSQL) TableName

func (s RollbackSQL) TableName() string

type RowList

type RowList []string

func (*RowList) ForceConvertIntSlice added in v1.2202.0

func (rl *RowList) ForceConvertIntSlice() []uint

func (*RowList) Scan

func (r *RowList) Scan(src interface{}) error

type Rule

type Rule struct {
	Name   string        `json:"name" gorm:"primary_key; not null"`
	DBType string        `json:"db_type" gorm:"primary_key; not null; default:\"mysql\""`
	Desc   string        `json:"desc"`
	Level  string        `json:"level" example:"error"` // notice, warn, error
	Typ    string        `json:"type" gorm:"column:type; not null"`
	Params params.Params `json:"params" gorm:"type:varchar(1000)"`
}

func GenerateRuleByDriverRule added in v1.2112.0

func GenerateRuleByDriverRule(dr *driver.Rule, dbType string) *Rule

func (Rule) TableName

func (r Rule) TableName() string

type RuleTemplate

type RuleTemplate struct {
	Model
	Name      string             `json:"name"`
	Desc      string             `json:"desc"`
	DBType    string             `json:"db_type"`
	Instances []Instance         `json:"instance_list" gorm:"many2many:instance_rule_template"`
	RuleList  []RuleTemplateRule `json:"rule_list" gorm:"foreignkey:rule_template_id;association_foreignkey:id"`
}

type RuleTemplateDetail

type RuleTemplateDetail struct {
	Name          string  `json:"name"`
	Desc          string  `json:"desc"`
	DBType        string  `json:"db_type"`
	RuleNames     RowList `json:"rule_names"`
	InstanceNames RowList `json:"instance_names"`
}

type RuleTemplateRule

type RuleTemplateRule struct {
	RuleTemplateId uint          `json:"rule_template_id" gorm:"primary_key;auto_increment:false;"`
	RuleName       string        `json:"name" gorm:"primary_key;"`
	RuleLevel      string        `json:"level" gorm:"column:level;"`
	RuleParams     params.Params `json:"value" gorm:"column:rule_params;type:varchar(1000)"`

	Rule *Rule `json:"-" gorm:"foreignkey:Name,DBType;association_foreignkey:RuleName,RuleDBType"`
}

func NewRuleTemplateRule

func NewRuleTemplateRule(t *RuleTemplate, r *Rule) RuleTemplateRule

func (*RuleTemplateRule) GetRule added in v1.2112.0

func (rtr *RuleTemplateRule) GetRule() *Rule

func (*RuleTemplateRule) TableName

func (rtr *RuleTemplateRule) TableName() string

type SMTPConfiguration

type SMTPConfiguration struct {
	Model
	Host           string `json:"smtp_host" gorm:"column:smtp_host; not null"`
	Port           string `json:"smtp_port" gorm:"column:smtp_port; not null"`
	Username       string `json:"smtp_username" gorm:"column:smtp_username; not null"`
	Password       string `json:"-"`
	SecretPassword string `json:"secret_smtp_password" gorm:"column:secret_smtp_password; not null"`
}

SMTPConfiguration store SMTP server configuration.

func (*SMTPConfiguration) AfterFind

func (i *SMTPConfiguration) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db.

func (*SMTPConfiguration) BeforeSave

func (i *SMTPConfiguration) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create.

func (*SMTPConfiguration) TableName

func (i *SMTPConfiguration) TableName() string

type SqlWhitelist

type SqlWhitelist struct {
	Model
	// Value store SQL text.
	Value            string `json:"value" gorm:"not null;type:text"`
	CapitalizedValue string `json:"-" gorm:"-"`
	Desc             string `json:"desc"`
	// MessageDigest deprecated after 1.1.0, keep it for compatibility.
	MessageDigest string `json:"message_digest" gorm:"type:char(32) not null comment 'md5 data';" `
	MatchType     string `json:"match_type" gorm:"default:\"exact_match\""`
}

func (*SqlWhitelist) AfterFind

func (s *SqlWhitelist) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*SqlWhitelist) BeforeSave

func (s *SqlWhitelist) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

func (SqlWhitelist) TableName

func (s SqlWhitelist) TableName() string

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func GetStorage

func GetStorage() *Storage

func NewStorage

func NewStorage(user, password, host, port, schema string, debug bool) (*Storage, error)

func (*Storage) AutoMigrate

func (s *Storage) AutoMigrate() error

func (*Storage) CheckUserHasOpToInstance added in v1.2202.0

func (s *Storage) CheckUserHasOpToInstance(user *User, instance *Instance, ops []uint) (bool, error)

func (*Storage) CloneRuleTemplateRules

func (s *Storage) CloneRuleTemplateRules(source, destination *RuleTemplate) error

func (*Storage) Create

func (s *Storage) Create(model interface{}) error

func (*Storage) CreateAdminUser

func (s *Storage) CreateAdminUser() error

func (*Storage) CreateDefaultTemplate

func (s *Storage) CreateDefaultTemplate(rules map[string][]*driver.Rule) error

func (*Storage) CreateDefaultWorkflowTemplate

func (s *Storage) CreateDefaultWorkflowTemplate() error

func (*Storage) CreateRulesIfNotExist

func (s *Storage) CreateRulesIfNotExist(rules map[string][]*driver.Rule) error

func (*Storage) CreateWorkflow

func (s *Storage) CreateWorkflow(subject, desc string, user *User, task *Task,
	stepTemplates []*WorkflowStepTemplate) error

func (*Storage) Delete

func (s *Storage) Delete(model interface{}) error

func (*Storage) DeleteRoleAndAssociations added in v1.2202.0

func (s *Storage) DeleteRoleAndAssociations(role *Role) error

func (*Storage) DeleteRoleOperationByRoleID added in v1.2202.0

func (s *Storage) DeleteRoleOperationByRoleID(roleID uint) (err error)

func (*Storage) DeleteTask

func (s *Storage) DeleteTask(task *Task) error

func (*Storage) DeleteWorkflow

func (s *Storage) DeleteWorkflow(workflow *Workflow) error

func (*Storage) Exist

func (s *Storage) Exist(model interface{}) (bool, error)

func (*Storage) GetAllInstanceCount added in v1.2203.0

func (s *Storage) GetAllInstanceCount() (int64, error)

func (*Storage) GetAllInstanceTips added in v1.2202.0

func (s *Storage) GetAllInstanceTips(dbType string) (instances []*Instance, err error)

func (*Storage) GetAllRoleTip

func (s *Storage) GetAllRoleTip() ([]*Role, error)

func (*Storage) GetAllRule

func (s *Storage) GetAllRule() ([]*Rule, error)

func (*Storage) GetAllRuleByDBType

func (s *Storage) GetAllRuleByDBType(dbType string) ([]*Rule, error)

func (*Storage) GetAllUserCount added in v1.2203.0

func (s *Storage) GetAllUserCount() (int64, error)

func (*Storage) GetAllUserGroupTip added in v1.2202.0

func (s *Storage) GetAllUserGroupTip() ([]*UserGroup, error)

func (*Storage) GetAllUserTip

func (s *Storage) GetAllUserTip() ([]*User, error)

func (*Storage) GetAndCheckInstanceExist

func (s *Storage) GetAndCheckInstanceExist(instanceNames []string) (instances []*Instance, err error)

func (*Storage) GetAndCheckRoleExist

func (s *Storage) GetAndCheckRoleExist(roleNames []string) (roles []*Role, err error)

func (*Storage) GetAndCheckRuleExist

func (s *Storage) GetAndCheckRuleExist(ruleNames []string, dbType string) (map[string]Rule, error)

func (*Storage) GetAndCheckRuleTemplateExist

func (s *Storage) GetAndCheckRuleTemplateExist(templateNames []string) (ruleTemplates []*RuleTemplate, err error)

func (*Storage) GetAndCheckUserExist

func (s *Storage) GetAndCheckUserExist(userNames []string) (users []*User, err error)

func (*Storage) GetAndCheckUserGroupExist added in v1.2202.0

func (s *Storage) GetAndCheckUserGroupExist(userGroupNames []string) (ugs []*UserGroup, err error)

func (*Storage) GetAuditPlanByName

func (s *Storage) GetAuditPlanByName(name string) (*AuditPlan, bool, error)

func (*Storage) GetAuditPlanReportSQLsByReq

func (s *Storage) GetAuditPlanReportSQLsByReq(data map[string]interface{}) (
	list []*AuditPlanReportSQLListDetail, count uint64, err error)

func (*Storage) GetAuditPlanReportsByReq

func (s *Storage) GetAuditPlanReportsByReq(data map[string]interface{}) (
	list []*AuditPlanReportListDetail, count uint64, err error)

func (*Storage) GetAuditPlanSQLs

func (s *Storage) GetAuditPlanSQLs(name string) ([]*AuditPlanSQLV2, error)

func (*Storage) GetAuditPlanSQLsByReq

func (s *Storage) GetAuditPlanSQLsByReq(data map[string]interface{}) (
	list []*AuditPlanSQLListDetail, count uint64, err error)

func (*Storage) GetAuditPlans

func (s *Storage) GetAuditPlans() ([]*AuditPlan, error)

func (*Storage) GetAuditPlansByReq

func (s *Storage) GetAuditPlansByReq(data map[string]interface{}) (
	list []*AuditPlanListDetail, count uint64, err error)

func (*Storage) GetDefaultRuleTemplateName added in v1.2111.0

func (s *Storage) GetDefaultRuleTemplateName(dbType string) string

func (*Storage) GetExpiredTasks

func (s *Storage) GetExpiredTasks(start time.Time) ([]*Task, error)

func (*Storage) GetExpiredWorkflows

func (s *Storage) GetExpiredWorkflows(start time.Time) ([]*Workflow, error)

func (*Storage) GetInstanceById

func (s *Storage) GetInstanceById(id string) (*Instance, bool, error)

func (*Storage) GetInstanceByName

func (s *Storage) GetInstanceByName(name string) (*Instance, bool, error)

func (*Storage) GetInstanceByWorkflowID added in v1.2202.0

func (s *Storage) GetInstanceByWorkflowID(workflowID uint) (*Instance, error)

func (*Storage) GetInstanceDetailByName

func (s *Storage) GetInstanceDetailByName(name string) (*Instance, bool, error)

func (*Storage) GetInstanceNamesByWorkflowTemplateId

func (s *Storage) GetInstanceNamesByWorkflowTemplateId(id uint) ([]string, error)

func (*Storage) GetInstanceTipsByUser added in v1.2202.0

func (s *Storage) GetInstanceTipsByUser(user *User, dbType string) (
	instances []*Instance, err error)

func (*Storage) GetInstanceTipsByUserViaRoles added in v1.2202.0

func (s *Storage) GetInstanceTipsByUserViaRoles(
	user *User, dbType string) (instances []*Instance, err error)

func (*Storage) GetInstancesByNames

func (s *Storage) GetInstancesByNames(names []string) ([]*Instance, error)

func (*Storage) GetInstancesByReq

func (s *Storage) GetInstancesByReq(data map[string]interface{}, user *User) (
	result []*InstanceDetail, count uint64, err error)

func (*Storage) GetLDAPConfiguration added in v1.2111.0

func (s *Storage) GetLDAPConfiguration() (*LDAPConfiguration, bool, error)

func (*Storage) GetLastWorkflow

func (s *Storage) GetLastWorkflow() (*Workflow, bool, error)

func (*Storage) GetLicense added in v1.2203.0

func (s *Storage) GetLicense() (*License, bool, error)

func (*Storage) GetNeedScheduledWorkflows added in v1.2112.0

func (s *Storage) GetNeedScheduledWorkflows() ([]*Workflow, error)

func (*Storage) GetRelatedDDLTask

func (s *Storage) GetRelatedDDLTask(task *Task) ([]Task, error)

func (*Storage) GetRoleByName

func (s *Storage) GetRoleByName(name string) (*Role, bool, error)

func (*Storage) GetRoleOperationsByRoleID added in v1.2202.0

func (s *Storage) GetRoleOperationsByRoleID(roleID uint) (roleOps []*RoleOperation, err error)

func (*Storage) GetRolesByNames

func (s *Storage) GetRolesByNames(names []string) ([]*Role, error)

func (*Storage) GetRolesByReq

func (s *Storage) GetRolesByReq(data map[string]interface{}) (
	result []*RoleDetail, count uint64, err error)

func (*Storage) GetRolesByUserID added in v1.2202.0

func (s *Storage) GetRolesByUserID(userID int) (roles []*Role, err error)

func (*Storage) GetRule

func (s *Storage) GetRule(name, dbType string) (*Rule, bool, error)

func (*Storage) GetRuleTemplateByName

func (s *Storage) GetRuleTemplateByName(name string) (*RuleTemplate, bool, error)

func (*Storage) GetRuleTemplateDetailByName

func (s *Storage) GetRuleTemplateDetailByName(name string) (*RuleTemplate, bool, error)

func (*Storage) GetRuleTemplateTips

func (s *Storage) GetRuleTemplateTips(dbType string) ([]*RuleTemplate, error)

func (*Storage) GetRuleTemplatesByInstance

func (s *Storage) GetRuleTemplatesByInstance(inst *Instance) ([]RuleTemplate, error)

func (*Storage) GetRuleTemplatesByNames

func (s *Storage) GetRuleTemplatesByNames(names []string) ([]*RuleTemplate, error)

func (*Storage) GetRuleTemplatesByReq

func (s *Storage) GetRuleTemplatesByReq(data map[string]interface{}) (
	result []*RuleTemplateDetail, count uint64, err error)

func (*Storage) GetRulesByInstanceId

func (s *Storage) GetRulesByInstanceId(instanceId string) ([]*Rule, error)

func (*Storage) GetRulesByNames

func (s *Storage) GetRulesByNames(names []string, dbType string) ([]Rule, error)

func (*Storage) GetRulesFromRuleTemplateByName

func (s *Storage) GetRulesFromRuleTemplateByName(name string) ([]*Rule, error)

func (*Storage) GetSMTPConfiguration

func (s *Storage) GetSMTPConfiguration() (*SMTPConfiguration, bool, error)

func (*Storage) GetSqlWhitelist

func (s *Storage) GetSqlWhitelist(pageIndex, pageSize uint32) ([]SqlWhitelist, uint32, error)

func (*Storage) GetSqlWhitelistById

func (s *Storage) GetSqlWhitelistById(sqlWhiteId string) (*SqlWhitelist, bool, error)

func (*Storage) GetTaskById

func (s *Storage) GetTaskById(taskId string) (*Task, bool, error)

func (*Storage) GetTaskByInstanceId

func (s *Storage) GetTaskByInstanceId(instanceId uint) ([]Task, error)

func (*Storage) GetTaskDetailById

func (s *Storage) GetTaskDetailById(taskId string) (*Task, bool, error)

func (*Storage) GetTaskExecuteSQLContent

func (s *Storage) GetTaskExecuteSQLContent(taskId string) ([]byte, error)

func (*Storage) GetTaskSQLByNumber added in v1.2201.0

func (s *Storage) GetTaskSQLByNumber(taskId, number string) (*ExecuteSQL, bool, error)

func (*Storage) GetTaskSQLsByReq

func (s *Storage) GetTaskSQLsByReq(data map[string]interface{}) (
	result []*TaskSQLDetail, count uint64, err error)

func (*Storage) GetUserByName

func (s *Storage) GetUserByName(name string) (*User, bool, error)

func (*Storage) GetUserCanOpInstances added in v1.2202.0

func (s *Storage) GetUserCanOpInstances(user *User, ops []uint) (instances []*Instance, err error)

func (*Storage) GetUserDetailByName

func (s *Storage) GetUserDetailByName(name string) (*User, bool, error)

func (*Storage) GetUserGroupByName added in v1.2202.0

func (s *Storage) GetUserGroupByName(name string) (
	userGroup *UserGroup, isExist bool, err error)

func (*Storage) GetUserGroupsByNames added in v1.2202.0

func (s *Storage) GetUserGroupsByNames(names []string) (ugs []*UserGroup, err error)

func (*Storage) GetUserGroupsByReq added in v1.2202.0

func (s *Storage) GetUserGroupsByReq(data map[string]interface{}) (
	results []*UserGroupDetail, count uint64, err error)

func (*Storage) GetUsersByNames

func (s *Storage) GetUsersByNames(names []string) ([]*User, error)

func (*Storage) GetUsersByReq

func (s *Storage) GetUsersByReq(data map[string]interface{}) (
	result []*UserDetail, count uint64, err error)

func (*Storage) GetWeChatConfiguration added in v1.2203.0

func (s *Storage) GetWeChatConfiguration() (*WeChatConfiguration, bool, error)

func (*Storage) GetWorkflowBySubject

func (s *Storage) GetWorkflowBySubject(subject string) (*Workflow, bool, error)

func (*Storage) GetWorkflowByTaskId

func (s *Storage) GetWorkflowByTaskId(id uint) (*Workflow, bool, error)

func (*Storage) GetWorkflowCountByReq

func (s *Storage) GetWorkflowCountByReq(data map[string]interface{}) (uint64, error)

func (*Storage) GetWorkflowDetailById

func (s *Storage) GetWorkflowDetailById(id string) (*Workflow, bool, error)

func (*Storage) GetWorkflowExpiredHoursOrDefault

func (s *Storage) GetWorkflowExpiredHoursOrDefault() (int64, error)

func (*Storage) GetWorkflowHistoryById

func (s *Storage) GetWorkflowHistoryById(id string) ([]*WorkflowRecord, error)

func (*Storage) GetWorkflowRecordByTaskId

func (s *Storage) GetWorkflowRecordByTaskId(id string) (*WorkflowRecord, bool, error)

TODO: args `id` using uint

func (*Storage) GetWorkflowStepsByTemplateId

func (s *Storage) GetWorkflowStepsByTemplateId(id uint) ([]*WorkflowStepTemplate, error)

func (*Storage) GetWorkflowStepsDetailByTemplateId

func (s *Storage) GetWorkflowStepsDetailByTemplateId(id uint) ([]*WorkflowStepTemplate, error)

func (*Storage) GetWorkflowTemplateById

func (s *Storage) GetWorkflowTemplateById(id uint) (*WorkflowTemplate, bool, error)

func (*Storage) GetWorkflowTemplateByName

func (s *Storage) GetWorkflowTemplateByName(name string) (*WorkflowTemplate, bool, error)

func (*Storage) GetWorkflowTemplateTip

func (s *Storage) GetWorkflowTemplateTip() ([]*WorkflowTemplate, error)

func (*Storage) GetWorkflowTemplatesByReq

func (s *Storage) GetWorkflowTemplatesByReq(data map[string]interface{}) (
	result []*WorkflowTemplateDetail, count uint64, err error)

func (*Storage) GetWorkflowsByReq

func (s *Storage) GetWorkflowsByReq(data map[string]interface{}, user *User) (
	result []*WorkflowListDetail, count uint64, err error)

func (*Storage) HardDelete

func (s *Storage) HardDelete(model interface{}) error

func (*Storage) OverrideAuditPlanSQLs

func (s *Storage) OverrideAuditPlanSQLs(apName string, sqls []*AuditPlanSQLV2) error

func (*Storage) ReplaceRoleOperationsByOpCodes added in v1.2202.0

func (s *Storage) ReplaceRoleOperationsByOpCodes(roleID uint, opCodes []uint) (err error)

func (*Storage) Save

func (s *Storage) Save(model interface{}) error

func (*Storage) SaveRoleAndAssociations added in v1.2202.0

func (s *Storage) SaveRoleAndAssociations(role *Role,
	instances []*Instance, opCodes []uint, us []*User, ugs []*UserGroup) (err error)

func (*Storage) SaveUserAndAssociations added in v1.2202.0

func (s *Storage) SaveUserAndAssociations(
	user *User, roles []*Role, userGroups []*UserGroup) (err error)

NOTE: parameter: roles([]*Users) and userGroups([]*Role) need to be distinguished as nil or zero length slice.

func (*Storage) SaveUserGroupAndAssociations added in v1.2202.0

func (s *Storage) SaveUserGroupAndAssociations(
	ug *UserGroup, us []*User, rs []*Role) (err error)

NOTE: parameter: us([]*Users) and rs([]*Role) need to be distinguished as nil or zero length slice.

func (*Storage) SaveWorkflowTemplate

func (s *Storage) SaveWorkflowTemplate(template *WorkflowTemplate) error

func (*Storage) TaskWorkflowIsRunning

func (s *Storage) TaskWorkflowIsRunning(taskIds []uint) (bool, error)

func (*Storage) Tx added in v1.2202.0

func (s *Storage) Tx(fn func(txDB *gorm.DB) error) (err error)

func (*Storage) TxExec

func (s *Storage) TxExec(fn func(tx *sql.Tx) error) error

func (*Storage) Update

func (s *Storage) Update(model interface{}, attrs ...interface{}) error

func (*Storage) UpdateAuditPlanByName

func (s *Storage) UpdateAuditPlanByName(name string, attrs map[string]interface{}) error

func (*Storage) UpdateDefaultAuditPlanSQLs added in v1.2202.0

func (s *Storage) UpdateDefaultAuditPlanSQLs(apName string, sqls []*AuditPlanSQLV2) error

func (*Storage) UpdateExecuteSQLById

func (s *Storage) UpdateExecuteSQLById(executeSQLId string, attrs ...interface{}) error

func (*Storage) UpdateExecuteSQLStatusByTaskId

func (s *Storage) UpdateExecuteSQLStatusByTaskId(task *Task, status string) error

func (*Storage) UpdateExecuteSQLs

func (s *Storage) UpdateExecuteSQLs(ExecuteSQLs []*ExecuteSQL) error

func (*Storage) UpdateExecuteSqlStatus

func (s *Storage) UpdateExecuteSqlStatus(baseSQL *BaseSQL, status, result string) error

func (*Storage) UpdateInstanceById

func (s *Storage) UpdateInstanceById(InstanceId uint, attrs ...interface{}) error

func (*Storage) UpdateInstanceRoles

func (s *Storage) UpdateInstanceRoles(instance *Instance, rs ...*Role) error

func (*Storage) UpdateInstanceRuleTemplates

func (s *Storage) UpdateInstanceRuleTemplates(instance *Instance, ts ...*RuleTemplate) error

func (*Storage) UpdatePassword

func (s *Storage) UpdatePassword(user *User, newPassword string) error

func (*Storage) UpdateRoleInstances

func (s *Storage) UpdateRoleInstances(role *Role, instances ...*Instance) error

func (*Storage) UpdateRoleUsers

func (s *Storage) UpdateRoleUsers(role *Role, users ...*User) error

func (*Storage) UpdateRollbackSQLById

func (s *Storage) UpdateRollbackSQLById(rollbackSQLId string, attrs ...interface{}) error

func (*Storage) UpdateRollbackSQLs

func (s *Storage) UpdateRollbackSQLs(rollbackSQLs []*RollbackSQL) error

func (*Storage) UpdateRollbackSqlStatus

func (s *Storage) UpdateRollbackSqlStatus(baseSQL *BaseSQL, status, result string) error

func (*Storage) UpdateRuleTemplateInstances

func (s *Storage) UpdateRuleTemplateInstances(tpl *RuleTemplate, instances ...*Instance) error

func (*Storage) UpdateRuleTemplateRules

func (s *Storage) UpdateRuleTemplateRules(tpl *RuleTemplate, rules ...RuleTemplateRule) error

func (*Storage) UpdateTask

func (s *Storage) UpdateTask(task *Task, attrs ...interface{}) error

func (*Storage) UpdateTaskStatusById

func (s *Storage) UpdateTaskStatusById(taskId uint, status string) error

func (*Storage) UpdateUserRoles

func (s *Storage) UpdateUserRoles(user *User, rs ...*Role) error

func (*Storage) UpdateWorkflowRecord

func (s *Storage) UpdateWorkflowRecord(w *Workflow, task *Task) error

func (*Storage) UpdateWorkflowSchedule added in v1.2112.0

func (s *Storage) UpdateWorkflowSchedule(w *Workflow, userId uint, scheduleTime *time.Time) error

func (*Storage) UpdateWorkflowStatus

func (s *Storage) UpdateWorkflowStatus(w *Workflow, operateStep *WorkflowStep) error

func (*Storage) UpdateWorkflowTemplateInstances

func (s *Storage) UpdateWorkflowTemplateInstances(workflowTemplate *WorkflowTemplate,
	instances ...*Instance) error

func (*Storage) UpdateWorkflowTemplateSteps

func (s *Storage) UpdateWorkflowTemplateSteps(templateId uint, steps []*WorkflowStepTemplate) error

func (*Storage) UserCanAccessInstance

func (s *Storage) UserCanAccessInstance(user *User, instance *Instance) (
	ok bool, err error)

func (*Storage) UserCanAccessWorkflow

func (s *Storage) UserCanAccessWorkflow(user *User, workflow *Workflow) (bool, error)

func (*Storage) UserHasBindWorkflowTemplate

func (s *Storage) UserHasBindWorkflowTemplate(user *User) (bool, error)

func (*Storage) UserHasRunningWorkflow

func (s *Storage) UserHasRunningWorkflow(userId uint) (bool, error)

type SystemVariable

type SystemVariable struct {
	Key   string `gorm:"primary_key"`
	Value string `gorm:"not null"`
}

SystemVariable store misc K-V.

type Task

type Task struct {
	Model
	InstanceId   uint    `json:"instance_id"`
	Schema       string  `json:"instance_schema" gorm:"column:instance_schema" example:"db1"`
	PassRate     float64 `json:"pass_rate"`
	Score        int32   `json:"score"`
	AuditLevel   string  `json:"audit_level"`
	SQLSource    string  `json:"sql_source" gorm:"column:sql_source"`
	DBType       string  `json:"db_type" gorm:"default:'mysql'" example:"mysql"`
	Status       string  `json:"status" gorm:"default:\"initialized\""`
	CreateUserId uint
	ExecStartAt  *time.Time
	ExecEndAt    *time.Time

	CreateUser   *User          `gorm:"foreignkey:CreateUserId"`
	Instance     *Instance      `json:"-" gorm:"foreignkey:InstanceId"`
	ExecuteSQLs  []*ExecuteSQL  `json:"-" gorm:"foreignkey:TaskId"`
	RollbackSQLs []*RollbackSQL `json:"-" gorm:"foreignkey:TaskId"`
}

func (*Task) HasDoingAudit

func (t *Task) HasDoingAudit() bool

func (*Task) HasDoingExecute

func (t *Task) HasDoingExecute() bool

func (*Task) HasDoingRollback

func (t *Task) HasDoingRollback() bool

func (*Task) InstanceName

func (t *Task) InstanceName() string

func (*Task) IsExecuteFailed

func (t *Task) IsExecuteFailed() bool

type TaskSQLDetail

type TaskSQLDetail struct {
	Number      uint           `json:"number"`
	Description string         `json:"description"`
	ExecSQL     string         `json:"exec_sql"`
	AuditResult string         `json:"audit_result"`
	AuditLevel  string         `json:"audit_level"`
	AuditStatus string         `json:"audit_status"`
	ExecResult  string         `json:"exec_result"`
	ExecStatus  string         `json:"exec_status"`
	RollbackSQL sql.NullString `json:"rollback_sql"`
}

type User

type User struct {
	Model
	// has created composite index: [id, login_name] by gorm#AddIndex
	Name                   string `gorm:"index;column:login_name"`
	Email                  string
	WeChatID               string                 `json:"wechat_id" gorm:"column:wechat_id"`
	Password               string                 `json:"-" gorm:"-"`
	SecretPassword         string                 `json:"secret_password" gorm:"not null;column:password"`
	UserAuthenticationType UserAuthenticationType `json:"user_authentication_type" gorm:"not null"`
	Roles                  []*Role                `gorm:"many2many:user_role;"`
	UserGroups             []*UserGroup           `gorm:"many2many:user_group_users"`
	Stat                   uint                   `json:"stat" gorm:"not null; default: 0; comment:'0:正常 1:被禁用'"`

	WorkflowStepTemplates []*WorkflowStepTemplate `gorm:"many2many:workflow_step_template_user"`
}

func (*User) AfterFind

func (i *User) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db

func (*User) BeforeSave

func (i *User) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

func (*User) IsDisabled added in v1.2202.0

func (u *User) IsDisabled() bool

func (*User) SetStat added in v1.2202.0

func (u *User) SetStat(stat uint)

type UserAuthenticationType added in v1.2111.0

type UserAuthenticationType string
const (
	UserAuthenticationTypeLDAP UserAuthenticationType = "ldap" // user verify through ldap
	UserAuthenticationTypeSQLE UserAuthenticationType = "sqle" //user verify through sqle
)

type UserDetail

type UserDetail struct {
	Id             int
	Name           string `json:"login_name"`
	Email          string
	WeChatID       sql.NullString `json:"wechat_id"`
	LoginType      string         `json:"user_authentication_type"`
	Stat           int            `json:"stat"`
	RoleNames      RowList        `json:"role_names"`
	UserGroupNames RowList        `json:"user_group_names"`
}

func (*UserDetail) IsDisabled added in v1.2202.0

func (u *UserDetail) IsDisabled() bool

type UserGroup added in v1.2202.0

type UserGroup struct {
	Model
	Name  string  `json:"name" gorm:"index"`
	Desc  string  `json:"desc" gorm:"column:description"`
	Users []*User `gorm:"many2many:user_group_users"`
	Stat  uint    `json:"stat" gorm:"comment:'0:active,1:disabled'"`
	Roles []*Role `gorm:"many2many:user_group_roles"`
}

func (*UserGroup) IsDisabled added in v1.2202.0

func (ug *UserGroup) IsDisabled() bool

func (*UserGroup) SetStat added in v1.2202.0

func (ug *UserGroup) SetStat(stat int)

func (*UserGroup) TableName added in v1.2202.0

func (ug *UserGroup) TableName() string

type UserGroupDetail added in v1.2202.0

type UserGroupDetail struct {
	Id        int
	Name      string  `json:"name"`
	Desc      string  `json:"description"`
	Stat      uint    `json:"stat"`
	UserNames RowList `json:"user_names"`
	RoleNames RowList `json:"role_names"`
}

func (*UserGroupDetail) IsDisabled added in v1.2202.0

func (ugd *UserGroupDetail) IsDisabled() bool

type WeChatConfiguration added in v1.2203.0

type WeChatConfiguration struct {
	Model
	EnableWeChatNotify  bool   `json:"enable_wechat_notify" gorm:"not null"`
	CorpID              string `json:"corp_id" gorm:"not null"`
	CorpSecret          string `json:"-" gorm:"-"`
	EncryptedCorpSecret string `json:"encrypted_corp_secret" gorm:"not null"`
	AgentID             int    `json:"agent_id" gorm:"not null"`
	SafeEnabled         bool   `json:"safe_enabled" gorm:"not null"`
	ProxyIP             string `json:"proxy_ip"`
}

WeChatConfiguration store WeChat configuration.

func (*WeChatConfiguration) AfterFind added in v1.2203.0

func (i *WeChatConfiguration) AfterFind() error

AfterFind is a hook implement gorm model after query, ignore err if query from db.

func (*WeChatConfiguration) BeforeSave added in v1.2203.0

func (i *WeChatConfiguration) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create.

func (*WeChatConfiguration) TableName added in v1.2203.0

func (i *WeChatConfiguration) TableName() string

type Workflow

type Workflow struct {
	Model
	Subject          string
	Desc             string
	CreateUserId     uint
	WorkflowRecordId uint

	CreateUser    *User             `gorm:"foreignkey:CreateUserId"`
	Record        *WorkflowRecord   `gorm:"foreignkey:WorkflowRecordId"`
	RecordHistory []*WorkflowRecord `gorm:"many2many:workflow_record_history;"`
}

func (*Workflow) CreateUserName

func (w *Workflow) CreateUserName() string

func (*Workflow) CurrentAssigneeUser

func (w *Workflow) CurrentAssigneeUser() []*User

func (*Workflow) CurrentStep

func (w *Workflow) CurrentStep() *WorkflowStep

func (*Workflow) FinalStep

func (w *Workflow) FinalStep() *WorkflowStep

func (*Workflow) IsFirstRecord

func (w *Workflow) IsFirstRecord(record *WorkflowRecord) bool

IsFirstRecord check the record is the first record in workflow; you must load record history first and then use it.

func (*Workflow) IsOperationUser

func (w *Workflow) IsOperationUser(user *User) bool

func (*Workflow) NextStep

func (w *Workflow) NextStep() *WorkflowStep

type WorkflowListDetail

type WorkflowListDetail struct {
	Id                      uint           `json:"workflow_id"`
	Subject                 string         `json:"subject"`
	Desc                    string         `json:"desc"`
	TaskPassRate            float64        `json:"task_pass_rate"`
	TaskScore               sql.NullInt32  `json:"task_score"`
	TaskInstance            sql.NullString `json:"task_instance_name"`
	TaskInstanceDeletedAt   *time.Time     `json:"task_instance_deleted_at"`
	TaskInstanceSchema      string         `json:"task_instance_schema"`
	TaskStatus              string         `json:"task_status"`
	CreateUser              sql.NullString `json:"create_user_name"`
	CreateUserDeletedAt     *time.Time     `json:"create_user_deleted_at"`
	CreateTime              *time.Time     `json:"create_time"`
	CurrentStepType         sql.NullString `json:"current_step_type" enums:"sql_review,sql_execute"`
	CurrentStepAssigneeUser RowList        `json:"current_step_assignee_user_name_list"`
	Status                  string         `json:"status"`
	ScheduleTime            *time.Time     `json:"schedule_time"`
}

type WorkflowRecord

type WorkflowRecord struct {
	Model
	TaskId                uint `gorm:"index"`
	CurrentWorkflowStepId uint
	Status                string `gorm:"default:\"on_process\""`
	ScheduledAt           *time.Time
	ScheduleUserId        uint

	CurrentStep *WorkflowStep   `gorm:"foreignkey:CurrentWorkflowStepId"`
	Steps       []*WorkflowStep `gorm:"foreignkey:WorkflowRecordId"`
}

type WorkflowStep

type WorkflowStep struct {
	Model
	OperationUserId        uint
	OperateAt              *time.Time
	WorkflowId             uint   `gorm:"index; not null"`
	WorkflowRecordId       uint   `gorm:"index; not null"`
	WorkflowStepTemplateId uint   `gorm:"index; not null"`
	State                  string `gorm:"default:\"initialized\""`
	Reason                 string

	Template      *WorkflowStepTemplate `gorm:"foreignkey:WorkflowStepTemplateId"`
	OperationUser *User                 `gorm:"foreignkey:OperationUserId"`
}

type WorkflowStepTemplate

type WorkflowStepTemplate struct {
	Model
	Number             uint   `gorm:"index; column:step_number"`
	WorkflowTemplateId int    `gorm:"index"`
	Typ                string `gorm:"column:type; not null"`
	Desc               string

	Users []*User `gorm:"many2many:workflow_step_template_user"`
}

type WorkflowTemplate

type WorkflowTemplate struct {
	Model
	Name                          string
	Desc                          string
	AllowSubmitWhenLessAuditLevel string

	Steps     []*WorkflowStepTemplate `json:"-" gorm:"foreignkey:workflowTemplateId"`
	Instances []*Instance             `gorm:"foreignkey:WorkflowTemplateId"`
}

type WorkflowTemplateDetail

type WorkflowTemplateDetail struct {
	Name string `json:"workflow_template_name"`
	Desc string `json:"desc"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL