From 5ca94941212cd38d39921fd095bfb3b244adeb68 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 21 Jun 2019 05:10:28 -0700 Subject: [PATCH] enable sql dialect option on integration env (#1014) Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1014 Pull Request resolved: https://github.com/facebookincubator/ent/pull/6 Reviewed By: alexsn Differential Revision: D15928002 fbshipit-source-id: 4b5a639405f218f6b6cc90d152380d2fc9525a3f --- dialect/sql/driver.go | 11 ++++++++++- dialect/sql/schema/mysql.go | 2 +- dialect/sql/schema/schema.go | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dialect/sql/driver.go b/dialect/sql/driver.go index a7c44c242..e027df46a 100644 --- a/dialect/sql/driver.go +++ b/dialect/sql/driver.go @@ -5,6 +5,7 @@ import ( "database/sql" "database/sql/driver" "fmt" + "strings" "time" "fbc/ent/dialect" @@ -31,7 +32,15 @@ func OpenDB(driver string, db *sql.DB) *Driver { } // Dialect implements the dialect.Dialect method. -func (d Driver) Dialect() string { return d.dialect } +func (d Driver) Dialect() string { + // if the underlying driver is wrapped with opencensus driver. + for _, name := range []string{dialect.MySQL, dialect.SQLite} { + if strings.HasPrefix(d.dialect, name) { + return name + } + } + return d.dialect +} // Tx starts and returns a transaction. func (d *Driver) Tx(ctx context.Context) (dialect.Tx, error) { diff --git a/dialect/sql/schema/mysql.go b/dialect/sql/schema/mysql.go index fbebba269..3021fbf8b 100644 --- a/dialect/sql/schema/mysql.go +++ b/dialect/sql/schema/mysql.go @@ -170,7 +170,7 @@ func changeSet(curr, new *Table) (*Table, error) { case !ok: changes.Columns = append(changes.Columns, c1) case c1.Type != c2.Type: - return nil, fmt.Errorf("changing column type for %q is invalid", c1.Name) + return nil, fmt.Errorf("changing column type for %q is invalid (%s != %s)", c1.Name, c1.Type, c2.Type) case c1.Unique != c2.Unique: return nil, fmt.Errorf("changing column cardinality for %q is invalid", c1.Name) } diff --git a/dialect/sql/schema/schema.go b/dialect/sql/schema/schema.go index fbef56f37..f367ae810 100644 --- a/dialect/sql/schema/schema.go +++ b/dialect/sql/schema/schema.go @@ -226,6 +226,8 @@ func (c *Column) ScanMySQL(rows *sql.Rows) error { }); parts[0] { case "int": c.Type = field.TypeInt + case "double": + c.Type = field.TypeFloat64 case "timestamp": c.Type = field.TypeTime case "tinyint":