Documentation ¶
Index ¶
- Constants
- Variables
- func IndexMach(info *task.DBInfo, sql string) (bool, error)
- func InitRuleStatus()
- func IsAlterIndexOperate(sql string) bool
- func IsBanned(column []sql_util.Column, old string, newFieldType byte, NewFieldLen int) bool
- func IsBreakRule(name string) bool
- func SetRuleStatusDao(impl RuleStatusDao)
- func UpdateRuleStatus(name, action string) (err error)
- type Audit
- type CheckerService
- type KeysInfo
- type OwlRuleStatus
- type Rule
- func (q *Rule) RuleAffectRows(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleAlterTableColumnExist(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleAlterTableDrop(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleAlterTableDropColumn(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleAlterTableExist(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleAutoIncrementLimit(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleBanAddMulti(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleColCommentCheck(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableCharset(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableCoIndexEx(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableCoIndexOrder(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableComment(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableDupIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableIndexColNum(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableIndexLen(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableIndexNum(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableNormalIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableNotNullValue(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableNotUseKeyWorld(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableSetColCharset(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableTextColNum(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleCreateTableUniqIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleDMLTableNoWhere(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleDmlIndexMatch(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleDmlNoMoreThan100(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleInsertColDef(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleInsertColValueEqual(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleMeaninglessWhere(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleMultiDeleteUpdate(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleNotUseIntAsPrimaryKey(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleOK(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleUnsupportedType(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- func (q *Rule) RuleVarcharLengthLimit(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
- type RuleStatusDao
Constants ¶
const ( Update opType = iota + 1 Delete )
const ( RuleCreate001 = "Create.001" RuleCreate002 = "Create.002" RuleCreate003 = "Create.003" RuleCreate004 = "Create.004" RuleCreate005 = "Create.005" RuleCreate006 = "Create.006" RuleCreate007 = "Create.007" RuleCreate008 = "Create.008" RuleCreate009 = "Create.009" RuleCreate010 = "Create.010" RuleCreate011 = "Create.011" RuleCreate012 = "Create.012" RuleCreate013 = "Create.013" RuleCreate014 = "Create.014" RuleCreate015 = "Create.015" RuleCreate016 = "Create.016" RuleCreate017 = "Create.017" RuleCreate018 = "Create.018" RuleCreate019 = "Create.019" RuleAlter001 = "Alter.001" RuleAlter002 = "Alter.002" RuleAlter003 = "Alter.003" RuleAlter004 = "Alter.004" RuleAlter005 = "Alter.005" RuleDml001 = "DML.001" RuleDml002 = "DML.002" RuleDml003 = "DML.003" RuleDml004 = "DML.004" RuleDml005 = "DML.005" RuleDml006 = "DML.006" RuleDml007 = "DML.007" RuleDml008 = "DML.008" RuleDml009 = "DML.009" )
Variables ¶
var Rules []Rule
Functions ¶
func InitRuleStatus ¶
func InitRuleStatus()
func IsAlterIndexOperate ¶
index str : unique,primary ,fulltext + index/key alter语句,判断是不是对索引的操作
func IsBanned ¶
* 判断是否为禁止的操作 规则要求: alter change/modify操作, 禁止以下动作: 1)int/bigint --> varchar 2) bigint --> int 3) varchar --> bigint/int 4) varchar(n) --> varchar(m) 其中n>m
* sql 类型和mysql.type 对应关系 varchar varchar int long bigint longlong
func IsBreakRule ¶
func SetRuleStatusDao ¶
func SetRuleStatusDao(impl RuleStatusDao)
func UpdateRuleStatus ¶
Types ¶
type Audit ¶
type Audit struct { Query string // 查询语句 Stmt sqlparser.Statement // 通过Vitess解析出的抽象语法树 TiStmt []ast.StmtNode // 通过TiDB解析出的抽象语法树 }
Audit 待评审的SQL结构体,由原SQL和其对应的抽象语法树组成
type CheckerService ¶
type CheckerService struct { }
var Checker CheckerService
func (CheckerService) ListRules ¶
func (CheckerService) ListRules() interface{}
type OwlRuleStatus ¶
type Rule ¶
type Rule struct { Item string `json:"item"` // 规则代号 Name string `json:"name"` // 规则名称 Summary string `json:"summary"` // 规则摘要 Content string `json:"content"` // 规则解释 Case string `json:"case"` // SQL示例 Position int `json:"position"` // 建议所处SQL字符位置,默认0表示全局建议 Open bool `json:"open"` // 是否禁用, CheckFunc func(*Rule, *Audit, *task.DBInfo) (pass bool, newSummary string, affectRows int) `json:"-"` // 函数名 }
Rule 评审规则元数据结构
func (*Rule) RuleAffectRows ¶
func (*Rule) RuleAlterTableColumnExist ¶
func (q *Rule) RuleAlterTableColumnExist(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleAlterTableColumnExist DML.007
func (*Rule) RuleAlterTableDrop ¶
func (q *Rule) RuleAlterTableDrop(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleAlterTableDrop Alter.002
func (*Rule) RuleAlterTableDropColumn ¶
func (q *Rule) RuleAlterTableDropColumn(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleAlterTableDropColumn Alter.001
func (*Rule) RuleAlterTableExist ¶
func (q *Rule) RuleAlterTableExist(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleAlterTableExist DML.006
func (*Rule) RuleAutoIncrementLimit ¶
func (*Rule) RuleBanAddMulti ¶
func (q *Rule) RuleBanAddMulti(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
Alter.004
func (*Rule) RuleColCommentCheck ¶
func (q *Rule) RuleColCommentCheck(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleColCommentCheck Create.004
func (*Rule) RuleCreateTableCharset ¶
func (q *Rule) RuleCreateTableCharset(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableCharset Create.001
func (*Rule) RuleCreateTableCoIndexEx ¶
func (q *Rule) RuleCreateTableCoIndexEx(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableCoIndexEx Create.013
func (*Rule) RuleCreateTableCoIndexOrder ¶
func (q *Rule) RuleCreateTableCoIndexOrder(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableCoIndexOrder Create.012
func (*Rule) RuleCreateTableComment ¶
func (q *Rule) RuleCreateTableComment(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableComment Create.002
func (*Rule) RuleCreateTableDupIndex ¶
func (q *Rule) RuleCreateTableDupIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableDupIndex Create.009
func (*Rule) RuleCreateTableIndex ¶
func (q *Rule) RuleCreateTableIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableIndex Create.003
func (*Rule) RuleCreateTableIndexColNum ¶
func (q *Rule) RuleCreateTableIndexColNum(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableIndexNum Create.007
func (*Rule) RuleCreateTableIndexLen ¶
func (q *Rule) RuleCreateTableIndexLen(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableIndexLen Create.014
func (*Rule) RuleCreateTableIndexNum ¶
func (q *Rule) RuleCreateTableIndexNum(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableIndexNum Create.008
func (*Rule) RuleCreateTableNormalIndex ¶
func (q *Rule) RuleCreateTableNormalIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableNormalIndex Create.006
func (*Rule) RuleCreateTableNotNullValue ¶
func (q *Rule) RuleCreateTableNotNullValue(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleAddNotNullValue Create.010
func (*Rule) RuleCreateTableNotUseKeyWorld ¶
func (q *Rule) RuleCreateTableNotUseKeyWorld(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableTextColNum Create.016
func (*Rule) RuleCreateTableSetColCharset ¶
func (q *Rule) RuleCreateTableSetColCharset(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableSetColCharset Create.011
func (*Rule) RuleCreateTableTextColNum ¶
func (q *Rule) RuleCreateTableTextColNum(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableTextColNum Create.015
func (*Rule) RuleCreateTableUniqIndex ¶
func (q *Rule) RuleCreateTableUniqIndex(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableUniqIndex Create.005
func (*Rule) RuleDMLTableNoWhere ¶
func (q *Rule) RuleDMLTableNoWhere(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleDMLTableNoWhere DML.001
func (*Rule) RuleDmlIndexMatch ¶
func (q *Rule) RuleDmlIndexMatch(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
IndexMatch DML008
func (*Rule) RuleDmlNoMoreThan100 ¶
func (q *Rule) RuleDmlNoMoreThan100(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
IndexMatch DML009
func (*Rule) RuleInsertColDef ¶
func (q *Rule) RuleInsertColDef(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleInsertColDef DML.004
func (*Rule) RuleInsertColValueEqual ¶
func (q *Rule) RuleInsertColValueEqual(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleInsertColValueEqual DML.005
func (*Rule) RuleMeaninglessWhere ¶
func (q *Rule) RuleMeaninglessWhere(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleMeaninglessWhere DML.002
func (*Rule) RuleMultiDeleteUpdate ¶
func (q *Rule) RuleMultiDeleteUpdate(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleMultiDeleteUpdate DML.003
func (*Rule) RuleNotUseIntAsPrimaryKey ¶
func (q *Rule) RuleNotUseIntAsPrimaryKey(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleCreateTableTextColNum Create.017
func (*Rule) RuleOK ¶
func (q *Rule) RuleOK(audit *Audit, info *task.DBInfo) (pass bool, newSummary string, affectRows int)
RuleOK OK
type RuleStatusDao ¶
type RuleStatusDao interface { ListAllStatus() ([]OwlRuleStatus, error) UpdateRuleStatus(ruleStatus *OwlRuleStatus) error }