From 10e6df934f996466a6d6004a6ab01719052d0a32 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Tue, 26 Feb 2019 00:33:37 +0800 Subject: [PATCH] update vendor --- Gopkg.lock | 5 +- vendor/yunion.io/x/sqlchemy/column.go | 71 +++++++++++++---------- vendor/yunion.io/x/sqlchemy/constraint.go | 23 ++++---- vendor/yunion.io/x/sqlchemy/index.go | 2 +- vendor/yunion.io/x/sqlchemy/parser.go | 39 ++++++------- vendor/yunion.io/x/sqlchemy/sync.go | 14 ++--- vendor/yunion.io/x/sqlchemy/table.go | 2 + 7 files changed, 83 insertions(+), 73 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 87bc7ca847..cace715c3d 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1722,11 +1722,11 @@ [[projects]] branch = "master" - digest = "1:0e3c8da76b7b7ba0f67ef0737d361e117b65bd328bfbcb28fb030268df587ca9" + digest = "1:b5a46ce3c4591a9d02662732fe09301a8ebfaf05ebd1d8925385d2e55519df4f" name = "yunion.io/x/sqlchemy" packages = ["."] pruneopts = "UT" - revision = "0b1ca973f3e5140dee7e773fc51cfc8c07ce0f69" + revision = "0aabcd7bbb728b02d10920325cc15b373e7b0538" [[projects]] branch = "master" @@ -1819,6 +1819,7 @@ "github.com/shirou/gopsutil/process", "github.com/stretchr/testify/assert", "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common", + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors", "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http", "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile", "github.com/tredoe/osutil/user/crypt/sha512_crypt", diff --git a/vendor/yunion.io/x/sqlchemy/column.go b/vendor/yunion.io/x/sqlchemy/column.go index 277412a07a..43996e90c0 100644 --- a/vendor/yunion.io/x/sqlchemy/column.go +++ b/vendor/yunion.io/x/sqlchemy/column.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "yunion.io/x/log" "yunion.io/x/pkg/gotypes" "yunion.io/x/pkg/tristate" "yunion.io/x/pkg/util/regutils" @@ -37,7 +38,6 @@ type IColumnSpec interface { // IsEqual(v1, v2 interface{}) bool Tags() map[string]string - SetIsPointer() IsPointer() bool } @@ -54,10 +54,6 @@ type SBaseColumn struct { tags map[string]string } -func (c *SBaseColumn) SetIsPointer() { - c.isPointer = true -} - func (c *SBaseColumn) IsPointer() bool { return c.isPointer } @@ -172,7 +168,7 @@ func definitionBuffer(c IColumnSpec) bytes.Buffer { return buf } -func NewBaseColumn(name string, sqltype string, tagmap map[string]string) SBaseColumn { +func NewBaseColumn(name string, sqltype string, tagmap map[string]string, isPointer bool) SBaseColumn { var val string var ok bool dbName := "" @@ -218,6 +214,7 @@ func NewBaseColumn(name string, sqltype string, tagmap map[string]string) SBaseC isUnique: isUnique, isIndex: isIndex, tags: tagmap, + isPointer: isPointer, } } @@ -234,13 +231,16 @@ func (c *SBaseWidthColumn) ColType() string { } } -func NewBaseWidthColumn(name string, sqltype string, tagmap map[string]string) SBaseWidthColumn { +func NewBaseWidthColumn(name string, sqltype string, tagmap map[string]string, isPointer bool) SBaseWidthColumn { width := 0 tagmap, v, ok := utils.TagPop(tagmap, TAG_WIDTH) if ok { width, _ = strconv.Atoi(v) } - wc := SBaseWidthColumn{SBaseColumn: NewBaseColumn(name, sqltype, tagmap), width: width} + wc := SBaseWidthColumn{ + SBaseColumn: NewBaseColumn(name, sqltype, tagmap, isPointer), + width: width, + } return wc } @@ -293,8 +293,12 @@ func (c *SBooleanColumn) IsZero(val interface{}) bool { } } -func NewBooleanColumn(name string, tagmap map[string]string) SBooleanColumn { - bc := SBooleanColumn{SBaseWidthColumn: NewBaseWidthColumn(name, "TINYINT", tagmap)} +func NewBooleanColumn(name string, tagmap map[string]string, isPointer bool) SBooleanColumn { + bc := SBooleanColumn{SBaseWidthColumn: NewBaseWidthColumn(name, "TINYINT", tagmap, isPointer)} + if !bc.IsPointer() && len(bc.Default()) > 0 && bc.ConvertFromString(bc.Default()) == "1" { + log.Warningf("Non-pointer boolean type should not set default value: %s(%s)", name, tagmap) + bc.defaultString = "" + } return bc } @@ -337,8 +341,8 @@ func (c *STristateColumn) IsZero(val interface{}) bool { } } -func NewTristateColumn(name string, tagmap map[string]string) STristateColumn { - bc := STristateColumn{SBaseWidthColumn: NewBaseWidthColumn(name, "TINYINT", tagmap)} +func NewTristateColumn(name string, tagmap map[string]string, isPointer bool) STristateColumn { + bc := STristateColumn{SBaseWidthColumn: NewBaseWidthColumn(name, "TINYINT", tagmap, isPointer)} return bc } @@ -384,7 +388,7 @@ func (c *SIntegerColumn) ColType() string { return str } -func NewIntegerColumn(name string, sqltype string, unsigned bool, tagmap map[string]string) SIntegerColumn { +func NewIntegerColumn(name string, sqltype string, unsigned bool, tagmap map[string]string, isPointer bool) SIntegerColumn { autoinc := false tagmap, v, ok := utils.TagPop(tagmap, TAG_AUTOINCREMENT) if ok { @@ -395,10 +399,11 @@ func NewIntegerColumn(name string, sqltype string, unsigned bool, tagmap map[str if ok { autover = utils.ToBool(v) } - c := SIntegerColumn{SBaseWidthColumn: NewBaseWidthColumn(name, sqltype, tagmap), - IsAutoIncrement: autoinc, - IsAutoVersion: autover, - IsUnsigned: unsigned, + c := SIntegerColumn{ + SBaseWidthColumn: NewBaseWidthColumn(name, sqltype, tagmap, isPointer), + IsAutoIncrement: autoinc, + IsAutoVersion: autover, + IsUnsigned: unsigned, } if autoinc { c.isPrimary = true // autoincrement column must be primary key @@ -446,8 +451,8 @@ func (c *SFloatColumn) IsZero(val interface{}) bool { return true } -func NewFloatColumn(name string, sqlType string, tagmap map[string]string) SFloatColumn { - return SFloatColumn{SBaseColumn: NewBaseColumn(name, sqlType, tagmap)} +func NewFloatColumn(name string, sqlType string, tagmap map[string]string, isPointer bool) SFloatColumn { + return SFloatColumn{SBaseColumn: NewBaseColumn(name, sqlType, tagmap, isPointer)} } type SDecimalColumn struct { @@ -487,7 +492,7 @@ func (c *SDecimalColumn) IsZero(val interface{}) bool { return true } -func NewDecimalColumn(name string, tagmap map[string]string) SDecimalColumn { +func NewDecimalColumn(name string, tagmap map[string]string, isPointer bool) SDecimalColumn { tagmap, v, ok := utils.TagPop(tagmap, TAG_PRECISION) if !ok { panic(fmt.Sprintf("Field %q of float misses precision tag", name)) @@ -496,8 +501,10 @@ func NewDecimalColumn(name string, tagmap map[string]string) SDecimalColumn { if err != nil { panic(fmt.Sprintf("Field precision of %q shoud be integer (%q)", name, v)) } - return SDecimalColumn{SBaseWidthColumn: NewBaseWidthColumn(name, "DECIMAL", tagmap), - Precision: prec} + return SDecimalColumn{ + SBaseWidthColumn: NewBaseWidthColumn(name, "DECIMAL", tagmap, isPointer), + Precision: prec, + } } type STextColumn struct { @@ -550,7 +557,7 @@ func (c *STextColumn) IsZero(val interface{}) bool { } } -func NewTextColumn(name string, tagmap map[string]string) STextColumn { +func NewTextColumn(name string, tagmap map[string]string, isPointer bool) STextColumn { var width int var sqltype string widthStr, _ := tagmap[TAG_WIDTH] @@ -576,8 +583,10 @@ func NewTextColumn(name string, tagmap map[string]string) STextColumn { } else if charset != "utf8" && charset != "ascii" { panic(fmt.Sprintf("Unsupported charset %s for %s", charset, name)) } - return STextColumn{SBaseWidthColumn: NewBaseWidthColumn(name, sqltype, tagmap), - Charset: charset} + return STextColumn{ + SBaseWidthColumn: NewBaseWidthColumn(name, sqltype, tagmap, isPointer), + Charset: charset, + } } /*type SStringColumn struct { @@ -623,7 +632,7 @@ func (c *SDateTimeColumn) IsZero(val interface{}) bool { } -func NewDateTimeColumn(name string, tagmap map[string]string) SDateTimeColumn { +func NewDateTimeColumn(name string, tagmap map[string]string, isPointer bool) SDateTimeColumn { createdAt := false updatedAt := false tagmap, v, ok := utils.TagPop(tagmap, TAG_CREATE_TIMESTAMP) @@ -634,8 +643,10 @@ func NewDateTimeColumn(name string, tagmap map[string]string) SDateTimeColumn { if ok { updatedAt = utils.ToBool(v) } - dtc := SDateTimeColumn{NewBaseColumn(name, "DATETIME", tagmap), - createdAt, updatedAt} + dtc := SDateTimeColumn{ + NewBaseColumn(name, "DATETIME", tagmap, isPointer), + createdAt, updatedAt, + } return dtc } @@ -668,8 +679,8 @@ func (c *CompoundColumn) ConvertFromValue(val interface{}) interface{} { } } -func NewCompoundColumn(name string, tagmap map[string]string) CompoundColumn { - dtc := CompoundColumn{NewTextColumn(name, tagmap)} +func NewCompoundColumn(name string, tagmap map[string]string, isPointer bool) CompoundColumn { + dtc := CompoundColumn{NewTextColumn(name, tagmap, isPointer)} return dtc } diff --git a/vendor/yunion.io/x/sqlchemy/constraint.go b/vendor/yunion.io/x/sqlchemy/constraint.go index 6f7bf29735..b08e3e56a2 100644 --- a/vendor/yunion.io/x/sqlchemy/constraint.go +++ b/vendor/yunion.io/x/sqlchemy/constraint.go @@ -3,23 +3,22 @@ package sqlchemy import ( "regexp" "strings" - ) type STableConstraint struct { - name string - columns []string + name string + columns []string foreignTable string - foreignKeys []string + foreignKeys []string } const ( - indexPattern = `(?PUNIQUE\s+)?KEY ` + "`" + `(?P\w+)` + "`" + ` \((?P` + "`" + `\w+` + "`" + `(\(\d+\))?(,\s*` + "`" + `\w+` + "`" + `(\(\d+\))?)*)\)` + indexPattern = `(?PUNIQUE\s+)?KEY ` + "`" + `(?P\w+)` + "`" + ` \((?P` + "`" + `\w+` + "`" + `(\(\d+\))?(,\s*` + "`" + `\w+` + "`" + `(\(\d+\))?)*)\)` constraintPattern = `CONSTRAINT ` + "`" + `(?P\w+)` + "`" + ` FOREIGN KEY \((?P` + "`" + `\w+` + "`" + `(,\s*` + "`" + `\w+` + "`" + `)*)\) REFERENCES ` + "`" + `(?P\w+)` + "`" + ` \((?P` + "`" + `\w+` + "`" + `(,\s*` + "`" + `\w+` + "`" + `)*)\)` ) var ( - indexRegexp = regexp.MustCompile(indexPattern) + indexRegexp = regexp.MustCompile(indexPattern) constraintRegexp = regexp.MustCompile(constraintPattern) ) @@ -45,10 +44,10 @@ func parseConstraints(defStr string) []STableConstraint { tcs := make([]STableConstraint, len(matches)) for i := range matches { tcs[i] = STableConstraint{ - name: matches[i][1], + name: matches[i][1], foreignTable: matches[i][4], - columns: fetchColumns(matches[i][2]), - foreignKeys: fetchColumns(matches[i][5]), + columns: fetchColumns(matches[i][2]), + foreignKeys: fetchColumns(matches[i][5]), } } return tcs @@ -59,10 +58,10 @@ func parseIndexes(defStr string) []STableIndex { tcs := make([]STableIndex, len(matches)) for i := range matches { tcs[i] = STableIndex{ - name: matches[i][2], + name: matches[i][2], isUnique: len(matches[i][1]) > 0, - columns: fetchColumns(matches[i][3]), + columns: fetchColumns(matches[i][3]), } } return tcs -} \ No newline at end of file +} diff --git a/vendor/yunion.io/x/sqlchemy/index.go b/vendor/yunion.io/x/sqlchemy/index.go index 49828a46df..798fe79106 100644 --- a/vendor/yunion.io/x/sqlchemy/index.go +++ b/vendor/yunion.io/x/sqlchemy/index.go @@ -61,4 +61,4 @@ func (ts *STableSpec) AddIndex(unique bool, cols ...string) bool { idx := STableIndex{name: name, columns: cols, isUnique: unique} ts.indexes = append(ts.indexes, idx) return true -} \ No newline at end of file +} diff --git a/vendor/yunion.io/x/sqlchemy/parser.go b/vendor/yunion.io/x/sqlchemy/parser.go index 93b87336d0..add1592721 100644 --- a/vendor/yunion.io/x/sqlchemy/parser.go +++ b/vendor/yunion.io/x/sqlchemy/parser.go @@ -15,12 +15,9 @@ func structField2ColumnSpec(field *reflectutils.SStructFieldValue) IColumnSpec { return nil } fieldType := field.Value.Type() - var retCol = getFiledTypeCol(fieldType, fieldname, tagmap) + var retCol = getFiledTypeCol(fieldType, fieldname, tagmap, false) if retCol == nil && fieldType.Kind() == reflect.Ptr { - retCol = getFiledTypeCol(fieldType.Elem(), fieldname, tagmap) - if retCol != nil { - retCol.SetIsPointer() - } + retCol = getFiledTypeCol(fieldType.Elem(), fieldname, tagmap, true) } if retCol == nil { panic("unsupported colume data type %s" + fieldType.Name()) @@ -28,69 +25,69 @@ func structField2ColumnSpec(field *reflectutils.SStructFieldValue) IColumnSpec { return retCol } -func getFiledTypeCol(fieldType reflect.Type, fieldname string, tagmap map[string]string) IColumnSpec { +func getFiledTypeCol(fieldType reflect.Type, fieldname string, tagmap map[string]string, isPointer bool) IColumnSpec { switch fieldType { case gotypes.StringType: - col := NewTextColumn(fieldname, tagmap) + col := NewTextColumn(fieldname, tagmap, isPointer) return &col case gotypes.IntType, gotypes.Int32Type: tagmap[TAG_WIDTH] = "11" - col := NewIntegerColumn(fieldname, "INT", false, tagmap) + col := NewIntegerColumn(fieldname, "INT", false, tagmap, isPointer) return &col case gotypes.Int8Type: tagmap[TAG_WIDTH] = "4" - col := NewIntegerColumn(fieldname, "TINYINT", false, tagmap) + col := NewIntegerColumn(fieldname, "TINYINT", false, tagmap, isPointer) return &col case gotypes.Int16Type: tagmap[TAG_WIDTH] = "6" - col := NewIntegerColumn(fieldname, "SMALLINT", false, tagmap) + col := NewIntegerColumn(fieldname, "SMALLINT", false, tagmap, isPointer) return &col case gotypes.Int64Type: tagmap[TAG_WIDTH] = "20" - col := NewIntegerColumn(fieldname, "BIGINT", false, tagmap) + col := NewIntegerColumn(fieldname, "BIGINT", false, tagmap, isPointer) return &col case gotypes.UintType, gotypes.Uint32Type: tagmap[TAG_WIDTH] = "11" - col := NewIntegerColumn(fieldname, "INT", true, tagmap) + col := NewIntegerColumn(fieldname, "INT", true, tagmap, isPointer) return &col case gotypes.Uint8Type: tagmap[TAG_WIDTH] = "4" - col := NewIntegerColumn(fieldname, "TINYINT", true, tagmap) + col := NewIntegerColumn(fieldname, "TINYINT", true, tagmap, isPointer) return &col case gotypes.Uint16Type: tagmap[TAG_WIDTH] = "6" - col := NewIntegerColumn(fieldname, "SMALLINT", true, tagmap) + col := NewIntegerColumn(fieldname, "SMALLINT", true, tagmap, isPointer) return &col case gotypes.Uint64Type: tagmap[TAG_WIDTH] = "20" - col := NewIntegerColumn(fieldname, "BIGINT", true, tagmap) + col := NewIntegerColumn(fieldname, "BIGINT", true, tagmap, isPointer) return &col case gotypes.BoolType: tagmap[TAG_WIDTH] = "1" - col := NewBooleanColumn(fieldname, tagmap) + col := NewBooleanColumn(fieldname, tagmap, isPointer) return &col case tristate.TriStateType: tagmap[TAG_WIDTH] = "1" - col := NewTristateColumn(fieldname, tagmap) + col := NewTristateColumn(fieldname, tagmap, isPointer) return &col case gotypes.Float32Type, gotypes.Float64Type: if _, ok := tagmap[TAG_WIDTH]; ok { - col := NewDecimalColumn(fieldname, tagmap) + col := NewDecimalColumn(fieldname, tagmap, isPointer) return &col } else { colType := "FLOAT" if fieldType == gotypes.Float64Type { colType = "DOUBLE" } - col := NewFloatColumn(fieldname, colType, tagmap) + col := NewFloatColumn(fieldname, colType, tagmap, isPointer) return &col } case gotypes.TimeType: - col := NewDateTimeColumn(fieldname, tagmap) + col := NewDateTimeColumn(fieldname, tagmap, isPointer) return &col default: if fieldType.Implements(gotypes.ISerializableType) { - col := NewCompoundColumn(fieldname, tagmap) + col := NewCompoundColumn(fieldname, tagmap, isPointer) return &col } } diff --git a/vendor/yunion.io/x/sqlchemy/sync.go b/vendor/yunion.io/x/sqlchemy/sync.go index fe680071db..2e801f9066 100644 --- a/vendor/yunion.io/x/sqlchemy/sync.go +++ b/vendor/yunion.io/x/sqlchemy/sync.go @@ -68,11 +68,11 @@ func (info *SSqlColumnInfo) toColumnSpec() IColumnSpec { tagmap[TAG_DEFAULT] = info.Default } if strings.HasSuffix(typeStr, "CHAR") { - c := NewTextColumn(info.Field, tagmap) + c := NewTextColumn(info.Field, tagmap, false) return &c } else if strings.HasSuffix(typeStr, "TEXT") { tagmap[TAG_TEXT_LENGTH] = typeStr[:len(typeStr)-4] - c := NewTextColumn(info.Field, tagmap) + c := NewTextColumn(info.Field, tagmap, false) return &c } else if strings.HasSuffix(typeStr, "INT") { if info.Extra == "auto_increment" { @@ -82,10 +82,10 @@ func (info *SSqlColumnInfo) toColumnSpec() IColumnSpec { if strings.HasSuffix(info.Type, " unsigned") { unsigned = true } - c := NewIntegerColumn(info.Field, typeStr, unsigned, tagmap) + c := NewIntegerColumn(info.Field, typeStr, unsigned, tagmap, false) return &c } else if typeStr == "FLOAT" || typeStr == "DOUBLE" { - c := NewFloatColumn(info.Field, typeStr, tagmap) + c := NewFloatColumn(info.Field, typeStr, tagmap, false) return &c } else if typeStr == "DECIMAL" { if len(matches) > 3 { @@ -94,10 +94,10 @@ func (info *SSqlColumnInfo) toColumnSpec() IColumnSpec { tagmap[TAG_PRECISION] = fmt.Sprintf("%d", precision) } } - c := NewDecimalColumn(info.Field, tagmap) + c := NewDecimalColumn(info.Field, tagmap, false) return &c } else if typeStr == "DATETIME" { - c := NewDateTimeColumn(info.Field, tagmap) + c := NewDateTimeColumn(info.Field, tagmap, false) return &c } else { log.Errorf("unsupported type %s", typeStr) @@ -189,7 +189,7 @@ func diffIndexes2(exists []STableIndex, defs []STableIndex) (diff []STableIndex) break } } - if ! findDef { + if !findDef { diff = append(diff, exists[i]) } } diff --git a/vendor/yunion.io/x/sqlchemy/table.go b/vendor/yunion.io/x/sqlchemy/table.go index c43cee7733..8342b2d8f3 100644 --- a/vendor/yunion.io/x/sqlchemy/table.go +++ b/vendor/yunion.io/x/sqlchemy/table.go @@ -5,6 +5,7 @@ import ( "reflect" "strings" + "yunion.io/x/log" "yunion.io/x/pkg/utils" ) @@ -38,6 +39,7 @@ func NewTableSpecFromStruct(s interface{}, name string) *STableSpec { name: name, structType: st, } + log.Infof("struct2TableSpec for table %s", name) struct2TableSpec(val, table) return table }