From 56882c3b14de0250e9ccdfb1cee879116766f6af Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 3 Mar 2020 15:57:29 +0800 Subject: [PATCH] Fix tests --- dialects/postgres.go | 18 ++++++++++++++++-- tags_test.go | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/dialects/postgres.go b/dialects/postgres.go index 89bd4672..623b59ed 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -995,7 +995,6 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att return nil, nil, err } - // fmt.Println(args, colName, isNullable, dataType, maxLenStr, colDefault, isPK, isUnique) var maxLen int if maxLenStr != nil { maxLen, err = strconv.Atoi(*maxLenStr) @@ -1007,7 +1006,22 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att col.Name = strings.Trim(colName, `" `) if colDefault != nil { - col.Default = *colDefault + var theDefault = *colDefault + // cockroach has type with the default value with ::: + // and postgres with ::, we should remove them before store them + idx := strings.Index(theDefault, ":::") + if idx == -1 { + idx = strings.Index(theDefault, "::") + } + if idx > -1 { + theDefault = theDefault[:idx] + } + + if strings.HasSuffix(theDefault, "+00:00'") { + theDefault = theDefault[:len(theDefault)-7] + "'" + } + + col.Default = theDefault col.DefaultIsEmpty = false if strings.HasPrefix(col.Default, "nextval(") { col.IsAutoIncrement = true diff --git a/tags_test.go b/tags_test.go index 775fcf60..295affd8 100644 --- a/tags_test.go +++ b/tags_test.go @@ -1031,6 +1031,7 @@ func TestTagDefault4(t *testing.T) { } assert.True(t, isDefaultExist) assert.True(t, "CURRENT_TIMESTAMP" == defaultVal || + "current_timestamp()" == defaultVal || // for cockroach "now()" == defaultVal || "getdate" == defaultVal, defaultVal) }