mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
ent/migrate: properly scan text columns
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/34 Reviewed By: alexsn Differential Revision: D17390040 fbshipit-source-id: 92cb0e638f484877af185a88e41aa9c5eef6d22b
This commit is contained in:
committed by
Facebook Github Bot
parent
78a7509c52
commit
d99d9d282e
@@ -6,6 +6,7 @@ package schema
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -161,6 +162,7 @@ func TestMySQL_Create(t *testing.T) {
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Nullable: true},
|
||||
{Name: "text", Type: field.TypeString, Nullable: true, Size: math.MaxInt32},
|
||||
{Name: "age", Type: field.TypeInt},
|
||||
},
|
||||
PrimaryKey: []*Column{
|
||||
@@ -179,7 +181,8 @@ func TestMySQL_Create(t *testing.T) {
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "column_type", "is_nullable", "column_key", "column_default", "extra", "character_set_name", "collation_name"}).
|
||||
AddRow("id", "bigint(20)", "NO", "PRI", "NULL", "auto_increment", "", "").
|
||||
AddRow("name", "varchar(255)", "NO", "YES", "NULL", "", "", ""))
|
||||
AddRow("name", "varchar(255)", "NO", "YES", "NULL", "", "", "").
|
||||
AddRow("text", "longtext", "NO", "YES", "NULL", "", "", ""))
|
||||
mock.ExpectQuery(escape("SELECT `index_name`, `column_name`, `non_unique`, `seq_in_index` FROM INFORMATION_SCHEMA.STATISTICS WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "non_unique", "seq_in_index"}).
|
||||
|
||||
@@ -368,6 +368,9 @@ func (c *Column) ScanMySQL(rows *sql.Rows) error {
|
||||
return fmt.Errorf("converting varchar size to int: %v", err)
|
||||
}
|
||||
c.Size = size
|
||||
case "longtext":
|
||||
c.Size = math.MaxInt32
|
||||
c.Type = field.TypeString
|
||||
}
|
||||
if defaults.Valid && defaults.String != Null {
|
||||
return c.ScanDefault(defaults.String)
|
||||
|
||||
Reference in New Issue
Block a user