model

package
v1.2210.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 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"
	OP_WORKFLOW_AUDIT       = 20300 // including "PASSED" and "REJECT"

	// AuditPlan: 审核计划 reserved 30000-39999
	// NOTE: 用户默认可以查看自己创建的扫描任务,无需定义此项动作权限
	OP_AUDIT_PLAN_VIEW_OTHERS = 30100
	OP_AUDIT_PLAN_SAVE        = 30200 // including "CREATE" and "UPDATE"

	// SqlQuery: SQL查询 reserved 40000-49999
	OP_SQL_QUERY_QUERY = 40100
)
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 (
	WorkflowStatusWaitForAudit     = "wait_for_audit"
	WorkflowStatusWaitForExecution = "wait_for_execution"
	WorkflowStatusReject           = "rejected"
	WorkflowStatusCancel           = "canceled"
	WorkflowStatusExecuting        = "executing"
	WorkflowStatusExecFailed       = "exec_failed"
	WorkflowStatusFinish           = "finished"

	WorkflowModeSameSQLs      = "same_sqls"
	WorkflowModeDifferentSQLs = "different_sqls"
)
View Source
const (
	WorkflowStepStateInit    = "initialized"
	WorkflowStepStateApprove = "approved"
	WorkflowStepStateReject  = "rejected"
)
View Source
const (
	DefaultAdminUser = "admin"
)
View Source
const FormatHourAndMinute = "15:04"
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"`
	RuleTemplateName string        `json:"rule_template_name"`
	Params           params.Params `json:"params" gorm:"type:varchar(1000)"`

	NotifyInterval      int    `json:"notify_interval" gorm:"default:10"`
	NotifyLevel         string `json:"notify_level" gorm:"default:'warn'"`
	EnableEmailNotify   bool   `json:"enable_email_notify"`
	EnableWebHookNotify bool   `json:"enable_web_hook_notify"`
	WebHookURL          string `json:"web_hook_url"`
	WebHookTemplate     string `json:"web_hook_template"`

	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"`
	RuleTemplateName sql.NullString `json:"rule_template_name"`
	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"`
	Number      uint   `json:"number"`
}

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"`
	Number            uint   `json:"number"`
	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"`
	FingerprintMD5 string `json:"fingerprint_md5" gorm:"column:fingerprint_md5;not null"`
	SQLContent     string `json:"sql" gorm:"type:mediumtext;not null"`
	Info           JSON   `gorm:"type:json"`
}

func (*AuditPlanSQLV2) BeforeSave added in v1.2203.0

func (a *AuditPlanSQLV2) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create.

func (*AuditPlanSQLV2) GetFingerprintMD5 added in v1.2203.0

func (a *AuditPlanSQLV2) GetFingerprintMD5() string

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:longtext"`
	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"`
	Schema          string `json:"schema"`
}

func (*BaseSQL) GetExecStatusDesc

func (s *BaseSQL) GetExecStatusDesc() string

type CloudBeaverInstanceCache added in v1.2209.0

type CloudBeaverInstanceCache struct {
	CloudBeaverInstanceID   string `json:"cloud_beaver_instance_id"`
	SQLEInstanceID          uint   `json:"sqle_instance_id" gorm:"primary_key"`
	SQLEInstanceFingerprint string `json:"sqle_instance_fingerprint"`
}

type CloudBeaverUserCache added in v1.2209.0

type CloudBeaverUserCache struct {
	SQLEUserID        uint   `json:"sqle_user_id" gorm:"column:sqle_user_id;primary_key"`
	CloudBeaverUserID string `json:"cloud_beaver_user_id" gorm:"column:cloud_beaver_user_id"`
	SQLEFingerprint   string `json:"sqle_fingerprint" gorm:"column:sqle_fingerprint"`
}

type DailyWorkflowCount added in v1.2208.0

type DailyWorkflowCount struct {
	Date  time.Time `json:"date"`
	Count int       `json:"count"`
}

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"`
	SqlQueryConfig     SqlQueryConfig `json:"sql_query_config" gorm:"type:varchar(255); default:'{\"max_pre_query_rows\":100,\"query_timeout_second\":10}'"`

	// 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

