Skip to content

Commit

Permalink
feature: 添加json类型开关 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchuanchuan committed May 6, 2019
1 parent c541033 commit f225847
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 88 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ type Inc struct {
EnableFingerprint bool `toml:"enable_fingerprint" json:"enable_fingerprint"`
EnableForeignKey bool `toml:"enable_foreign_key" json:"enable_foreign_key"`
EnableIdentiferKeyword bool `toml:"enable_identifer_keyword" json:"enable_identifer_keyword"`
EnableJsonType bool `toml:"enable_json_type" json:"enable_json_type"`
EnableNotInnodb bool `toml:"enable_not_innodb" json:"enable_not_innodb"`
EnableNullable bool `toml:"enable_nullable" json:"enable_nullable"` // 允许空列
EnableOrderByRand bool `toml:"enable_orderby_rand" json:"enable_orderby_rand"`
Expand Down Expand Up @@ -339,7 +340,7 @@ type Inc struct {
SupportCollation string `toml:"support_collation" json:"support_collation"`
// Version *string

EnableNullIndexName bool `toml:"enable_null_index_name" json:"enable_null_index_name"` //是否允许不指定索引名
EnableNullIndexName bool `toml:"enable_null_index_name" json:"enable_null_index_name"` //是否允许不指定索引名
}

// Osc online schema change 工具参数配置
Expand Down
5 changes: 4 additions & 1 deletion session/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ const (
ErrCharsetNotSupport
ErrCollationNotSupport
ErrTableCollationNotSupport
ER_ERROR_LAST
ErrJsonTypeSupport
//ER_NULL_NAME_FOR_INDEX
ER_ERROR_LAST
)

var ErrorsDefault = map[int]string{
Expand Down Expand Up @@ -347,6 +348,7 @@ var ErrorsDefault = map[int]string{
ErrDataTooLong: "Data too long for column '%s' at row %d",
ErrCharsetNotSupport: "Set charset to one of '%s'.",
ErrCollationNotSupport: "Set collation to one of '%s'",
ErrJsonTypeSupport: "Json type not allowed in column '%s'.",
ER_ERROR_LAST: "TheLastError,ByeBye",
//ER_NULL_NAME_FOR_INDEX: "Index name cannot be null in table '%s'.",
}
Expand Down Expand Up @@ -503,6 +505,7 @@ var ErrorsChinese = map[int]string{
ErrCharsetNotSupport: "允许的字符集: '%s'.",
ErrCollationNotSupport: "允许的排序规则: '%s'.",
ErrWrongUsage: "%s子句无法使用%s",
ErrJsonTypeSupport: "不允许使用json类型(列'%s').",
//ER_NULL_NAME_FOR_INDEX: "在表 '%s' 中, 索引名称不能为空.",
}

Expand Down
8 changes: 7 additions & 1 deletion session/session_inception.go
Original file line number Diff line number Diff line change
Expand Up @@ -2988,8 +2988,10 @@ func (s *session) mysqlCheckField(t *TableInfo, field *ast.ColumnDef) {
}
//是否使用 text\blob\json 字段类型
//当EnableNullable=false,不强制text\blob\json使用NOT NULL
if types.IsTypeBlob(field.Tp.Tp) || field.Tp.Tp == mysql.TypeJSON {
if types.IsTypeBlob(field.Tp.Tp) {
s.AppendErrorNo(ER_USE_TEXT_OR_BLOB, field.Name.Name)
} else if field.Tp.Tp == mysql.TypeJSON {
s.AppendErrorNo(ErrJsonTypeSupport, field.Name.Name)
} else {
if !notNullFlag && !hasGenerated {
s.AppendErrorNo(ER_NOT_ALLOWED_NULLABLE, field.Name.Name, tableName)
Expand Down Expand Up @@ -4881,6 +4883,10 @@ func (s *session) checkInceptionVariables(number int) bool {
if s.Inc.EnableBlobType {
return false
}
case ErrJsonTypeSupport:
if s.Inc.EnableJsonType {
return false
}
case ER_TABLE_MUST_INNODB:
if s.Inc.EnableNotInnodb {
return false
Expand Down
Loading

0 comments on commit f225847

Please sign in to comment.