From 6bd4f1d95aad807b2d72427fd1c72d9af89cc79a Mon Sep 17 00:00:00 2001 From: ioito Date: Thu, 27 Apr 2023 10:06:24 +0800 Subject: [PATCH] fix(region): vendor update --- go.mod | 4 ++-- go.sum | 8 +++---- vendor/modules.txt | 4 ++-- .../x/pkg/util/stringutils/stringutils.go | 6 ++++++ .../backends/clickhouse/clickhouse.go | 5 +++-- .../x/sqlchemy/backends/clickhouse/column.go | 2 +- .../backends/clickhouse/columninfo.go | 2 +- .../x/sqlchemy/backends/clickhouse/sync.go | 21 ++++++++++++++++--- .../x/sqlchemy/backends/mysql/column.go | 4 ++-- .../x/sqlchemy/backends/mysql/mysql.go | 2 +- .../x/sqlchemy/backends/sqlite/column.go | 2 +- .../x/sqlchemy/backends/sqlite/sqlite.go | 2 +- 12 files changed, 42 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index e00be6f1b5..fa61796aec 100644 --- a/go.mod +++ b/go.mod @@ -89,9 +89,9 @@ require ( yunion.io/x/jsonutils v1.0.1-0.20230417123225-5dcde3e4598b yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361 yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 - yunion.io/x/pkg v1.0.1-0.20230327034731-79f520e7d373 + yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e - yunion.io/x/sqlchemy v1.1.2-0.20230326161357-912d44dd66d6 + yunion.io/x/sqlchemy v1.1.2-0.20230422192549-7a9668176f46 yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 ) diff --git a/go.sum b/go.sum index 3c4b93050f..301242a38f 100644 --- a/go.sum +++ b/go.sum @@ -1204,12 +1204,12 @@ yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZV yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E= yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e/go.mod h1:nYOMflWG1wQC6301rGVglQva9bYbJxHThEJUxRAgMFc= -yunion.io/x/pkg v1.0.1-0.20230327034731-79f520e7d373 h1:VdQgvUo6JoOZNsPzRdoFKbD+3tEt4saHRhI/kUf6DeM= -yunion.io/x/pkg v1.0.1-0.20230327034731-79f520e7d373/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk= +yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe h1:pwjs6kOP3cenRN+Oc2zyJerAhBAn4owaLbzZyLx5/rA= +yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo= yunion.io/x/sqlchemy v1.0.1/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI= -yunion.io/x/sqlchemy v1.1.2-0.20230326161357-912d44dd66d6 h1:qs8BU3AH7MsKeWLzuaj2bCc2/VnwyYqzl55VJXS25X4= -yunion.io/x/sqlchemy v1.1.2-0.20230326161357-912d44dd66d6/go.mod h1:xXVfJLIxxTRTnPEaVIIoRZXqWyO8+takIOYhc+zO5KE= +yunion.io/x/sqlchemy v1.1.2-0.20230422192549-7a9668176f46 h1:M/Xv+Qu6/dSMyuvhgbs52/adr+O5k5NXtpF7czYVCJU= +yunion.io/x/sqlchemy v1.1.2-0.20230422192549-7a9668176f46/go.mod h1:xXVfJLIxxTRTnPEaVIIoRZXqWyO8+takIOYhc+zO5KE= yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 h1:WuWXhY3DvhdRTzWCJ/kwt3Ss6KIq7+KqJwb+esvNGwU= yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng= diff --git a/vendor/modules.txt b/vendor/modules.txt index a93de3548a..7bd1e8e00e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1548,7 +1548,7 @@ yunion.io/x/log/hooks yunion.io/x/ovsdb/cli_util yunion.io/x/ovsdb/schema/ovn_nb yunion.io/x/ovsdb/types -# yunion.io/x/pkg v1.0.1-0.20230327034731-79f520e7d373 +# yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe ## explicit; go 1.18 yunion.io/x/pkg/appctx yunion.io/x/pkg/errors @@ -1603,7 +1603,7 @@ yunion.io/x/pkg/utils # yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e ## explicit; go 1.12 yunion.io/x/s3cli -# yunion.io/x/sqlchemy v1.1.2-0.20230326161357-912d44dd66d6 +# yunion.io/x/sqlchemy v1.1.2-0.20230422192549-7a9668176f46 ## explicit; go 1.17 yunion.io/x/sqlchemy yunion.io/x/sqlchemy/backends diff --git a/vendor/yunion.io/x/pkg/util/stringutils/stringutils.go b/vendor/yunion.io/x/pkg/util/stringutils/stringutils.go index 4fccc70971..460c656efa 100644 --- a/vendor/yunion.io/x/pkg/util/stringutils/stringutils.go +++ b/vendor/yunion.io/x/pkg/util/stringutils/stringutils.go @@ -16,6 +16,7 @@ package stringutils import ( "fmt" + "regexp" "strings" "time" @@ -89,3 +90,8 @@ func SplitKeyValueBySep(line string, sep string) (string, string) { } return "", "" } + +func ContainsWord(str, w string) bool { + reg := regexp.MustCompile(fmt.Sprintf("\\b%s\\b", w)) + return reg.MatchString(str) +} diff --git a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go index f6d29108a3..c75b42898b 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go +++ b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go @@ -24,6 +24,7 @@ import ( "yunion.io/x/pkg/errors" "yunion.io/x/pkg/gotypes" "yunion.io/x/pkg/tristate" + "yunion.io/x/pkg/util/stringutils" "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" @@ -190,7 +191,7 @@ func (click *SClickhouseBackend) FetchTableColumnSpecs(ts sqlchemy.ITableSpec) ( clickSpec.SetOrderBy(true) } for _, part := range partitions { - if strings.Contains(part, clickSpec.Name()) { + if stringutils.ContainsWord(part, clickSpec.Name()) { clickSpec.SetPartitionBy(part) } } @@ -206,7 +207,7 @@ func (click *SClickhouseBackend) FetchTableColumnSpecs(ts sqlchemy.ITableSpec) ( func (click *SClickhouseBackend) GetColumnSpecByFieldType(table *sqlchemy.STableSpec, fieldType reflect.Type, fieldname string, tagmap map[string]string, isPointer bool) sqlchemy.IColumnSpec { switch fieldType { case tristate.TriStateType: - col := NewTristateColumn(fieldname, tagmap, isPointer) + col := NewTristateColumn(table.Name(), fieldname, tagmap, isPointer) return &col case gotypes.TimeType: col := NewDateTimeColumn(fieldname, tagmap, isPointer) diff --git a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/column.go b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/column.go index 3b01fdfba0..682476317f 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/column.go +++ b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/column.go @@ -240,7 +240,7 @@ func (c *STristateColumn) IsZero(val interface{}) bool { } // NewTristateColumn return an instance of STristateColumn -func NewTristateColumn(name string, tagmap map[string]string, isPointer bool) STristateColumn { +func NewTristateColumn(table, name string, tagmap map[string]string, isPointer bool) STristateColumn { //if _, ok := tagmap[sqlchemy.TAG_NULLABLE]; ok { // tristate always nullable delete(tagmap, sqlchemy.TAG_NULLABLE) diff --git a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/columninfo.go b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/columninfo.go index e8102ea433..525e4303ee 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/columninfo.go +++ b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/columninfo.go @@ -53,7 +53,7 @@ func (info *sSqlColumnInfo) getType() string { } func (info *sSqlColumnInfo) getDefault() string { - if len(info.DefaultExpression) > 0 { + if info.DefaultType == "DEFAULT" { if strings.HasPrefix(info.DefaultExpression, "CAST(") { defaultVals := strings.Split(info.DefaultExpression[len("CAST("):len(info.DefaultExpression)-1], ",") defaultVal := defaultVals[0] diff --git a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/sync.go b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/sync.go index d652ad6c57..f265707f4b 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/sync.go +++ b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/sync.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/pkg/sortedstring" + "yunion.io/x/pkg/util/stringutils" "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" ) @@ -60,6 +61,15 @@ func findPartitions(cols []sqlchemy.IColumnSpec) []string { return parts } +func arrayContainsWord(strs []string, word string) bool { + for _, str := range strs { + if stringutils.ContainsWord(str, word) { + return true + } + } + return false +} + func (clickhouse *SClickhouseBackend) CommitTableChangeSQL(ts sqlchemy.ITableSpec, changes sqlchemy.STableChanges) []string { ret := make([]string, 0) @@ -119,9 +129,15 @@ func (clickhouse *SClickhouseBackend) CommitTableChangeSQL(ts sqlchemy.ITableSpe log.Errorf("column %s is not nullable but no default, drop not nullable attribute", col.Name()) } } + + oldPartitions := findPartitions(changes.OldColumns) for _, cols := range changes.UpdatedColumns { - sql := fmt.Sprintf("MODIFY COLUMN %s", cols.NewCol.DefinitionString()) - alters = append(alters, sql) + if cols.OldCol.IsNullable() && !cols.NewCol.IsNullable() && arrayContainsWord(oldPartitions, cols.NewCol.Name()) { + needCopyTable = true + } else { + sql := fmt.Sprintf("MODIFY COLUMN %s", cols.NewCol.DefinitionString()) + alters = append(alters, sql) + } } for _, col := range changes.AddColumns { sql := fmt.Sprintf("ADD COLUMN %s", col.DefinitionString()) @@ -162,7 +178,6 @@ func (clickhouse *SClickhouseBackend) CommitTableChangeSQL(ts sqlchemy.ITableSpe } // check partitions - oldPartitions := findPartitions(changes.OldColumns) newPartitions := findPartitions(ts.Columns()) if !sortedstring.Equals(oldPartitions, newPartitions) { log.Infof("partition inconsistemt: old=%s new=%s", oldPartitions, newPartitions) diff --git a/vendor/yunion.io/x/sqlchemy/backends/mysql/column.go b/vendor/yunion.io/x/sqlchemy/backends/mysql/column.go index 24aa1e639d..85b5704d41 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/mysql/column.go +++ b/vendor/yunion.io/x/sqlchemy/backends/mysql/column.go @@ -168,12 +168,12 @@ func (c *STristateColumn) IsZero(val interface{}) bool { } // NewTristateColumn return an instance of STristateColumn -func NewTristateColumn(name string, tagmap map[string]string, isPointer bool) STristateColumn { +func NewTristateColumn(table, name string, tagmap map[string]string, isPointer bool) STristateColumn { if _, ok := tagmap[sqlchemy.TAG_NULLABLE]; ok { // simply warning, for backward compatiblity reason // tristate always nullable // delete(tagmap, sqlchemy.TAG_NULLABLE) - log.Warningf("TristateColumn %s should have no nullable tag", name) + log.Warningf("%s TristateColumn %s should have no nullable tag", table, name) } bc := STristateColumn{SBaseWidthColumn: sqlchemy.NewBaseWidthColumn(name, "TINYINT", tagmap, isPointer)} return bc diff --git a/vendor/yunion.io/x/sqlchemy/backends/mysql/mysql.go b/vendor/yunion.io/x/sqlchemy/backends/mysql/mysql.go index b6dbb4d2da..096a617e34 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/mysql/mysql.go +++ b/vendor/yunion.io/x/sqlchemy/backends/mysql/mysql.go @@ -156,7 +156,7 @@ func (mysql *SMySQLBackend) GetColumnSpecByFieldType(table *sqlchemy.STableSpec, switch fieldType { case tristate.TriStateType: tagmap[sqlchemy.TAG_WIDTH] = "1" - col := NewTristateColumn(fieldname, tagmap, isPointer) + col := NewTristateColumn(table.Name(), fieldname, tagmap, isPointer) return &col case gotypes.TimeType: col := NewDateTimeColumn(fieldname, tagmap, isPointer) diff --git a/vendor/yunion.io/x/sqlchemy/backends/sqlite/column.go b/vendor/yunion.io/x/sqlchemy/backends/sqlite/column.go index a0a2ce399e..ce64a40ba5 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/sqlite/column.go +++ b/vendor/yunion.io/x/sqlchemy/backends/sqlite/column.go @@ -171,7 +171,7 @@ func (c *STristateColumn) IsZero(val interface{}) bool { } // NewTristateColumn return an instance of STristateColumn -func NewTristateColumn(name string, tagmap map[string]string, isPointer bool) STristateColumn { +func NewTristateColumn(table, name string, tagmap map[string]string, isPointer bool) STristateColumn { if _, ok := tagmap[sqlchemy.TAG_NULLABLE]; ok { // tristate always nullable delete(tagmap, sqlchemy.TAG_NULLABLE) diff --git a/vendor/yunion.io/x/sqlchemy/backends/sqlite/sqlite.go b/vendor/yunion.io/x/sqlchemy/backends/sqlite/sqlite.go index cc38c2f7f0..a917021d72 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/sqlite/sqlite.go +++ b/vendor/yunion.io/x/sqlchemy/backends/sqlite/sqlite.go @@ -151,7 +151,7 @@ func (sqlite *SSqliteBackend) FetchTableColumnSpecs(ts sqlchemy.ITableSpec) ([]s func (sqlite *SSqliteBackend) GetColumnSpecByFieldType(table *sqlchemy.STableSpec, fieldType reflect.Type, fieldname string, tagmap map[string]string, isPointer bool) sqlchemy.IColumnSpec { switch fieldType { case tristate.TriStateType: - col := NewTristateColumn(fieldname, tagmap, isPointer) + col := NewTristateColumn(table.Name(), fieldname, tagmap, isPointer) return &col case gotypes.TimeType: col := NewDateTimeColumn(fieldname, tagmap, isPointer)