func (*Instance) Fingerprint added in v1.2209.0

func (i *Instance) Fingerprint() string

type InstanceDetail

type InstanceDetail struct {
	Name                 string         `json:"name"`
	DbType               string         `json:"db_type"`
	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"`
	SqlQueryConfig       SqlQueryConfig `json:"sql_query_config"`
}

type JSON added in v1.2202.0

type JSON json.RawMessage

func (JSON) OriginValue added in v1.2207.0

func (j JSON) OriginValue() (map[string]interface{}, error)

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"`
	// whether the ssl is enabled
	EnableSSL bool `json:"enable_ssl" 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 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 Oauth2Configuration added in v1.2205.0

type Oauth2Configuration struct {
	Model
	EnableOauth2    bool   `json:"enable_oauth2" gorm:"column:enable_oauth2"`
	ClientID        string `json:"client_id" gorm:"column:client_id"`
	ClientKey       string `json:"-" gorm:"-"`
	ClientSecret    string `json:"client_secret" gorm:"client_secret"`
	ClientHost      string `json:"client_host" gorm:"column:client_host"`
	ServerAuthUrl   string `json:"server_auth_url" gorm:"column:server_auth_url"`
	ServerTokenUrl  string `json:"server_token_url" gorm:"column:server_token_url"`
	ServerUserIdUrl string `json:"server_user_id_url" gorm:"column:server_user_id_url"`
	Scopes          string `json:"scopes" gorm:"column:scopes"`
	AccessTokenTag  string `json:"access_token_tag" gorm:"column:access_token_tag"`
	UserIdTag       string `json:"user_id_tag" gorm:"column:user_id_tag"`
	LoginTip        string `json:"login_tip" gorm:"column:login_tip; default:'使用第三方账户登录'"`
}

Oauth2Configuration store ldap server configuration.

func (*Oauth2Configuration) AfterFind added in v1.2205.0

func (i *Oauth2Configuration) AfterFind() error

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

func (*Oauth2Configuration) BeforeSave added in v1.2205.0

func (i *Oauth2Configuration) BeforeSave() error

BeforeSave is a hook implement gorm model before exec create

func (*Oauth2Configuration) GetScopes added in v1.2205.0

func (i *Oauth2Configuration) GetScopes() []string

func (*Oauth2Configuration) SetScopes added in v1.2205.0

func (i *Oauth2Configuration) SetScopes(s []string)

func (*Oauth2Configuration) TableName added in v1.2205.0

func (i *Oauth2Configuration) TableName() string

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

func (RowList) Value added in v1.2205.0

func (r RowList) Value() (sqlDriver.Value, 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"`
	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)"`
	RuleDBType     string        `json:"rule_db_type" gorm:"column:db_type; not null;"`

	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
	EnableSMTPNotify sql.NullBool `json:"enable_smtp_notify" gorm:"default:true"`
	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:"-" gorm:"-"`
	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 SqlExecuteStatistic added in v1.2210.0

type SqlExecuteStatistic struct {
	InstanceID       uint `json:"instance_id"`
	AvgExecutionTime uint `json:"avg_execution_time"`
	MaxExecutionTime uint `json:"max_execution_time"`
	MinExecutionTime uint `json:"min_execution_time"`
}

type SqlExecutionCount added in v1.2210.0

type SqlExecutionCount struct {
	InstanceName string `json:"instance_name"`
	Count        uint   `json:"count"`
}

type SqlQueryConfig added in v1.2205.0

type SqlQueryConfig struct {
	MaxPreQueryRows                  int    `json:"max_pre_query_rows"`
	QueryTimeoutSecond               int    `json:"query_timeout_second"`
	AuditEnabled                     bool   `json:"audit_enabled"`
	AllowQueryWhenLessThanAuditLevel string `json:"allow_query_when_less_than_audit_level"`
}

func (*SqlQueryConfig) Scan added in v1.2205.0

func (c *SqlQueryConfig) Scan(value interface{}) error

Scan impl sql.Scanner interface

func (SqlQueryConfig) Value added in v1.2205.0

func (c SqlQueryConfig) Value() (driver.Value, error)

Value impl sql.driver.Valuer interface

type SqlQueryExecutionSql added in v1.2205.0

type SqlQueryExecutionSql struct {
	Model
	SqlQueryHistoryId uint       `json:"sql_query_history_id" gorm:"not null"`
	Sql               string     `json:"sql" gorm:"type:text;not null"`
	ExecStartAt       *time.Time `json:"exec_start_at"`
	ExecEndAt         *time.Time `json:"exec_end_at"`
	ExecResult        string     `json:"exec_result" gorm:"type:text"`
}

type SqlQueryHistory added in v1.2205.0

type SqlQueryHistory struct {
	Model
	CreateUserId uint                    `json:"create_user_id" gorm:"not null;index"`
	InstanceId   uint                    `json:"instance_id" gorm:"not null;index"`
	Schema       string                  `json:"schema"`
	RawSql       string                  `json:"raw_sql" gorm:"type:text;not null"`
	ExecSQLs     []*SqlQueryExecutionSql `json:"-" gorm:"foreignkey:SqlQueryHistoryId"`
}

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) CheckUserCanCreateAuditPlan added in v1.2204.0

func (s *Storage) CheckUserCanCreateAuditPlan(user *User, instName, dbType string) (bool, error)

func (*Storage) CheckUserHasOpToAnyInstance added in v1.2209.0

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

func (*Storage) CheckUserHasOpToInstances added in v1.2209.0

func (s *Storage) CheckUserHasOpToInstances(user *User, instances []*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, tasks []*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) GetAllInstance added in v1.2209.0

func (s *Storage) GetAllInstance() ([]*Instance, error)

func (*Storage) GetAllInstanceCount added in v1.2203.0

func (s *Storage) GetAllInstanceCount() ([]*TypeCount, error)

func (*Storage) GetAllInstanceCountByType added in v1.2206.0

func (s *Storage) GetAllInstanceCountByType(dbTypes ...string) (int64, 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) GetAllWorkflowCount added in v1.2208.0

func (s *Storage) GetAllWorkflowCount() (int, 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) GetApprovedWorkflowCount added in v1.2208.0

func (s *Storage) GetApprovedWorkflowCount() (count int, err error)

GetApprovedWorkflowCount 返回审核通过的工单数(工单状态是 待上线,正在上线,上线成功,上线失败 中任意一个表示工单通过审核) 工单状态是 待审核,已驳回,已关闭 中任意一个表示工单未通过审核

func (*Storage) GetAuditPlanByName

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

func (*Storage) GetAuditPlanReportByID added in v1.2204.0

func (s *Storage) GetAuditPlanReportByID(id uint) (*AuditPlanReportV2, bool, error)

func (*Storage) GetAuditPlanReportSQLV2ByReportIDAndNumber added in v1.2206.0

func (s *Storage) GetAuditPlanReportSQLV2ByReportIDAndNumber(reportId, number uint) (
	auditPlanReportSQLV2 *AuditPlanReportSQLV2, exist bool, err 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) GetCloudBeaverInstanceCacheByCBInstIDs added in v1.2209.0

func (s *Storage) GetCloudBeaverInstanceCacheByCBInstIDs(ids []string) ([]*CloudBeaverInstanceCache, error)

func (*Storage) GetCloudBeaverInstanceCacheBySQLEInstIDs added in v1.2209.0

func (s *Storage) GetCloudBeaverInstanceCacheBySQLEInstIDs(ids []uint) ([]*CloudBeaverInstanceCache, error)

func (*Storage) GetCloudBeaverUserCacheByCBUserID added in v1.2209.0

func (s *Storage) GetCloudBeaverUserCacheByCBUserID(id string) (*CloudBeaverUserCache, bool, error)

func (*Storage) GetDefaultRuleTemplateName added in v1.2111.0

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

func (*Storage) GetDurationMinHasAudit added in v1.2208.0

func (s *Storage) GetDurationMinHasAudit(ids []uint) (int, error)

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) GetInstanceDetailByName

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

func (*Storage) GetInstanceNamesByWorkflowTemplateId

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

func (*Storage) GetInstanceTipsByTypeAndTempID added in v1.2209.0

func (s *Storage) GetInstanceTipsByTypeAndTempID(dbType string, tempID uint32) (instances []*Instance, err error)

func (*Storage) GetInstanceTipsByUser added in v1.2202.0

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

func (*Storage) GetInstanceTipsByUserAndOperation added in v1.2204.0

func (s *Storage) GetInstanceTipsByUserAndOperation(user *User, dbType string, opCode ...int) (
	instances []*Instance, err error)

func (*Storage) GetInstanceTipsByUserAndTypeAndTempID added in v1.2209.0

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

func (*Storage) GetInstancesByIds added in v1.2210.0

func (s *Storage) GetInstancesByIds(ids []uint) (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) GetInstancesByType added in v1.2206.0

func (s *Storage) GetInstancesByType(dbType string) ([]*Instance, error)

func (*Storage) GetInstancesByWorkflowID added in v1.2209.0

func (s *Storage) GetInstancesByWorkflowID(workflowID uint) ([]*Instance, error)

func (*Storage) GetInstancesTipsByUserAndTypeAndTempId added in v1.2209.0

func (s *Storage) GetInstancesTipsByUserAndTypeAndTempId(user *User, dbType string, tempID uint32) ([]*Instance, 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) GetNeedScheduledWorkflows added in v1.2112.0

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

func (*Storage) GetOauth2Configuration added in v1.2205.0

func (s *Storage) GetOauth2Configuration() (*Oauth2Configuration, bool, 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) GetRuleTemplatesByInstanceName added in v1.2208.0

func (s *Storage) GetRuleTemplatesByInstanceName(name string) (*RuleTemplate, bool, 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) GetSqlAvgExecutionTimeStatistic added in v1.2210.0

func (s *Storage) GetSqlAvgExecutionTimeStatistic(limit uint) ([]*SqlExecuteStatistic, error)

func (*Storage) GetSqlExecutionFailCount added in v1.2210.0

func (s *Storage) GetSqlExecutionFailCount() ([]SqlExecutionCount, error)

GetSqlExecutionFailCount 获取sql上线失败统计

func (*Storage) GetSqlExecutionTotalCount added in v1.2210.0

func (s *Storage) GetSqlExecutionTotalCount() ([]SqlExecutionCount, error)

GetSqlExecutionTotalCount 获取sql上线总数统计 上线总数(根据数据源划分)是指:正在上线,上线成功,上线失败 task的总数

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) GetTaskGroupByGroupId added in v1.2209.0

func (s *Storage) GetTaskGroupByGroupId(groupId uint) (*TaskGroup, error)

func (*Storage) GetTaskSQLByNumber added in v1.2201.0

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

func (*Storage) GetTaskSQLCountByTaskID added in v1.2203.0

func (s *Storage) GetTaskSQLCountByTaskID(taskId uint) (int64, error)

func (*Storage) GetTaskSQLsByReq

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

func (*Storage) GetTasksByIds added in v1.2209.0

func (s *Storage) GetTasksByIds(taskIds []uint) (tasks []*Task, foundAllIds bool, err error)

func (*Storage) GetTasksByWorkFlowRecordID added in v1.2209.0

func (s *Storage) GetTasksByWorkFlowRecordID(id uint) ([]*Task, error)

func (*Storage) GetUserByID added in v1.2204.0

func (s *Storage) GetUserByID(id uint) (*User, bool, error)

func (*Storage) GetUserByName

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

func (*Storage) GetUserByThirdPartyUserID added in v1.2205.0

func (s *Storage) GetUserByThirdPartyUserID(thirdPartyUserID 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) GetUsersByOperationCode added in v1.2204.0

func (s *Storage) GetUsersByOperationCode(instance *Instance, opCode ...int) (users []*User, err error)

GetUsersByOperationCode will return admin user if no qualified user is found, preventing the process from being stuck because no user can operate

func (*Storage) GetUsersByReq

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

func (*Storage) GetWaitExecInstancesCountByWorkflowId added in v1.2209.0

func (s *Storage) GetWaitExecInstancesCountByWorkflowId(workflowId uint) (int, error)

func (*Storage) GetWeChatConfiguration added in v1.2203.0

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

func (*Storage) GetWorkFlowCountBetweenStartTimeAndEndTime added in v1.2208.0

func (s *Storage) GetWorkFlowCountBetweenStartTimeAndEndTime(startTime, endTime time.Time) (int64, error)

func (*Storage) GetWorkFlowReverseStepsByIndexAndState added in v1.2208.0

func (s *Storage) GetWorkFlowReverseStepsByIndexAndState(index int, state string) ([]*WorkFlowStepsBO, error)

GetWorkFlowReverseStepsByIndexAndState 返回以workflow_id为分组的倒数第index个记录

func (*Storage) GetWorkFlowStepIdsHasAudit added in v1.2208.0

func (s *Storage) GetWorkFlowStepIdsHasAudit() ([]uint, error)

GetWorkFlowStepIdsHasAudit 返回走完所有审核流程的workflow_steps的id 返回以workflow_record_id为分组的倒数第二条记录的workflow_steps.id 如果存在多个工单审核流程,workflow_record_id为分组的倒数第二条记录仍然是判断审核流程是否结束的依据 如果不存在工单审核流程,LIMIT 1 offset 1 会将workflow过滤掉 每个workflow_record_id对应一个workflows表中的一条记录,返回的id数组可以作为工单数量统计的依据

func (*Storage) GetWorkInstanceRecordByTaskId added in v1.2209.0

func (s *Storage) GetWorkInstanceRecordByTaskId(id string) (instanceRecord WorkflowInstanceRecord, err 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) GetWorkflowCountByStatus added in v1.2208.0

func (s *Storage) GetWorkflowCountByStatus(status string) (int, error)

func (*Storage) GetWorkflowCountByStepType added in v1.2208.0

func (s *Storage) GetWorkflowCountByStepType(stepTypes []string) (int, error)

func (*Storage) GetWorkflowDailyCountBetweenStartTimeAndEndTime added in v1.2208.0

func (s *Storage) GetWorkflowDailyCountBetweenStartTimeAndEndTime(startTime, endTime time.Time) ([]*DailyWorkflowCount, 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) GetWorkflowRecordCountByTaskIds added in v1.2209.0

func (s *Storage) GetWorkflowRecordCountByTaskIds(ids []uint) (uint32, error)

func (*Storage) GetWorkflowStepsByTemplateId

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

func (*Storage) GetWorkflowStepsDetailByTemplateId

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

func (*Storage) GetWorkflowTasksSummaryByReq added in v1.2209.0

func (s *Storage) GetWorkflowTasksSummaryByReq(data map[string]interface{}) (
	result []*WorkflowTasksSummaryDetail, err 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) IsRuleTemplateBeingUsed added in v1.2208.0

func (s *Storage) IsRuleTemplateBeingUsed(ruleTemplateName string) (bool, error)

func (*Storage) IsRuleTemplateExist added in v1.2208.0

func (s *Storage) IsRuleTemplateExist(ruleTemplateName string) (bool, 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) TaskWorkflowIsUnfinished added in v1.2209.0

func (s *Storage) TaskWorkflowIsUnfinished(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) UpdateCloudBeaverUserCache added in v1.2209.0

func (s *Storage) UpdateCloudBeaverUserCache(sqleUserID uint, CloudBeaverUserID string) 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) UpdateInstanceRecordSchedule added in v1.2209.0

func (s *Storage) UpdateInstanceRecordSchedule(ir *WorkflowInstanceRecord, userId uint, scheduleTime *time.Time) 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, tasks []*Task, stepTemplates []*WorkflowStepTemplate) error

func (*Storage) UpdateWorkflowRecordByID added in v1.2209.0

func (s *Storage) UpdateWorkflowRecordByID(id uint, workFlow map[string]interface{}) error

func (*Storage) UpdateWorkflowStatus

func (s *Storage) UpdateWorkflowStatus(w *Workflow, operateStep *WorkflowStep, instanceRecords []*WorkflowInstanceRecord) 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\""`
	GroupId      uint    `json:"group_id" gorm:"column:group_id"`
	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 TaskGroup added in v1.2209.0

