Repository: ariga/atlas
Pull request #373 (2022-01-05 17:18:22)

sql/mysql: export column types for external usage


Patch:
diff --git a/sql/mysql/convert.go b/sql/mysql/convert.go
index 516e7697..b6f13fa3 100644
--- a/sql/mysql/convert.go
+++ b/sql/mysql/convert.go
@@ -27,12 +27,12 @@ func FormatType(t schema.Type) (string, error) {
 		}
 	case *schema.BinaryType:
 		f = strings.ToLower(t.T)
-		if f == tVarBinary {
+		if f == TypeVarBinary {
 			// Zero is also a valid length.
 			f = fmt.Sprintf("%s(%d)", f, t.Size)
 		}
 	case *schema.DecimalType:
-		if f = strings.ToLower(t.T); f != tDecimal && f != tNumeric {
+		if f = strings.ToLower(t.T); f != TypeDecimal && f != TypeNumeric {
 			return "", fmt.Errorf("mysql: unexpected decimal type: %q", t.T)
 		}
 		switch p, s := t.Precision, t.Scale; {
@@ -56,8 +56,8 @@ func FormatType(t schema.Type) (string, error) {
 		f = strings.ToLower(t.T)
 		// FLOAT with precision > 24, become DOUBLE.
 		// Also, REAL is a synonym for DOUBLE (if REAL_AS_FLOAT was not set).
-		if f == tFloat && t.Precision > 24 || f == tReal {
-			f = tDouble
+		if f == TypeFloat && t.Precision > 24 || f == TypeReal {
+			f = TypeDouble
 		}
 	case *schema.IntegerType:
 		f = strings.ToLower(t.T)
@@ -70,7 +70,7 @@ func FormatType(t schema.Type) (string, error) {
 		f = fmt.Sprintf("enum(%s)", formatValues(t.Values))
 	case *schema.StringType:
 		f = strings.ToLower(t.T)
-		if f == tChar || f == tVarchar {
+		if f == TypeChar || f == TypeVarchar {
 			// Zero is also a valid length.
 			f = fmt.Sprintf("%s(%d)", f, t.Size)
 		}
diff --git a/sql/mysql/driver.go b/sql/mysql/driver.go
index 13db7a03..07c6e9ff 100644
--- a/sql/mysql/driver.go
+++ b/sql/mysql/driver.go
@@ -130,51 +130,51 @@ func unescape(s string) string {
 // https://github.com/mysql/mysql-server/blob/8.0/sql/sql_show.cc
 // https://github.com/mysql/mysql-server/blob/8.0/sql/gis/geometries.cc
 const (
-	tBit       = "bit"       // MYSQL_TYPE_BIT
-	tInt       = "int"       // MYSQL_TYPE_LONG
-	tTinyInt   = "tinyint"   // MYSQL_TYPE_TINY
-	tSmallInt  = "smallint"  // MYSQL_TYPE_SHORT
-	tMediumInt = "mediumint" // MYSQL_TYPE_INT24
-	tBigInt    = "bigint"    // MYSQL_TYPE_LONGLONG
-
-	tDecimal = "decimal" // MYSQL_TYPE_DECIMAL
-	tNumeric = "numeric" // MYSQL_TYPE_DECIMAL (numeric_type rule in sql_yacc.yy)
-	tFloat   = "float"   // MYSQL_TYPE_FLOAT
-	tDouble  = "double"  // MYSQL_TYPE_DOUBLE
-	tReal    = "real"    // MYSQL_TYPE_FLOAT or MYSQL_TYPE_DOUBLE (real_type in sql_yacc.yy)
-
-	tTimestamp = "timestamp" // MYSQL_TYPE_TIMESTAMP
-	tDate      = "date"      // MYSQL_TYPE_DATE
-	tTime      = "time"      // MYSQL_TYPE_TIME
-	tDateTime  = "datetime"  // MYSQL_TYPE_DATETIME
-	tYear      = "year"      // MYSQL_TYPE_YEAR
-
-	tVarchar    = "varchar"    // MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VARCHAR
-	tChar       = "char"       // MYSQL_TYPE_STRING
-	tVarBinary  = "varbinary"  // MYSQL_TYPE_VAR_STRING + NULL CHARACTER_SET.
-	tBinary     = "binary"     // MYSQL_TYPE_STRING + NULL CHARACTER_SET.
-	tBlob       = "blob"       // MYSQL_TYPE_BLOB
-	tTinyBlob   = "tinyblob"   // MYSQL_TYPE_TINYBLOB
-	tMediumBlob = "mediumblob" // MYSQL_TYPE_MEDIUM_BLOB
-	tLongBlob   = "longblob"   // MYSQL_TYPE_LONG_BLOB
-	tText       = "text"       // MYSQL_TYPE_BLOB + CHARACTER_SET utf8mb4
-	tTinyText   = "tinytext"   // MYSQL_TYPE_TINYBLOB + CHARACTER_SET utf8mb4
-	tMediumText = "mediumtext" // MYSQL_TYPE_MEDIUM_BLOB + CHARACTER_SET utf8mb4
-	tLongText   = "longtext"   // MYSQL_TYPE_LONG_BLOB with + CHARACTER_SET utf8mb4
-
-	tEnum = "enum" // MYSQL_TYPE_ENUM
-	tSet  = "set"  // MYSQL_TYPE_SET
-	tJSON = "json" // MYSQL_TYPE_JSON
-
-	tGeometry           = "geometry"           // MYSQL_TYPE_GEOMETRY
-	tPoint              = "point"              // Geometry_type::kPoint
-	tMultiPoint         = "multipoint"         // Geometry_type::kMultipoint
-	tLineString         = "linestring"         // Geometry_type::kLinestring
-	tMultiLineString    = "multilinestring"    // Geometry_type::kMultilinestring
-	tPolygon            = "polygon"            // Geometry_type::kPolygon
-	tMultiPolygon       = "multipolygon"       // Geometry_type::kMultipolygon
-	tGeoCollection      = "geomcollection"     // Geometry_type::kGeometrycollection
-	tGeometryCollection = "geometrycollection" // Geometry_type::kGeometrycollection
+	TypeBit       = "bit"       // MYSQL_TYPE_BIT
+	TypeInt       = "int"       // MYSQL_TYPE_LONG
+	TypeTinyInt   = "tinyint"   // MYSQL_TYPE_TINY
+	TypeSmallInt  = "smallint"  // MYSQL_TYPE_SHORT
+	TypeMediumInt = "mediumint" // MYSQL_TYPE_INT24
+	TypeBigInt    = "bigint"    // MYSQL_TYPE_LONGLONG
+
+	TypeDecimal = "decimal" // MYSQL_TYPE_DECIMAL
+	TypeNumeric = "numeric" // MYSQL_TYPE_DECIMAL (numeric_type rule in sql_yacc.yy)
+	TypeFloat   = "float"   // MYSQL_TYPE_FLOAT
+	TypeDouble  = "double"  // MYSQL_TYPE_DOUBLE
+	TypeReal    = "real"    // MYSQL_TYPE_FLOAT or MYSQL_TYPE_DOUBLE (real_type in sql_yacc.yy)
+
+	TypeTimestamp = "timestamp" // MYSQL_TYPE_TIMESTAMP
+	TypeDate      = "date"      // MYSQL_TYPE_DATE
+	TypeTime      = "time"      // MYSQL_TYPE_TIME
+	TypeDateTime  = "datetime"  // MYSQL_TYPE_DATETIME
+	TypeYear      = "year"      // MYSQL_TYPE_YEAR
+
+	TypeVarchar    = "varchar"    // MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VARCHAR
+	TypeChar       = "char"       // MYSQL_TYPE_STRING
+	TypeVarBinary  = "varbinary"  // MYSQL_TYPE_VAR_STRING + NULL CHARACTER_SET.
+	TypeBinary     = "binary"     // MYSQL_TYPE_STRING + NULL CHARACTER_SET.
+	TypeBlob       = "blob"       // MYSQL_TYPE_BLOB
+	TypeTinyBlob   = "tinyblob"   // MYSQL_TYPE_TINYBLOB
+	TypeMediumBlob = "mediumblob" // MYSQL_TYPE_MEDIUM_BLOB
+	TypeLongBlob   = "longblob"   // MYSQL_TYPE_LONG_BLOB
+	TypeText       = "text"       // MYSQL_TYPE_BLOB + CHARACTER_SET utf8mb4
+	TypeTinyText   = "tinytext"   // MYSQL_TYPE_TINYBLOB + CHARACTER_SET utf8mb4
+	TypeMediumText = "mediumtext" // MYSQL_TYPE_MEDIUM_BLOB + CHARACTER_SET utf8mb4
+	TypeLongText   = "longtext"   // MYSQL_TYPE_LONG_BLOB with + CHARACTER_SET utf8mb4
+
+	TypeEnum = "enum" // MYSQL_TYPE_ENUM
+	TypeSet  = "set"  // MYSQL_TYPE_SET
+	TypeJSON = "json" // MYSQL_TYPE_JSON
+
+	TypeGeometry           = "geometry"           // MYSQL_TYPE_GEOMETRY
+	TypePoint              = "point"              // Geometry_type::kPoint
+	TypeMultiPoint         = "multipoint"         // Geometry_type::kMultipoint
+	TypeLineString         = "linestring"         // Geometry_type::kLinestring
+	TypeMultiLineString    = "multilinestring"    // Geometry_type::kMultilinestring
+	TypePolygon            = "polygon"            // Geometry_type::kPolygon
+	TypeMultiPolygon       = "multipolygon"       // Geometry_type::kMultipolygon
+	TypeGeoCollection      = "geomcollection"     // Geometry_type::kGeometrycollection
+	TypeGeometryCollection = "geometrycollection" // Geometry_type::kGeometrycollection
 )
 
 // Additional common constants in MySQL.
diff --git a/sql/mysql/inspect.go b/sql/mysql/inspect.go
index 0899a9b2..307f0100 100644
--- a/sql/mysql/inspect.go
+++ b/sql/mysql/inspect.go
@@ -268,11 +268,11 @@ func parseRawType(raw string) (schema.Type, error) {
 		return nil, err
 	}
 	switch t := parts[0]; t {
-	case tBit:
+	case TypeBit:
 		return &BitType{
 			T: t,
 		}, nil
-	case tTinyInt, tSmallInt, tMediumInt, tInt, tBigInt:
+	case TypeTinyInt, TypeSmallInt, TypeMediumInt, TypeInt, TypeBigInt:
 		if size == 1 {
 			return &schema.BoolType{
 				T: t,
@@ -297,7 +297,7 @@ func parseRawType(raw string) (schema.Type, error) {
 			}
 		}
 		return ft, nil
-	case tNumeric, tDecimal:
+	case TypeNumeric, TypeDecimal:
 		dt := &schema.DecimalType{
 			T: t,
 		}
@@ -316,7 +316,7 @@ func parseRawType(raw string) (schema.Type, error) {
 			dt.Scale = int(s)
 		}
 		return dt, nil
-	case tFloat, tDouble, tReal:
+	case TypeFloat, TypeDouble, TypeReal:
 		ft := &schema.FloatType{
 			T: t,
 		}
@@ -328,25 +328,25 @@ func parseRawType(raw string) (schema.Type, error) {
 			ft.Precision = int(p)
 		}
 		return ft, nil
-	case tBinary, tVarBinary:
+	case TypeBinary, TypeVarBinary:
 		return &schema.BinaryType{
 			T:    t,
 			Size: int(size),
 		}, nil
-	case tTinyBlob, tMediumBlob, tBlob, tLongBlob:
+	case TypeTinyBlob, TypeMediumBlob, TypeBlob, TypeLongBlob:
 		return &schema.BinaryType{
 			T: t,
 		}, nil
-	case tChar, tVarchar:
+	case TypeChar, TypeVarchar:
 		return &schema.StringType{
 			T:    t,
 			Size: int(size),
 		}, nil
-	case tTinyText, tMediumText, tText, tLongText:
+	case TypeTinyText, TypeMediumText, TypeText, TypeLongText:
 		return &schema.StringType{
 			T: t,
 		}, nil
-	case tEnum, tSet:
+	case TypeEnum, TypeSet:
 		// Parse the enum values according to the MySQL format.
 		// github.com/mysql/mysql-server/blob/8.0/sql/field.cc#Field_enum::sql_type
 		rv := strings.TrimSuffix(strings.TrimPrefix(raw, t+"("), ")")
@@ -357,7 +357,7 @@ func parseRawType(raw string) (schema.Type, error) {
 		for i := range values {
 			values[i] = strings.Trim(values[i], "'")
 		}
-		if t == tEnum {
+		if t == TypeEnum {
 			return &schema.EnumType{
 				Values: values,
 			}, nil
@@ -365,15 +365,15 @@ func parseRawType(raw string) (schema.Type, error) {
 		return &SetType{
 			Values: values,
 		}, nil
-	case tDate, tDateTime, tTime, tTimestamp, tYear:
+	case TypeDate, TypeDateTime, TypeTime, TypeTimestamp, TypeYear:
 		return &schema.TimeType{
 			T: t,
 		}, nil
-	case tJSON:
+	case TypeJSON:
 		return &schema.JSONType{
 			T: t,
 		}, nil
-	case tPoint, tMultiPoint, tLineString, tMultiLineString, tPolygon, tMultiPolygon, tGeometry, tGeoCollection, tGeometryCollection:
+	case TypePoint, TypeMultiPoint, TypeLineString, TypeMultiLineString, TypePolygon, TypeMultiPolygon, TypeGeometry, TypeGeoCollection, TypeGeometryCollection:
 		return &schema.SpatialType{
 			T: t,
 		}, nil
@@ -513,9 +513,9 @@ func (i *inspect) checks(ctx context.Context, t *schema.Table) error {
 		// Ent to manually add this CHECK for older versions of MariaDB.
 		if i.mariadb() {
 			c, ok := t.Column(check.Name)
-			if ok && c.Type.Raw == tLongText && check.Expr == fmt.Sprintf("json_valid(`%s`)", c.Name) {
-				c.Type.Raw = tJSON
-				c.Type.Type = &schema.JSONType{T: tJSON}
+			if ok && c.Type.Raw == TypeLongText && check.Expr == fmt.Sprintf("json_valid(`%s`)", c.Name) {
+				c.Type.Raw = TypeJSON
+				c.Type.Type = &schema.JSONType{T: TypeJSON}
 			}
 		}
 
@@ -548,14 +548,14 @@ func parseColumn(typ string) (parts []string, size int64, unsigned bool, err err
 	switch parts = strings.FieldsFunc(typ, func(r rune) bool {
 		return r == '(' || r == ')' || r == ' ' || r == ','
 	}); parts[0] {
-	case tTinyInt, tSmallInt, tMediumInt, tInt, tBigInt:
+	case TypeTinyInt, TypeSmallInt, TypeMediumInt, TypeInt, TypeBigInt:
 		if attr := parts[len(parts)-1]; attr == "unsigned" || attr == "zerofill" {
 			unsigned = true
 		}
 		if len(parts) > 2 || len(parts) == 2 && !unsigned {
 			size, err = strconv.ParseInt(parts[1], 10, 64)
 		}
-	case tBinary, tVarBinary, tChar, tVarchar:
+	case TypeBinary, TypeVarBinary, TypeChar, TypeVarchar:
 		size, err = strconv.ParseInt(parts[1], 10, 64)
 	}
 	if err != nil {
diff --git a/sql/mysql/sqlspec.go b/sql/mysql/sqlspec.go
index 1675e51f..92614a1f 100644
--- a/sql/mysql/sqlspec.go
+++ b/sql/mysql/sqlspec.go
@@ -226,57 +226,57 @@ var TypeRegistry = specutil.NewRegistry(
 	specutil.WithParser(parseRawType),
 	specutil.WithSpecs(
 		&schemaspec.TypeSpec{
-			Name: tEnum,
-			T:    tEnum,
+			Name: TypeEnum,
+			T:    TypeEnum,
 			Attributes: []*schemaspec.TypeAttr{
 				{Name: "values", Kind: reflect.Slice, Required: true},
 			},
 			RType: reflect.TypeOf(schema.EnumType{}),
 		},
 		&schemaspec.TypeSpec{
-			Name: tSet,
-			T:    tSet,
+			Name: TypeSet,
+			T:    TypeSet,
 			Attributes: []*schemaspec.TypeAttr{
 				{Name: "values", Kind: reflect.Slice, Required: true},
 			},
 			RType: reflect.TypeOf(SetType{}),
 		},
-		specutil.TypeSpec(tBit, specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tTinyInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tSmallInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tMediumInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tBigInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tDecimal),
-		specutil.TypeSpec(tNumeric),
-		specutil.TypeSpec(tFloat, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
-		specutil.TypeSpec(tDouble, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
-		specutil.TypeSpec(tReal, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
-		specutil.TypeSpec(tTimestamp),
-		specutil.TypeSpec(tDate),
-		specutil.TypeSpec(tTime),
-		specutil.TypeSpec(tDateTime),
-		specutil.TypeSpec(tYear),
-		specutil.TypeSpec(tVarchar, specutil.SizeTypeAttr(true)),
-		specutil.TypeSpec(tChar, specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tVarBinary, specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tBinary, specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tBlob, specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tTinyBlob),
-		specutil.TypeSpec(tMediumBlob),
-		specutil.TypeSpec(tLongBlob),
-		specutil.TypeSpec(tText, specutil.SizeTypeAttr(false)),
-		specutil.TypeSpec(tTinyText),
-		specutil.TypeSpec(tMediumText),
-		specutil.TypeSpec(tLongText),
-		specutil.TypeSpec(tGeometry),
-		specutil.TypeSpec(tPoint),
-		specutil.TypeSpec(tMultiPoint),
-		specutil.TypeSpec(tLineString),
-		specutil.TypeSpec(tMultiLineString),
-		specutil.TypeSpec(tPolygon),
-		specutil.TypeSpec(tMultiPolygon),
-		specutil.TypeSpec(tGeometryCollection),
+		specutil.TypeSpec(TypeBit, specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeTinyInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeSmallInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeMediumInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeBigInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeDecimal),
+		specutil.TypeSpec(TypeNumeric),
+		specutil.TypeSpec(TypeFloat, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
+		specutil.TypeSpec(TypeDouble, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
+		specutil.TypeSpec(TypeReal, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
+		specutil.TypeSpec(TypeTimestamp),
+		specutil.TypeSpec(TypeDate),
+		specutil.TypeSpec(TypeTime),
+		specutil.TypeSpec(TypeDateTime),
+		specutil.TypeSpec(TypeYear),
+		specutil.TypeSpec(TypeVarchar, specutil.SizeTypeAttr(true)),
+		specutil.TypeSpec(TypeChar, specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeVarBinary, specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeBinary, specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeBlob, specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeTinyBlob),
+		specutil.TypeSpec(TypeMediumBlob),
+		specutil.TypeSpec(TypeLongBlob),
+		specutil.TypeSpec(TypeText, specutil.SizeTypeAttr(false)),
+		specutil.TypeSpec(TypeTinyText),
+		specutil.TypeSpec(TypeMediumText),
+		specutil.TypeSpec(TypeLongText),
+		specutil.TypeSpec(TypeGeometry),
+		specutil.TypeSpec(TypePoint),
+		specutil.TypeSpec(TypeMultiPoint),
+		specutil.TypeSpec(TypeLineString),
+		specutil.TypeSpec(TypeMultiLineString),
+		specutil.TypeSpec(TypePolygon),
+		specutil.TypeSpec(TypeMultiPolygon),
+		specutil.TypeSpec(TypeGeometryCollection),
 	),
 )
 


Test patch:
diff --git a/sql/mysql/sqlspec_test.go b/sql/mysql/sqlspec_test.go
index a7b17de1..5962fd49 100644
--- a/sql/mysql/sqlspec_test.go
+++ b/sql/mysql/sqlspec_test.go
@@ -69,7 +69,7 @@ table "accounts" {
 					Name: "col",
 					Type: &schema.ColumnType{
 						Type: &schema.IntegerType{
-							T: tInt,
+							T: TypeInt,
 						},
 					},
 				},
@@ -77,7 +77,7 @@ table "accounts" {
 					Name: "age",
 					Type: &schema.ColumnType{
 						Type: &schema.IntegerType{
-							T: tInt,
+							T: TypeInt,
 						},
 					},
 				},
@@ -85,7 +85,7 @@ table "accounts" {
 					Name: "account_name",
 					Type: &schema.ColumnType{
 						Type: &schema.StringType{
-							T:    tVarchar,
+							T:    TypeVarchar,
 							Size: 32,
 						},
 					},
@@ -100,7 +100,7 @@ table "accounts" {
 					Name: "name",
 					Type: &schema.ColumnType{
 						Type: &schema.StringType{
-							T:    tVarchar,
+							T:    TypeVarchar,
 							Size: 32,
 						},
 					},
@@ -280,84 +280,84 @@ func TestTypes(t *testing.T) {
 	}{
 		{
 			typeExpr: "varchar(255)",
-			expected: &schema.StringType{T: tVarchar, Size: 255},
+			expected: &schema.StringType{T: TypeVarchar, Size: 255},
 		},
 		{
 			typeExpr: "char(255)",
-			expected: &schema.StringType{T: tChar, Size: 255},
+			expected: &schema.StringType{T: TypeChar, Size: 255},
 		},
 		{
 			typeExpr: "binary(255)",
-			expected: &schema.BinaryType{T: tBinary, Size: 255},
+			expected: &schema.BinaryType{T: TypeBinary, Size: 255},
 		},
 		{
 			typeExpr: "varbinary(255)",
-			expected: &schema.BinaryType{T: tVarBinary, Size: 255},
+			expected: &schema.BinaryType{T: TypeVarBinary, Size: 255},
 		},
 		{
 			typeExpr: "int",
-			expected: &schema.IntegerType{T: tInt},
+			expected: &schema.IntegerType{T: TypeInt},
 		},
 		{
 			typeExpr:  "int",
 			extraAttr: "unsigned=true",
-			expected:  &schema.IntegerType{T: tInt, Unsigned: true},
+			expected:  &schema.IntegerType{T: TypeInt, Unsigned: true},
 		},
 		{
 			typeExpr: "int",
-			expected: &schema.IntegerType{T: tInt},
+			expected: &schema.IntegerType{T: TypeInt},
 		},
 		{
 			typeExpr: "bigint",
-			expected: &schema.IntegerType{T: tBigInt},
+			expected: &schema.IntegerType{T: TypeBigInt},
 		},
 		{
 			typeExpr:  "bigint",
 			extraAttr: "unsigned=true",
-			expected:  &schema.IntegerType{T: tBigInt, Unsigned: true},
+			expected:  &schema.IntegerType{T: TypeBigInt, Unsigned: true},
 		},
 		{
 			typeExpr: "tinyint",
-			expected: &schema.IntegerType{T: tTinyInt},
+			expected: &schema.IntegerType{T: TypeTinyInt},
 		},
 		{
 			typeExpr:  "tinyint",
 			extraAttr: "unsigned=true",
-			expected:  &schema.IntegerType{T: tTinyInt, Unsigned: true},
+			expected:  &schema.IntegerType{T: TypeTinyInt, Unsigned: true},
 		},
 		{
 			typeExpr: "smallint",
-			expected: &schema.IntegerType{T: tSmallInt},
+			expected: &schema.IntegerType{T: TypeSmallInt},
 		},
 		{
 			typeExpr:  "smallint",
 			extraAttr: "unsigned=true",
-			expected:  &schema.IntegerType{T: tSmallInt, Unsigned: true},
+			expected:  &schema.IntegerType{T: TypeSmallInt, Unsigned: true},
 		},
 		{
 			typeExpr: "mediumint",
-			expected: &schema.IntegerType{T: tMediumInt},
+			expected: &schema.IntegerType{T: TypeMediumInt},
 		},
 		{
 			typeExpr:  "mediumint",
 			extraAttr: "unsigned=true",
-			expected:  &schema.IntegerType{T: tMediumInt, Unsigned: true},
+			expected:  &schema.IntegerType{T: TypeMediumInt, Unsigned: true},
 		},
 		{
 			typeExpr: "tinytext",
-			expected: &schema.StringType{T: tTinyText},
+			expected: &schema.StringType{T: TypeTinyText},
 		},
 		{
 			typeExpr: "mediumtext",
-			expected: &schema.StringType{T: tMediumText},
+			expected: &schema.StringType{T: TypeMediumText},
 		},
 		{
 			typeExpr: "longtext",
-			expected: &schema.StringType{T: tLongText},
+			expected: &schema.StringType{T: TypeLongText},
 		},
 		{
 			typeExpr: "text",
-			expected: &schema.StringType{T: tText},
+			expected: &schema.StringType{T: TypeText},
 		},
 		{
 			typeExpr: `enum("on","off")`,
@@ -365,115 +365,115 @@ func TestTypes(t *testing.T) {
 		},
 		{
 			typeExpr: "bit(10)",
-			expected: &BitType{T: tBit},
+			expected: &BitType{T: TypeBit},
 		},
 		{
 			typeExpr: "int(10)",
-			expected: &schema.IntegerType{T: tInt},
+			expected: &schema.IntegerType{T: TypeInt},
 		},
 		{
 			typeExpr: "tinyint(10)",
-			expected: &schema.IntegerType{T: tTinyInt},
+			expected: &schema.IntegerType{T: TypeTinyInt},
 		},
 		{
 			typeExpr: "smallint(10)",
-			expected: &schema.IntegerType{T: tSmallInt},
+			expected: &schema.IntegerType{T: TypeSmallInt},
 		},
 		{
 			typeExpr: "mediumint(10)",
-			expected: &schema.IntegerType{T: tMediumInt},
+			expected: &schema.IntegerType{T: TypeMediumInt},
 		},
 		{
 			typeExpr: "bigint(10)",
-			expected: &schema.IntegerType{T: tBigInt},
+			expected: &schema.IntegerType{T: TypeBigInt},
 		},
 		{
 			typeExpr: "decimal",
-			expected: &schema.DecimalType{T: tDecimal},
+			expected: &schema.DecimalType{T: TypeDecimal},
 		},
 		{
 			typeExpr: "numeric",
-			expected: &schema.DecimalType{T: tNumeric},
+			expected: &schema.DecimalType{T: TypeNumeric},
 		},
 		{
 			typeExpr: "float(10,0)",
-			expected: &schema.FloatType{T: tFloat, Precision: 10},
+			expected: &schema.FloatType{T: TypeFloat, Precision: 10},
 		},
 		{
 			typeExpr: "double(10,0)",
-			expected: &schema.FloatType{T: tDouble, Precision: 10},
+			expected: &schema.FloatType{T: TypeDouble, Precision: 10},
 		},
 		{
 			typeExpr: "real",
-			expected: &schema.FloatType{T: tReal},
+			expected: &schema.FloatType{T: TypeReal},
 		},
 		{
 			typeExpr: "timestamp",
-			expected: &schema.TimeType{T: tTimestamp},
+			expected: &schema.TimeType{T: TypeTimestamp},
 		},
 		{
 			typeExpr: "date",
-			expected: &schema.TimeType{T: tDate},
+			expected: &schema.TimeType{T: TypeDate},
 		},
 		{
 			typeExpr: "time",
-			expected: &schema.TimeType{T: tTime},
+			expected: &schema.TimeType{T: TypeTime},
 		},
 		{
 			typeExpr: "datetime",
-			expected: &schema.TimeType{T: tDateTime},
+			expected: &schema.TimeType{T: TypeDateTime},
 		},
 		{
 			typeExpr: "year",
-			expected: &schema.TimeType{T: tYear},
+			expected: &schema.TimeType{T: TypeYear},
 		},
 		{
 			typeExpr: "varchar(10)",
-			expected: &schema.StringType{T: tVarchar, Size: 10},
+			expected: &schema.StringType{T: TypeVarchar, Size: 10},
 		},
 		{
 			typeExpr: "char(25)",
-			expected: &schema.StringType{T: tChar, Size: 25},
+			expected: &schema.StringType{T: TypeChar, Size: 25},
 		},
 		{
 			typeExpr: "varbinary(30)",
-			expected: &schema.BinaryType{T: tVarBinary, Size: 30},
+			expected: &schema.BinaryType{T: TypeVarBinary, Size: 30},
 		},
 		{
 			typeExpr: "binary(5)",
-			expected: &schema.BinaryType{T: tBinary, Size: 5},
+			expected: &schema.BinaryType{T: TypeBinary, Size: 5},
 		},
 		{
 			typeExpr: "blob(5)",
-			expected: &schema.StringType{T: tBlob},
+			expected: &schema.StringType{T: TypeBlob},
 		},
 		{
 			typeExpr: "tinyblob",
-			expected: &schema.StringType{T: tTinyBlob},
+			expected: &schema.StringType{T: TypeTinyBlob},
 		},
 		{
 			typeExpr: "mediumblob",
-			expected: &schema.StringType{T: tMediumBlob},
+			expected: &schema.StringType{T: TypeMediumBlob},
 		},
 		{
 			typeExpr: "longblob",
-			expected: &schema.StringType{T: tLongBlob},
+			expected: &schema.StringType{T: TypeLongBlob},
 		},
 		{
 			typeExpr: "text(13)",
-			expected: &schema.StringType{T: tText},
+			expected: &schema.StringType{T: TypeText},
 		},
 		{
 			typeExpr: "tinytext",
-			expected: &schema.StringType{T: tTinyText},
+			expected: &schema.StringType{T: TypeTinyText},
 		},
 		{
 			typeExpr: "mediumtext",
-			expected: &schema.StringType{T: tMediumText},
+			expected: &schema.StringType{T: TypeMediumText},
 		},
 		{
 			typeExpr: "longtext",
-			expected: &schema.StringType{T: tLongText},
+			expected: &schema.StringType{T: TypeLongText},
 		},
 		{
 			typeExpr: `enum("a","b")`,
@@ -485,35 +485,35 @@ func TestTypes(t *testing.T) {
 		},
 		{
 			typeExpr: "geometry",
-			expected: &schema.SpatialType{T: tGeometry},
+			expected: &schema.SpatialType{T: TypeGeometry},
 		},
 		{
 			typeExpr: "point",
-			expected: &schema.SpatialType{T: tPoint},
+			expected: &schema.SpatialType{T: TypePoint},
 		},
 		{
 			typeExpr: "multipoint",
-			expected: &schema.SpatialType{T: tMultiPoint},
+			expected: &schema.SpatialType{T: TypeMultiPoint},
 		},
 		{
 			typeExpr: "linestring",
-			expected: &schema.SpatialType{T: tLineString},
+			expected: &schema.SpatialType{T: TypeLineString},
 		},
 		{
 			typeExpr: "multilinestring",
-			expected: &schema.SpatialType{T: tMultiLineString},
+			expected: &schema.SpatialType{T: TypeMultiLineString},
 		},
 		{
 			typeExpr: "polygon",
-			expected: &schema.SpatialType{T: tPolygon},
+			expected: &schema.SpatialType{T: TypePolygon},
 		},
 		{
 			typeExpr: "multipolygon",
-			expected: &schema.SpatialType{T: tMultiPolygon},
+			expected: &schema.SpatialType{T: TypeMultiPolygon},
 		},
 		{
 			typeExpr: "geometrycollection",
-			expected: &schema.SpatialType{T: tGeometryCollection},
+			expected: &schema.SpatialType{T: TypeGeometryCollection},
 		},
 	}
 	for _, tt := range tests {