Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add datetime precision for mysql #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion translators/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 4 additions & 0 deletions translators/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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", {})
}
Expand Down