Skip to content

Commit

Permalink
Make timestamp to match MySQL's timestamp type.
Browse files Browse the repository at this point in the history
It's very confusing that timestamp is translated to datetime when MySQL
has a type called timestamp.

This change uses the right type for timestamps in MySQL.

Signed-off-by: David Calavera <david.calavera@gmail.com>
  • Loading branch information
calavera authored and markbates committed Nov 3, 2017
1 parent fa78227 commit abae1e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fizz/translators/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ func (p *MySQL) colType(c fizz.Column) string {
return fmt.Sprintf("VARCHAR (%s)", s)
case "uuid":
return "char(36)"
case "timestamp", "time", "datetime":
case "timestamp":
return "TIMESTAMP"
case "time", "datetime":
return "DATETIME"
default:
return c.ColType
Expand Down
4 changes: 4 additions & 0 deletions fizz/translators/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ permissions text,
age integer DEFAULT 40,
company_id char(36) NOT NULL DEFAULT 'test',
uuid char(36) NOT NULL,
deleted_at TIMESTAMP NOT NULL,
expired_at DATETIME NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY(uuid)
Expand All @@ -88,6 +90,8 @@ PRIMARY KEY(uuid)
t.Column("age", "integer", {"null": true, "default": 40})
t.Column("company_id", "uuid", {"default_raw": "'test'"})
t.Column("uuid", "uuid", {"primary": true})
t.Column("deleted_at", "timestamp")
t.Column("expired_at", "datetime")
})
`, myt)
r.Equal(ddl, res)
Expand Down

0 comments on commit abae1e9

Please sign in to comment.