From c6ec19c5ed778d2606eb048a5472d825cc124c8e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 16 Apr 2018 15:07:29 +0800 Subject: [PATCH 01/27] add cockroach support --- dialects/postgres.go | 21 +++++++++++++++++---- engine.go | 11 +++++++++-- test_cockroach.sh | 1 + 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100755 test_cockroach.sh diff --git a/dialects/postgres.go b/dialects/postgres.go index 2e314812..80e2f0ad 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -1022,8 +1022,8 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att col.Nullable = (isNullable == "YES") - switch dataType { - case "character varying", "character": + switch strings.ToLower(dataType) { + case "character varying", "character", "string": col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: 0, DefaultLength2: 0} case "timestamp without time zone": col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 0, DefaultLength2: 0} @@ -1035,10 +1035,19 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att col.SQLType = schemas.SQLType{Name: schemas.Bool, DefaultLength: 0, DefaultLength2: 0} case "time without time zone": col.SQLType = schemas.SQLType{Name: schemas.Time, DefaultLength: 0, DefaultLength2: 0} + case "bytes": + col.SQLType = schemas.SQLType{Name: schemas.Binary, DefaultLength: 0, DefaultLength2: 0} case "oid": col.SQLType = schemas.SQLType{Name: schemas.BigInt, DefaultLength: 0, DefaultLength2: 0} default: - col.SQLType = schemas.SQLType{Name: strings.ToUpper(dataType), DefaultLength: 0, DefaultLength2: 0} + startIdx := strings.Index(strings.ToLower(dataType), "string(") + if startIdx != -1 && strings.HasSuffix(dataType, ")") { + length := dataType[startIdx+8 : len(dataType)-1] + l, _ := strconv.Atoi(length) + col.SQLType = schemas.SQLType{Name: "STRING", DefaultLength: l, DefaultLength2: 0} + } else { + col.SQLType = schemas.SQLType{Name: strings.ToUpper(dataType), DefaultLength: 0, DefaultLength2: 0} + } } if _, ok := schemas.SqlTypes[col.SQLType.Name]; !ok { return nil, nil, fmt.Errorf("Unknown colType: %v", dataType) @@ -1128,6 +1137,10 @@ func (db *postgres) GetIndexes(ctx context.Context, tableName string) (map[strin if err != nil { return nil, err } + + if indexName == "primary" { + continue + } indexName = strings.Trim(indexName, `" `) if strings.HasSuffix(indexName, "_pkey") { continue @@ -1149,7 +1162,7 @@ func (db *postgres) GetIndexes(ctx context.Context, tableName string) (map[strin index := &schemas.Index{Name: indexName, Type: indexType, Cols: make([]string, 0)} for _, colName := range colNames { - index.Cols = append(index.Cols, strings.Trim(colName, `" `)) + index.Cols = append(index.Cols, strings.TrimSpace(strings.Replace(colName, `"`, "", -1))) } index.IsRegular = isRegular indexes[index.Name] = index diff --git a/engine.go b/engine.go index 421e89e0..7865b7cb 100644 --- a/engine.go +++ b/engine.go @@ -284,12 +284,19 @@ func (engine *Engine) loadTableInfo(table *schemas.Table) error { } table.Indexes = indexes + var seq int for _, index := range indexes { for _, name := range index.Cols { - if col := table.GetColumn(name); col != nil { + parts := strings.Split(name, " ") + if len(parts) > 1 { + if parts[1] == "DESC" { + seq = 1 + } + } + if col := table.GetColumn(parts[0]); col != nil { col.Indexes[index.Name] = index.Type } else { - return fmt.Errorf("Unknown col %s in index %v of table %v, columns %v", name, index.Name, table.Name, table.ColumnsSeq()) + return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq()) } } } diff --git a/test_cockroach.sh b/test_cockroach.sh new file mode 100755 index 00000000..ea6a844b --- /dev/null +++ b/test_cockroach.sh @@ -0,0 +1 @@ +go test -db=postgres -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" \ No newline at end of file -- 2.40.1 From 59c2b816e50475ab782f9e1ccda762991c568380 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 17 Apr 2018 09:39:33 +0800 Subject: [PATCH 02/27] add cockroach test to circleci --- circle.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 00000000..61d5bf23 --- /dev/null +++ b/circle.yml @@ -0,0 +1,46 @@ +dependencies: + override: + # './...' is a relative pattern which means all subdirectories + - go get -t -d -v ./... + - go get -t -d -v github.com/go-xorm/tests + - go get -u github.com/go-xorm/core + - go get -u github.com/go-xorm/builder + - go build -v + +database: + override: + - mysql -u root -e "CREATE DATABASE xorm_test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" + - mysql -u root -e "CREATE DATABASE xorm_test1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" + - mysql -u root -e "CREATE DATABASE xorm_test2 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" + - mysql -u root -e "CREATE DATABASE xorm_test3 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" + - createdb -p 5432 -e -U postgres xorm_test + - createdb -p 5432 -e -U postgres xorm_test1 + - createdb -p 5432 -e -U postgres xorm_test2 + - createdb -p 5432 -e -U postgres xorm_test3 + - psql xorm_test postgres -c "create schema xorm" + +test: + override: + # './...' is a relative pattern which means all subdirectories + - go get -u github.com/wadey/gocovmerge + - go test -v -race -db="sqlite3" -conn_str="./test.db" -coverprofile=coverage1-1.txt -covermode=atomic + - go test -v -race -db="sqlite3" -conn_str="./test.db" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic + - go test -v -race -db="mysql" -conn_str="root:@/xorm_test" -coverprofile=coverage2-1.txt -covermode=atomic + - go test -v -race -db="mysql" -conn_str="root:@/xorm_test" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic + - go test -v -race -db="mymysql" -conn_str="xorm_test/root/" -coverprofile=coverage3-1.txt -covermode=atomic + - go test -v -race -db="mymysql" -conn_str="xorm_test/root/" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic + - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -coverprofile=coverage4-1.txt -covermode=atomic + - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic + - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic + - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic + - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.0.0.linux-amd64.tgz | tar xvz + - cp -i cockroach-v2.0.0.linux-amd64/cockroach /usr/local/bin + - cockroach start --insecure --host=localhost & + - cockroach sql --execute="create database xorm_test" + - go test -v -race -db="postgres" -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" -coverprofile=coverage6-1.txt -covermode=atomic + - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt> coverage.txt + - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh + - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./mysql.sh + - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./postgres.sh + post: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file -- 2.40.1 From 0c769bd443a9a0a32bdc09eac1c65a8da306dcf4 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 17 Apr 2018 10:13:32 +0800 Subject: [PATCH 03/27] fix run cockroach --- circle.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 61d5bf23..8820afea 100644 --- a/circle.yml +++ b/circle.yml @@ -34,9 +34,8 @@ test: - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.0.0.linux-amd64.tgz | tar xvz - - cp -i cockroach-v2.0.0.linux-amd64/cockroach /usr/local/bin - - cockroach start --insecure --host=localhost & - - cockroach sql --execute="create database xorm_test" + - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --host=localhost & + - ./cockroach-v2.0.0.linux-amd64/cockroach sql --execute="create database xorm_test" - go test -v -race -db="postgres" -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" -coverprofile=coverage6-1.txt -covermode=atomic - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt> coverage.txt - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh -- 2.40.1 From ffe162203944db1350fcb3040960d331276de7d9 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 17 Apr 2018 10:31:28 +0800 Subject: [PATCH 04/27] fix test --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 8820afea..668adc25 100644 --- a/circle.yml +++ b/circle.yml @@ -35,7 +35,7 @@ test: - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.0.0.linux-amd64.tgz | tar xvz - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --host=localhost & - - ./cockroach-v2.0.0.linux-amd64/cockroach sql --execute="create database xorm_test" + - ./cockroach-v2.0.0.linux-amd64/cockroach sql --insecure --execute="create database xorm_test" - go test -v -race -db="postgres" -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" -coverprofile=coverage6-1.txt -covermode=atomic - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt> coverage.txt - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh -- 2.40.1 From d303e6f022865df0f28d7bc601f718f9d502a899 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 17 Apr 2018 10:54:44 +0800 Subject: [PATCH 05/27] run cockroach backround --- circle.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 668adc25..52a6b286 100644 --- a/circle.yml +++ b/circle.yml @@ -34,7 +34,9 @@ test: - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.0.0.linux-amd64.tgz | tar xvz - - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --host=localhost & + - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --host=localhost + background: true + - sleep 5 - ./cockroach-v2.0.0.linux-amd64/cockroach sql --insecure --execute="create database xorm_test" - go test -v -race -db="postgres" -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" -coverprofile=coverage6-1.txt -covermode=atomic - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt> coverage.txt -- 2.40.1 From 96195e0d1efc335958e94118e22aaee64548d287 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 17 Apr 2018 10:57:06 +0800 Subject: [PATCH 06/27] run cockroach backround --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 52a6b286..8cfb87f8 100644 --- a/circle.yml +++ b/circle.yml @@ -34,7 +34,7 @@ test: - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.0.0.linux-amd64.tgz | tar xvz - - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --host=localhost + - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --host=localhost: background: true - sleep 5 - ./cockroach-v2.0.0.linux-amd64/cockroach sql --insecure --execute="create database xorm_test" -- 2.40.1 From de9a3337633698d082aa4abc5f2eee3c118a0552 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 17 Apr 2018 21:29:02 +0800 Subject: [PATCH 07/27] run cockroach background --- circle.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 8cfb87f8..a51a8a8e 100644 --- a/circle.yml +++ b/circle.yml @@ -34,8 +34,7 @@ test: - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.0.0.linux-amd64.tgz | tar xvz - - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --host=localhost: - background: true + - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --background --host=localhost - sleep 5 - ./cockroach-v2.0.0.linux-amd64/cockroach sql --insecure --execute="create database xorm_test" - go test -v -race -db="postgres" -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" -coverprofile=coverage6-1.txt -covermode=atomic -- 2.40.1 From 6a2582521f80a1517f0153e240076b40ba896516 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Oct 2018 09:40:01 +0800 Subject: [PATCH 08/27] add drone ci --- .drone.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index eb8ed320..dbe3ca96 100644 --- a/.drone.yml +++ b/.drone.yml @@ -180,6 +180,20 @@ steps: - push - pull_request +- name: test-cockroach + pull: default + image: golang:1.13 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + commands: + - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -coverprofile=coverage8-1.txt -covermode=atomic + - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage8-2.txt -covermode=atomic + when: + event: + - push + - pull_request + - name: merge_coverage pull: default image: golang:1.12 @@ -262,4 +276,13 @@ services: event: - push - tag - - pull_request \ No newline at end of file + - pull_request + +- name: cockroach + pull: default + image: cockroachdb/cockroach:v2.0.6 + when: + event: + - push + - tag + - pull_request -- 2.40.1 From f89e8a1a917ac55646a218a9625d746b30cdf714 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Oct 2018 10:00:29 +0800 Subject: [PATCH 09/27] add trace on error --- dialects/postgres.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dialects/postgres.go b/dialects/postgres.go index 80e2f0ad..89bd4672 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -1050,7 +1050,7 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att } } if _, ok := schemas.SqlTypes[col.SQLType.Name]; !ok { - return nil, nil, fmt.Errorf("Unknown colType: %v", dataType) + return nil, nil, fmt.Errorf("Unknown colType: %s - %s", dataType, col.SQLType.Name) } col.Length = maxLen -- 2.40.1 From ea611cb2b68c98fac6d21cecf07fbe46dc0ffc04 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 23 Dec 2018 20:40:56 +0800 Subject: [PATCH 10/27] upgrade cockroach version --- circle.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index a51a8a8e..8cacf5eb 100644 --- a/circle.yml +++ b/circle.yml @@ -33,10 +33,10 @@ test: - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic - - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.0.0.linux-amd64.tgz | tar xvz - - ./cockroach-v2.0.0.linux-amd64/cockroach start --insecure --background --host=localhost + - wget -qO- https://binaries.cockroachdb.com/cockroach-v2.1.3.linux-amd64.tgz | tar xvz + - ./cockroach-v2.1.3.linux-amd64/cockroach start --insecure --background --host=localhost - sleep 5 - - ./cockroach-v2.0.0.linux-amd64/cockroach sql --insecure --execute="create database xorm_test" + - ./cockroach-v2.1.3.linux-amd64/cockroach sql --insecure --execute="create database xorm_test" - go test -v -race -db="postgres" -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" -coverprofile=coverage6-1.txt -covermode=atomic - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt> coverage.txt - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh -- 2.40.1 From f337f2c2154a60a7a2c0b8be45d0a87f40e60e92 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 23 Jan 2019 15:12:07 +0800 Subject: [PATCH 11/27] fix circle ci for cockroach --- test_cockroach.sh | 2 +- xorm_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test_cockroach.sh b/test_cockroach.sh index ea6a844b..27c61089 100755 --- a/test_cockroach.sh +++ b/test_cockroach.sh @@ -1 +1 @@ -go test -db=postgres -conn_str="postgresql://root@localhost:26257/xorm_test?sslmode=disable" \ No newline at end of file +go test -db=postgres -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable" \ No newline at end of file diff --git a/xorm_test.go b/xorm_test.go index 59f6c1a9..9c1c5b66 100644 --- a/xorm_test.go +++ b/xorm_test.go @@ -63,7 +63,7 @@ func createEngine(dbType, connStr string) error { if err != nil { return err } - rows, err := db.Query(fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = 'xorm_test'")) + rows, err := db.Query("SELECT 1 FROM pg_database WHERE datname = 'xorm_test'") if err != nil { return fmt.Errorf("db.Query: %v", err) } -- 2.40.1 From 098b98461e8c82695eee52bd63ab6c3af63435fb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 23 Jan 2019 15:18:57 +0800 Subject: [PATCH 12/27] fix postgres ci --- xorm_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xorm_test.go b/xorm_test.go index 9c1c5b66..72cea408 100644 --- a/xorm_test.go +++ b/xorm_test.go @@ -75,6 +75,12 @@ func createEngine(dbType, connStr string) error { } } if *schema != "" { + db.Close() + db, err = sql.Open(dbType, connStr) + if err != nil { + return err + } + defer db.Close() if _, err = db.Exec("CREATE SCHEMA IF NOT EXISTS " + *schema); err != nil { return fmt.Errorf("CREATE SCHEMA: %v", err) } -- 2.40.1 From 01cecd524e9a31a286838786e698eb0fddd9d55d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 1 Feb 2019 11:17:08 +0800 Subject: [PATCH 13/27] use sql_sequence when testing --- test_cockroach.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cockroach.sh b/test_cockroach.sh index 27c61089..2d5fa788 100755 --- a/test_cockroach.sh +++ b/test_cockroach.sh @@ -1 +1 @@ -go test -db=postgres -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable" \ No newline at end of file +go test -db=postgres -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable experimental_serial_normalization=sql_sequence" \ No newline at end of file -- 2.40.1 From 311c6e7f236cc577a06fd9b4c5e4be4a33b65739 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 1 Feb 2019 11:45:02 +0800 Subject: [PATCH 14/27] fix tests --- xorm_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xorm_test.go b/xorm_test.go index 72cea408..850f0f97 100644 --- a/xorm_test.go +++ b/xorm_test.go @@ -59,7 +59,7 @@ func createEngine(dbType, connStr string) error { db.Close() *ignoreSelectUpdate = true case schemas.POSTGRES: - db, err := sql.Open(dbType, connStr) + db, err := sql.Open(dbType, strings.Replace(connStr, "xorm_test", "postgres", -1)) if err != nil { return err } -- 2.40.1 From 7a4af40e1bb6049e2161d74c5406ab4821a98e9b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 21 Feb 2019 15:40:07 +0800 Subject: [PATCH 15/27] update --- test_cockroach.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cockroach.sh b/test_cockroach.sh index 2d5fa788..27c61089 100755 --- a/test_cockroach.sh +++ b/test_cockroach.sh @@ -1 +1 @@ -go test -db=postgres -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable experimental_serial_normalization=sql_sequence" \ No newline at end of file +go test -db=postgres -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable" \ No newline at end of file -- 2.40.1 From 559b98c7149122d1d9b9746a6896733eb73d344d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 13 Nov 2019 19:18:14 +0800 Subject: [PATCH 16/27] fix drone --- .drone.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index dbe3ca96..55ac24d4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -280,7 +280,9 @@ services: - name: cockroach pull: default - image: cockroachdb/cockroach:v2.0.6 + image: cockroachdb/cockroach:v19.2.0 + commands: + - start --insecure when: event: - push -- 2.40.1 From 1fd7a045bb0249028ff6ae84f0816d37bf0f8ead Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 13 Nov 2019 20:25:15 +0800 Subject: [PATCH 17/27] fix drone --- .drone.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.drone.yml b/.drone.yml index 55ac24d4..c33280f0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -180,6 +180,18 @@ steps: - push - pull_request +- name: cockroach + pull: default + image: cockroachdb/cockroach:v19.2.0 + detach: true + commands: + - start --insecure + when: + event: + - push + - tag + - pull_request + - name: test-cockroach pull: default image: golang:1.13 @@ -187,6 +199,7 @@ steps: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" commands: + - sleep 5 - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -coverprofile=coverage8-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage8-2.txt -covermode=atomic when: @@ -278,13 +291,4 @@ services: - tag - pull_request -- name: cockroach - pull: default - image: cockroachdb/cockroach:v19.2.0 - commands: - - start --insecure - when: - event: - - push - - tag - - pull_request + -- 2.40.1 From 3fd03001a2a6f81e62aa8abc3977e958670e91c4 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 14 Nov 2019 09:59:06 +0800 Subject: [PATCH 18/27] fix drone --- .drone.yml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.drone.yml b/.drone.yml index c33280f0..55ac24d4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -180,18 +180,6 @@ steps: - push - pull_request -- name: cockroach - pull: default - image: cockroachdb/cockroach:v19.2.0 - detach: true - commands: - - start --insecure - when: - event: - - push - - tag - - pull_request - - name: test-cockroach pull: default image: golang:1.13 @@ -199,7 +187,6 @@ steps: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" commands: - - sleep 5 - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -coverprofile=coverage8-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage8-2.txt -covermode=atomic when: @@ -291,4 +278,13 @@ services: - tag - pull_request - +- name: cockroach + pull: default + image: cockroachdb/cockroach:v19.2.0 + commands: + - start --insecure + when: + event: + - push + - tag + - pull_request -- 2.40.1 From 4ffe2d8e98c8556af502fb25b245529478ad8599 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 21 Feb 2020 13:13:58 +0800 Subject: [PATCH 19/27] Add makefile --- Makefile | 18 ++++++++++++++++++ test_cockroach.sh | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) delete mode 100755 test_cockroach.sh diff --git a/Makefile b/Makefile index 737ca96c..6eea67c9 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,12 @@ GOFILES := $(shell find . -name "*.go" -type f) PACKAGES ?= $(shell GO111MODULE=on $(GO) list ./...) +TEST_COCKROACH_HOST ?= cockroach:26257 +TEST_COCKROACH_SCHEMA ?= +TEST_COCKROACH_DBNAME ?= xorm_test +TEST_COCKROACH_USERNAME ?= postgres +TEST_COCKROACH_PASSWORD ?= + TEST_MSSQL_HOST ?= mssql:1433 TEST_MSSQL_DBNAME ?= gitea TEST_MSSQL_USERNAME ?= sa @@ -115,6 +121,18 @@ misspell-check: .PHONY: test test: test-sqlite +.PNONY: test-cockroach +test-cockroach: go-check + $(GO) test -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable" \ + -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic + +.PHONY: test-cockroach\#% +test-cockroach\#%: go-check + $(GO) test -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable" \ + -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic + .PNONY: test-mssql test-mssql: go-check $(GO) test -v -race -db=mssql -cache=$(TEST_CACHE_ENABLE) \ diff --git a/test_cockroach.sh b/test_cockroach.sh deleted file mode 100755 index 27c61089..00000000 --- a/test_cockroach.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=postgres -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable" \ No newline at end of file -- 2.40.1 From 06899ba68f9532bf398d330801f1517327148787 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 21 Feb 2020 17:36:14 +0800 Subject: [PATCH 20/27] Remove space --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6eea67c9..a723cb66 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ TEST_COCKROACH_HOST ?= cockroach:26257 TEST_COCKROACH_SCHEMA ?= TEST_COCKROACH_DBNAME ?= xorm_test TEST_COCKROACH_USERNAME ?= postgres -TEST_COCKROACH_PASSWORD ?= +TEST_COCKROACH_PASSWORD ?= TEST_MSSQL_HOST ?= mssql:1433 TEST_MSSQL_DBNAME ?= gitea -- 2.40.1 From 4b7ce8a1c1a0a466fa663075a843743443366e19 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Feb 2020 16:21:04 +0800 Subject: [PATCH 21/27] Fix drone --- .drone.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 55ac24d4..8bc18fb8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -186,9 +186,13 @@ steps: environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_TIDB_HOST: "cockroach:26257" + TEST_TIDB_DBNAME: xorm_test + TEST_TIDB_USERNAME: root + TEST_TIDB_PASSWORD: commands: - - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -coverprofile=coverage8-1.txt -covermode=atomic - - go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage8-2.txt -covermode=atomic + - make test-cockroach + - TEST_CACHE_ENABLE=true make test-cockroach when: event: - push @@ -210,6 +214,7 @@ steps: - test-postgres-schema - test-mssql - test-tidb + - test-cockroach commands: - make coverage when: @@ -280,7 +285,7 @@ services: - name: cockroach pull: default - image: cockroachdb/cockroach:v19.2.0 + image: cockroachdb/cockroach:v19.2.4 commands: - start --insecure when: -- 2.40.1 From 5745aa4a65a5f524ce8df8e697a8768ac106382c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Feb 2020 16:39:01 +0800 Subject: [PATCH 22/27] Fix drone --- .drone.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 8bc18fb8..9c992fff 100644 --- a/.drone.yml +++ b/.drone.yml @@ -186,10 +186,10 @@ steps: environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" - TEST_TIDB_HOST: "cockroach:26257" - TEST_TIDB_DBNAME: xorm_test - TEST_TIDB_USERNAME: root - TEST_TIDB_PASSWORD: + TEST_COCKROACH_HOST: "cockroach:26257" + TEST_COCKROACH_DBNAME: xorm_test + TEST_COCKROACH_USERNAME: root + TEST_COCKROACH_PASSWORD: commands: - make test-cockroach - TEST_CACHE_ENABLE=true make test-cockroach @@ -286,6 +286,7 @@ services: - name: cockroach pull: default image: cockroachdb/cockroach:v19.2.4 + hostname: cockroach commands: - start --insecure when: -- 2.40.1 From e3a0c2ed04fb214455d8106f287cf1c9c69b4c51 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Feb 2020 17:15:34 +0800 Subject: [PATCH 23/27] Fix drone --- .drone.yml | 2 +- xorm_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 9c992fff..90df4dc2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -288,7 +288,7 @@ services: image: cockroachdb/cockroach:v19.2.4 hostname: cockroach commands: - - start --insecure + - /cockroach/cockroach start --insecure when: event: - push diff --git a/xorm_test.go b/xorm_test.go index 850f0f97..75000417 100644 --- a/xorm_test.go +++ b/xorm_test.go @@ -184,6 +184,7 @@ func TestMain(m *testing.M) { if err := prepareEngine(); err != nil { fmt.Println(err) + os.Exit(1) return } -- 2.40.1 From 9f950e928fbc042d251b5531d53e1c7e1c248a83 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Feb 2020 17:25:42 +0800 Subject: [PATCH 24/27] fix drone --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 90df4dc2..dac49cdf 100644 --- a/.drone.yml +++ b/.drone.yml @@ -191,6 +191,7 @@ steps: TEST_COCKROACH_USERNAME: root TEST_COCKROACH_PASSWORD: commands: + - sleep 10 - make test-cockroach - TEST_CACHE_ENABLE=true make test-cockroach when: @@ -286,7 +287,6 @@ services: - name: cockroach pull: default image: cockroachdb/cockroach:v19.2.4 - hostname: cockroach commands: - /cockroach/cockroach start --insecure when: -- 2.40.1 From 17b86c99041afde794abbf5574fd115996165be1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 3 Mar 2020 15:01:53 +0800 Subject: [PATCH 25/27] Add &experimental_serial_normalization=sql_sequence on test so that id will increase from 1 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a723cb66..e3bccd57 100644 --- a/Makefile +++ b/Makefile @@ -124,13 +124,13 @@ test: test-sqlite .PNONY: test-cockroach test-cockroach: go-check $(GO) test -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ - -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable" \ + -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \ -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PHONY: test-cockroach\#% test-cockroach\#%: go-check $(GO) test -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ - -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable" \ + -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \ -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-mssql -- 2.40.1 From 8dab834a3bb2f920bb2a4b52eff736cb8462a1cb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 3 Mar 2020 15:30:31 +0800 Subject: [PATCH 26/27] fix some tests and ignore some --- Makefile | 4 ++-- session_get_test.go | 4 ++-- session_update_test.go | 5 +++++ xorm_test.go | 6 +++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index e3bccd57..faad978f 100644 --- a/Makefile +++ b/Makefile @@ -125,13 +125,13 @@ test: test-sqlite test-cockroach: go-check $(GO) test -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \ - -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic + -ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PHONY: test-cockroach\#% test-cockroach\#%: go-check $(GO) test -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ -conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \ - -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic + -ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-mssql test-mssql: go-check diff --git a/session_get_test.go b/session_get_test.go index b7eac2b4..5bac9cd7 100644 --- a/session_get_test.go +++ b/session_get_test.go @@ -335,13 +335,13 @@ func TestJSONString(t *testing.T) { assert.NoError(t, err) assert.True(t, has) assert.EqualValues(t, 1, js.Id) - assert.EqualValues(t, `["1","2"]`, js.Content) + assert.True(t, `["1","2"]` == js.Content || `["1", "2"]` == js.Content) var jss []JsonString err = testEngine.Table("json_json").Find(&jss) assert.NoError(t, err) assert.EqualValues(t, 1, len(jss)) - assert.EqualValues(t, `["1","2"]`, jss[0].Content) + assert.True(t, `["1","2"]` == jss[0].Content || `["1", "2"]` == jss[0].Content) } func TestGetActionMapping(t *testing.T) { diff --git a/session_update_test.go b/session_update_test.go index 0ef59155..f76e447b 100644 --- a/session_update_test.go +++ b/session_update_test.go @@ -42,6 +42,11 @@ func TestUpdateMap(t *testing.T) { } func TestUpdateLimit(t *testing.T) { + if *ingoreUpdateLimit { + t.Skip() + return + } + assert.NoError(t, prepareEngine()) type UpdateTable2 struct { diff --git a/xorm_test.go b/xorm_test.go index 75000417..c1f38757 100644 --- a/xorm_test.go +++ b/xorm_test.go @@ -37,9 +37,9 @@ var ( splitter = flag.String("splitter", ";", "the splitter on connstr for cluster") schema = flag.String("schema", "", "specify the schema") ignoreSelectUpdate = flag.Bool("ignore_select_update", false, "ignore select update if implementation difference, only for tidb") - - tableMapper names.Mapper - colMapper names.Mapper + ingoreUpdateLimit = flag.Bool("ignore_update_limit", false, "ignore update limit if implementation difference, only for cockroach") + tableMapper names.Mapper + colMapper names.Mapper ) func createEngine(dbType, connStr string) error { -- 2.40.1 From 56882c3b14de0250e9ccdfb1cee879116766f6af Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 3 Mar 2020 15:57:29 +0800 Subject: [PATCH 27/27] 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) } -- 2.40.1