mijia / modelq

ModelQ is a code generator for creating Golang codes/models to access RDBMS database/tables
MIT License
293 stars 40 forks source link

time fields with default value CURRENT_TIMESTAMP(X) in sql are still written to with dont-touch-timestamp=True flag #27

Open chushik opened 8 years ago

chushik commented 8 years ago

codegen.go only checks for strings.ToUpper(f.DefaultValue) == "CURRENT_TIMESTAMP" or strings.ToUpper(f.DefaultValue) == "NOW()" when deciding whether a time column has some default value. See https://github.com/mijia/modelq/blob/master/main.go#L28

However, MySql also allows default values like CURRENT_TIMESTAMP(X) and NOW(X) where X is a number. See http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html

I think code generator should check for matches against ^NOW(?:\\(\\d\\))?$" and "^CURRENT_TIMESTAMP(?:\\(\\d\\))?$"

mijia commented 8 years ago

En, yeah, that is not considered before. I will verify and fix this later. Or would you like to provide a PR, :P Thank you very much.

chushik commented 8 years ago

yup, I'll try to prepare a PR!