diff --git a/translators/mysql.go b/translators/mysql.go index b5abfb01..cc461a27 100644 --- a/translators/mysql.go +++ b/translators/mysql.go @@ -241,7 +241,11 @@ func (p *MySQL) colType(c fizz.Column) string { case "uuid": return "char(36)" case "timestamp", "time", "datetime": - return "DATETIME" + if c.Options["size"] != nil { + return fmt.Sprintf("DATETIME(%d)", c.Options["size"]) + } else { + return "DATETIME" + } case "blob", "[]byte": return "BLOB" case "int", "integer": diff --git a/translators/mysql_test.go b/translators/mysql_test.go index 1afccec9..6e1f456e 100644 --- a/translators/mysql_test.go +++ b/translators/mysql_test.go @@ -55,6 +55,8 @@ PRIMARY KEY(` + "`id`" + `), ` + "`decimal`" + ` DECIMAL(6,2) NOT NULL, ` + "`numeric`" + ` NUMERIC(7,2) NOT NULL, ` + "`double`" + ` DOUBLE(8,2) NOT NULL, +` + "`datetime_size3`" + ` DATETIME(3) NOT NULL, +` + "`datetime_nosize`" + ` DATETIME NOT NULL, ` + "`integer`" + ` INTEGER NOT NULL, ` + "`bytes`" + ` BLOB NOT NULL, ` + "`created_at`" + ` DATETIME NOT NULL, @@ -77,6 +79,8 @@ PRIMARY KEY(` + "`id`" + `), t.Column("decimal", "decimal", {"precision": 6,"scale":2}) t.Column("numeric", "numeric", {"precision": 7,"scale":2}) t.Column("double", "double", {"precision": 8,"scale":2}) + t.Column("datetime_size3", "datetime", {"size": 3}) + t.Column("datetime_nosize", "datetime") t.Column("integer", "integer", {}) t.Column("bytes", "[]byte", {}) }