diff --git a/postgres.go b/postgres.go index c0fdea0..7c59701 100644 --- a/postgres.go +++ b/postgres.go @@ -165,11 +165,11 @@ func (dialector Dialector) DataTypeOf(field *schema.Field) string { } else { switch { case size <= 16: - return "smallint" + return "int2" case size <= 32: - return "integer" + return "int4" default: - return "bigint" + return "int8" } } case schema.Float: @@ -186,7 +186,8 @@ func (dialector Dialector) DataTypeOf(field *schema.Field) string { } return "text" case schema.Time: - if field.Precision > 0 { + // in postgresql, Precision == 0, This means being accurate to the seconds. + if field.Precision >= 0 && field.Precision <= 6 { return fmt.Sprintf("timestamptz(%d)", field.Precision) } return "timestamptz" @@ -210,11 +211,11 @@ func (dialectopr Dialector) RollbackTo(tx *gorm.DB, name string) error { func getSerialDatabaseType(s string) (dbType string, ok bool) { switch s { case "smallserial": - return "smallint", true + return "int2", true case "serial": - return "integer", true + return "int4", true case "bigserial": - return "bigint", true + return "int8", true default: return "", false }