Fix tests
This commit is contained in:
parent
7aff5dd693
commit
3ea0cca87f
|
@ -284,7 +284,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
|||
case schemas.TimeStampz:
|
||||
res = "DATETIMEOFFSET"
|
||||
c.Length = 7
|
||||
case schemas.MediumInt:
|
||||
case schemas.MediumInt, schemas.UnsignedInt:
|
||||
res = schemas.Int
|
||||
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
|
||||
res = db.defaultVarchar + "(MAX)"
|
||||
|
@ -296,7 +296,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
|||
case schemas.TinyInt:
|
||||
res = schemas.TinyInt
|
||||
c.Length = 0
|
||||
case schemas.BigInt:
|
||||
case schemas.BigInt, schemas.UnsignedBigInt:
|
||||
res = schemas.BigInt
|
||||
c.Length = 0
|
||||
case schemas.NVarchar:
|
||||
|
|
|
@ -254,6 +254,10 @@ func (db *mysql) SQLType(c *schemas.Column) string {
|
|||
c.Length = 40
|
||||
case schemas.Json:
|
||||
res = schemas.Text
|
||||
case schemas.UnsignedInt:
|
||||
res = schemas.Int
|
||||
case schemas.UnsignedBigInt:
|
||||
res = schemas.BigInt
|
||||
default:
|
||||
res = t
|
||||
}
|
||||
|
@ -271,6 +275,11 @@ func (db *mysql) SQLType(c *schemas.Column) string {
|
|||
} else if hasLen1 {
|
||||
res += "(" + strconv.Itoa(c.Length) + ")"
|
||||
}
|
||||
|
||||
if c.SQLType.Name == schemas.UnsignedBigInt || c.SQLType.Name == schemas.UnsignedInt {
|
||||
res += " UNSIGNED"
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -331,16 +340,16 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
col := new(schemas.Column)
|
||||
col.Indexes = make(map[string]int)
|
||||
|
||||
var columnName, isNullable, colType, colKey, extra, comment string
|
||||
var alreadyQuoted bool
|
||||
var columnName, nullableStr, colType, colKey, extra, comment string
|
||||
var alreadyQuoted, isUnsigned bool
|
||||
var colDefault *string
|
||||
err = rows.Scan(&columnName, &isNullable, &colDefault, &colType, &colKey, &extra, &comment, &alreadyQuoted)
|
||||
err = rows.Scan(&columnName, &nullableStr, &colDefault, &colType, &colKey, &extra, &comment, &alreadyQuoted)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
col.Name = strings.Trim(columnName, "` ")
|
||||
col.Comment = comment
|
||||
if "YES" == isNullable {
|
||||
if nullableStr == "YES" {
|
||||
col.Nullable = true
|
||||
}
|
||||
|
||||
|
@ -351,6 +360,11 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
col.DefaultIsEmpty = true
|
||||
}
|
||||
|
||||
fields := strings.Fields(colType)
|
||||
if len(fields) == 2 && fields[1] == "unsigned" {
|
||||
isUnsigned = true
|
||||
}
|
||||
colType = fields[0]
|
||||
cts := strings.Split(colType, "(")
|
||||
colName := cts[0]
|
||||
// Remove the /* mariadb-5.3 */ suffix from coltypes
|
||||
|
@ -389,11 +403,8 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
}
|
||||
}
|
||||
}
|
||||
if colType == "FLOAT UNSIGNED" {
|
||||
colType = "FLOAT"
|
||||
}
|
||||
if colType == "DOUBLE UNSIGNED" {
|
||||
colType = "DOUBLE"
|
||||
if isUnsigned {
|
||||
colType = "UNSIGNED " + colType
|
||||
}
|
||||
col.Length = len1
|
||||
col.Length2 = len2
|
||||
|
|
|
@ -833,12 +833,12 @@ func (db *postgres) SQLType(c *schemas.Column) string {
|
|||
case schemas.Bit:
|
||||
res = schemas.Boolean
|
||||
return res
|
||||
case schemas.MediumInt, schemas.Int, schemas.Integer:
|
||||
case schemas.MediumInt, schemas.Int, schemas.Integer, schemas.UnsignedInt:
|
||||
if c.IsAutoIncrement {
|
||||
return schemas.Serial
|
||||
}
|
||||
return schemas.Integer
|
||||
case schemas.BigInt:
|
||||
case schemas.BigInt, schemas.UnsignedBigInt:
|
||||
if c.IsAutoIncrement {
|
||||
return schemas.BigSerial
|
||||
}
|
||||
|
|
|
@ -149,40 +149,6 @@ var (
|
|||
Suffix: '`',
|
||||
IsReserved: schemas.AlwaysReserve,
|
||||
}
|
||||
|
||||
sqlite3Types = map[string]int{
|
||||
"INT": schemas.NUMERIC_TYPE,
|
||||
"INTEGER": schemas.NUMERIC_TYPE,
|
||||
"TINYINT": schemas.NUMERIC_TYPE,
|
||||
"SMALLINT": schemas.NUMERIC_TYPE,
|
||||
"MEDIUMINT": schemas.NUMERIC_TYPE,
|
||||
"BIGINT": schemas.NUMERIC_TYPE,
|
||||
"UNSIGNED BIG INT": schemas.NUMERIC_TYPE,
|
||||
"INT2": schemas.NUMERIC_TYPE,
|
||||
"INT8": schemas.NUMERIC_TYPE,
|
||||
|
||||
"REAL": schemas.NUMERIC_TYPE,
|
||||
"DOUBLE": schemas.NUMERIC_TYPE,
|
||||
"DOUBLE PRECISION": schemas.NUMERIC_TYPE,
|
||||
"FLOAT": schemas.NUMERIC_TYPE,
|
||||
"NUMERIC": schemas.NUMERIC_TYPE,
|
||||
"DECIMAL": schemas.NUMERIC_TYPE,
|
||||
"BOOLEAN": schemas.NUMERIC_TYPE,
|
||||
|
||||
"CHARACTER": schemas.TEXT_TYPE,
|
||||
"VARCHAR": schemas.TEXT_TYPE,
|
||||
"VARYING CHARACTER": schemas.TEXT_TYPE,
|
||||
"NCHAR": schemas.TEXT_TYPE,
|
||||
"NATIVE CHARACTER": schemas.TEXT_TYPE,
|
||||
"NVARCHAR": schemas.TEXT_TYPE,
|
||||
"TEXT": schemas.TEXT_TYPE,
|
||||
"CLOB": schemas.TEXT_TYPE,
|
||||
|
||||
"BLOB": schemas.BLOB_TYPE,
|
||||
|
||||
"DATE": schemas.TIME_TYPE,
|
||||
"DATETIME": schemas.TIME_TYPE,
|
||||
}
|
||||
)
|
||||
|
||||
type sqlite3 struct {
|
||||
|
@ -227,7 +193,8 @@ func (db *sqlite3) SQLType(c *schemas.Column) string {
|
|||
case schemas.Char, schemas.Varchar, schemas.NVarchar, schemas.TinyText,
|
||||
schemas.Text, schemas.MediumText, schemas.LongText, schemas.Json:
|
||||
return schemas.Text
|
||||
case schemas.Bit, schemas.TinyInt, schemas.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt:
|
||||
case schemas.Bit, schemas.TinyInt, schemas.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt,
|
||||
schemas.UnsignedBigInt, schemas.UnsignedInt:
|
||||
return schemas.Integer
|
||||
case schemas.Float, schemas.Double, schemas.Real:
|
||||
return schemas.Real
|
||||
|
|
|
@ -393,7 +393,12 @@ func TestUnsigned(t *testing.T) {
|
|||
case schemas.SQLITE:
|
||||
assert.EqualValues(t, "INTEGER", tables[0].Columns()[0].SQLType.Name)
|
||||
case schemas.MYSQL:
|
||||
assert.EqualValues(t, "unsigned int", tables[0].Columns()[0].SQLType.Name)
|
||||
assert.EqualValues(t, "UNSIGNED BIGINT", tables[0].Columns()[0].SQLType.Name)
|
||||
case schemas.POSTGRES:
|
||||
assert.EqualValues(t, "BIGINT", tables[0].Columns()[0].SQLType.Name)
|
||||
case schemas.MSSQL:
|
||||
assert.EqualValues(t, "BIGINT", tables[0].Columns()[0].SQLType.Name)
|
||||
default:
|
||||
assert.False(t, true, "Unsigned is not implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,6 +80,8 @@ var (
|
|||
Int = "INT"
|
||||
Integer = "INTEGER"
|
||||
BigInt = "BIGINT"
|
||||
UnsignedInt = "UNSIGNED INT"
|
||||
UnsignedBigInt = "UNSIGNED BIGINT"
|
||||
|
||||
Enum = "ENUM"
|
||||
Set = "SET"
|
||||
|
@ -143,6 +145,8 @@ var (
|
|||
Int: NUMERIC_TYPE,
|
||||
Integer: NUMERIC_TYPE,
|
||||
BigInt: NUMERIC_TYPE,
|
||||
UnsignedInt: NUMERIC_TYPE,
|
||||
UnsignedBigInt: NUMERIC_TYPE,
|
||||
|
||||
Enum: TEXT_TYPE,
|
||||
Set: TEXT_TYPE,
|
||||
|
@ -280,10 +284,14 @@ var (
|
|||
// Type2SQLType generate SQLType acorrding Go's type
|
||||
func Type2SQLType(t reflect.Type) (st SQLType) {
|
||||
switch k := t.Kind(); k {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32:
|
||||
st = SQLType{Int, 0, 0}
|
||||
case reflect.Int64, reflect.Uint64:
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
|
||||
st = SQLType{UnsignedInt, 0, 0}
|
||||
case reflect.Int64:
|
||||
st = SQLType{BigInt, 0, 0}
|
||||
case reflect.Uint64:
|
||||
st = SQLType{UnsignedBigInt, 0, 0}
|
||||
case reflect.Float32:
|
||||
st = SQLType{Float, 0, 0}
|
||||
case reflect.Float64:
|
||||
|
|
Loading…
Reference in New Issue