type TaskGroup struct {
	Model
	Tasks []*Task `json:"tasks" gorm:"foreignkey:GroupId"`
}

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 TypeCount added in v1.2206.0

type TypeCount struct {
	DBType string `json:"db_type"`
	Count  int64  `json:"count"`
}

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:被禁用'"`
	ThirdPartyUserID       string                 `json:"third_party_user_id"`

	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) FingerPrint added in v1.2209.0

func (i *User) FingerPrint() string

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
	UserAuthenticationTypeOAUTH2 UserAuthenticationType = "oauth2" //user verify through oauth2
)

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 WorkFlowStepsBO added in v1.2208.0

type WorkFlowStepsBO struct {
	ID         uint
	OperateAt  *time.Time
	WorkflowId uint
}

WorkFlowStepsBO BO是business object的缩写,表示业务对象

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;"`
	Mode          string
}

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) GetTaskIds added in v1.2209.0

func (w *Workflow) GetTaskIds() []uint

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 WorkflowInstanceRecord added in v1.2209.0

type WorkflowInstanceRecord struct {
	Model
	TaskId           uint `gorm:"index"`
	WorkflowRecordId uint `gorm:"index; not null"`
	InstanceId       uint
	ScheduledAt      *time.Time
	ScheduleUserId   uint
	// 用于区分工单处于上线步骤时,某个数据源是否已上线,因为数据源可以分批上线
	IsSQLExecuted   bool
	ExecutionUserId uint
}

type WorkflowListDetail

type WorkflowListDetail struct {
	Id                      uint           `json:"workflow_id"`
	Subject                 string         `json:"subject"`
	Desc                    string         `json:"desc"`
	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"`
	TaskStatus              RowList        `json:"task_status"`
	Status                  string         `json:"status"`
	TaskInstanceType        RowList        `json:"task_instance_type"`
}

type WorkflowRecord

type WorkflowRecord struct {
	Model
	CurrentWorkflowStepId uint
	Status                string                    `gorm:"default:\"wait_for_audit\""`
	InstanceRecords       []*WorkflowInstanceRecord `gorm:"foreignkey:WorkflowRecordId"`

	// 当workflow只有部分数据源已上线时,current step仍处于"sql_execute"步骤
	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

	Assignees     []*User               `gorm:"many2many:workflow_step_user"`
	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
	ApprovedByAuthorized sql.NullBool `gorm:"column:approved_by_authorized"`

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

type WorkflowTasksSummaryDetail added in v1.2209.0

type WorkflowTasksSummaryDetail struct {
	WorkflowRecordStatus      string     `json:"workflow_record_status"`
	TaskId                    uint       `json:"task_id"`
	TaskExecStartAt           *time.Time `json:"task_exec_start_at"`
	TaskExecEndAt             *time.Time `json:"task_exec_end_at"`
	TaskPassRate              float64    `json:"task_pass_rate"`
	TaskScore                 int32      `json:"task_score"`
	TaskStatus                string     `json:"task_status"`
	InstanceName              string     `json:"instance_name"`
	InstanceDeletedAt         *time.Time `json:"instance_deleted_at"`
	InstanceMaintenancePeriod Periods    `json:"instance_maintenance_period" gorm:"text"`
	InstanceScheduledAt       *time.Time `json:"instance_scheduled_at"`
	ExecutionUserDeletedAt    *time.Time `json:"execution_user_deleted_at"`
	ExecutionUserName         string     `json:"execution_user_name"`
	CurrentStepAssigneeUsers  RowList    `json:"current_step_assignee_users"`
}

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