Merge 49667154be
into 57a7e4421e
This commit is contained in:
commit
7b9b04869b
|
@ -30,6 +30,9 @@ jobs:
|
|||
|
||||
- image: pingcap/tidb:v2.1.2
|
||||
|
||||
- image: cockroachdb/cockroach:v2.1.6
|
||||
command: start --insecure
|
||||
|
||||
working_directory: /go/src/github.com/go-xorm/xorm
|
||||
steps:
|
||||
- checkout
|
||||
|
@ -56,6 +59,8 @@ jobs:
|
|||
- run: go test -v -race -db="mssql" -conn_str="server=localhost;user id=sa;password=yourStrong(!)Password;database=xorm_test" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic
|
||||
- run: go test -v -race -db="mysql" -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true -coverprofile=coverage7-1.txt -covermode=atomic
|
||||
- run: go test -v -race -db="mysql" -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true -cache=true -coverprofile=coverage7-2.txt -covermode=atomic
|
||||
- run: 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 coverage6-2.txt coverage7-1.txt coverage7-2.txt > coverage.txt
|
||||
- run: go test -v -race -db="postgres" -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable" -coverprofile=coverage8-1.txt -covermode=atomic
|
||||
- run: go test -v -race -db="postgres" -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable" -cache=true -coverprofile=coverage8-2.txt -covermode=atomic
|
||||
- run: 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 coverage6-2.txt coverage7-1.txt coverage7-2.txt coverage8-1.txt coverage8-2.txt > coverage.txt
|
||||
|
||||
- run: bash <(curl -s https://codecov.io/bash)
|
24
.drone.yml
24
.drone.yml
|
@ -505,8 +505,24 @@ steps:
|
|||
commands:
|
||||
- "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -coverprofile=coverage6-1.txt -covermode=atomic"
|
||||
- "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic"
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
- name: init_cockroach
|
||||
pull: default
|
||||
image: cockroachdb/cockroach:v2.0.6
|
||||
commands:
|
||||
- cockroach sql --insecure --execute="create database xorm_test"
|
||||
|
||||
- name: test-cockroach
|
||||
image: golang:1.12
|
||||
commands:
|
||||
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -coverprofile=coverage7-1.txt -covermode=atomic
|
||||
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@cockroach/xorm_test?sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage7-2.txt -covermode=atomic
|
||||
- go get -u github.com/wadey/gocovmerge
|
||||
- gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt > coverage.txt
|
||||
- gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt coverage7-1.txt coverage7-2.txt > coverage.txt
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
|
@ -549,3 +565,9 @@ services:
|
|||
- push
|
||||
- tag
|
||||
- pull_request
|
||||
|
||||
- name: cockroach
|
||||
pull: default
|
||||
image: cockroachdb/cockroach:v2.0.6
|
||||
when:
|
||||
event: [push, tag, pull_request]
|
||||
|
|
|
@ -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.1.3.linux-amd64.tgz | tar xvz
|
||||
- ./cockroach-v2.1.3.linux-amd64/cockroach start --insecure --background --host=localhost
|
||||
- sleep 5
|
||||
- ./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
|
||||
- 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)
|
|
@ -1019,8 +1019,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 = core.SQLType{Name: core.Varchar, DefaultLength: 0, DefaultLength2: 0}
|
||||
case "timestamp without time zone":
|
||||
col.SQLType = core.SQLType{Name: core.DateTime, DefaultLength: 0, DefaultLength2: 0}
|
||||
|
@ -1032,13 +1032,22 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att
|
|||
col.SQLType = core.SQLType{Name: core.Bool, DefaultLength: 0, DefaultLength2: 0}
|
||||
case "time without time zone":
|
||||
col.SQLType = core.SQLType{Name: core.Time, DefaultLength: 0, DefaultLength2: 0}
|
||||
case "bytes":
|
||||
col.SQLType = core.SQLType{Name: core.Binary, DefaultLength: 0, DefaultLength2: 0}
|
||||
case "oid":
|
||||
col.SQLType = core.SQLType{Name: core.BigInt, DefaultLength: 0, DefaultLength2: 0}
|
||||
default:
|
||||
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 = core.SQLType{Name: "STRING", DefaultLength: l, DefaultLength2: 0}
|
||||
} else {
|
||||
col.SQLType = core.SQLType{Name: strings.ToUpper(dataType), DefaultLength: 0, DefaultLength2: 0}
|
||||
}
|
||||
}
|
||||
if _, ok := core.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
|
||||
|
@ -1124,6 +1133,10 @@ func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if indexName == "primary" {
|
||||
continue
|
||||
}
|
||||
indexName = strings.Trim(indexName, `" `)
|
||||
if strings.HasSuffix(indexName, "_pkey") {
|
||||
continue
|
||||
|
@ -1145,7 +1158,7 @@ func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error)
|
|||
|
||||
index := &core.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
|
||||
|
|
11
engine.go
11
engine.go
|
@ -398,12 +398,19 @@ func (engine *Engine) DBMetas() ([]*core.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 nil, fmt.Errorf("Unknown col %s in index %v of table %v, columns %v", name, index.Name, table.Name, table.ColumnsSeq())
|
||||
return nil, fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
go test -db=postgres -conn_str="user=root port=26257 dbname=xorm_test sslmode=disable"
|
10
xorm_test.go
10
xorm_test.go
|
@ -54,11 +54,11 @@ func createEngine(dbType, connStr string) error {
|
|||
db.Close()
|
||||
*ignoreSelectUpdate = true
|
||||
case core.POSTGRES:
|
||||
db, err := sql.Open(dbType, connStr)
|
||||
db, err := sql.Open(dbType, strings.Replace(connStr, "xorm_test", "postgres", -1))
|
||||
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)
|
||||
}
|
||||
|
@ -70,6 +70,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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue