From 767083bd56d983cb38847916150449349bc5e9b6 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 24 Oct 2014 14:58:17 +0800 Subject: [PATCH] Revert "Add column default attribute" --- orm/cmd_utils.go | 48 +------------------------------------------- orm/models_info_f.go | 6 ------ 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/orm/cmd_utils.go b/orm/cmd_utils.go index cabd957c..8304da6b 100644 --- a/orm/cmd_utils.go +++ b/orm/cmd_utils.go @@ -104,11 +104,7 @@ func getColumnAddQuery(al *alias, fi *fieldInfo) string { typ += " " + "NOT NULL" } - return fmt.Sprintf("ALTER TABLE %s%s%s ADD COLUMN %s%s%s %s %s", - Q, fi.mi.table, Q, - Q, fi.column, Q, - typ, getColumnDefault(fi), - ) + return fmt.Sprintf("ALTER TABLE %s%s%s ADD COLUMN %s%s%s %s", Q, fi.mi.table, Q, Q, fi.column, Q, typ) } // create database creation string. @@ -159,9 +155,6 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex //if fi.initial.String() != "" { // column += " DEFAULT " + fi.initial.String() //} - - // Append attribute DEFAULT - column += getColumnDefault(fi) if fi.unique { column += " " + "UNIQUE" @@ -246,42 +239,3 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex return } - - -// Get string value for the attribute "DEFAULT" for the CREATE, ALTER commands -func getColumnDefault(fi *fieldInfo) string { - var ( - v, t, d string - ) - - t = " DEFAULT '%s' " - - // These defaults will be useful if there no config value orm:"default" and NOT NULL is on - switch fi.fieldType { - case TypeDateField: - d = "0000-00-00" - - case TypeDateTimeField: - d = "0000-00-00 00:00:00" - - case TypeBooleanField, TypeBitField, TypeSmallIntegerField, TypeIntegerField, - TypeBigIntegerField, TypePositiveBitField, TypePositiveSmallIntegerField, - TypePositiveIntegerField, TypePositiveBigIntegerField, TypeFloatField, - TypeDecimalField: - d = "0" - } - - if fi.colDefault { - if !fi.initial.Exist() { - v = fmt.Sprintf(t, "") - } else { - v = fmt.Sprintf(t, fi.initial.String()) - } - } else { - if !fi.null { - v = fmt.Sprintf(t, d) - } - } - - return v -} diff --git a/orm/models_info_f.go b/orm/models_info_f.go index 84a0c024..a79ffab2 100644 --- a/orm/models_info_f.go +++ b/orm/models_info_f.go @@ -116,7 +116,6 @@ type fieldInfo struct { null bool index bool unique bool - colDefault bool initial StrTo size int auto_now bool @@ -281,11 +280,6 @@ checkType: fi.pk = attrs["pk"] fi.unique = attrs["unique"] - // Mark object property if there is attribute "default" in the orm configuration - if _, ok := tags["default"]; ok { - fi.colDefault = true - } - switch fieldType { case RelManyToMany, RelReverseMany, RelReverseOne: fi.null = false