Commit 2a85c79c authored by astaxie's avatar astaxie

Merge pull request #881 from astaxie/revert-870-add-column-default-attribute

Revert "Add column default attribute"
parents c6cb1f92 767083bd
...@@ -104,11 +104,7 @@ func getColumnAddQuery(al *alias, fi *fieldInfo) string { ...@@ -104,11 +104,7 @@ func getColumnAddQuery(al *alias, fi *fieldInfo) string {
typ += " " + "NOT NULL" typ += " " + "NOT NULL"
} }
return fmt.Sprintf("ALTER TABLE %s%s%s ADD COLUMN %s%s%s %s %s", return fmt.Sprintf("ALTER TABLE %s%s%s ADD COLUMN %s%s%s %s", Q, fi.mi.table, Q, Q, fi.column, Q, typ)
Q, fi.mi.table, Q,
Q, fi.column, Q,
typ, getColumnDefault(fi),
)
} }
// create database creation string. // create database creation string.
...@@ -159,9 +155,6 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex ...@@ -159,9 +155,6 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
//if fi.initial.String() != "" { //if fi.initial.String() != "" {
// column += " DEFAULT " + fi.initial.String() // column += " DEFAULT " + fi.initial.String()
//} //}
// Append attribute DEFAULT
column += getColumnDefault(fi)
if fi.unique { if fi.unique {
column += " " + "UNIQUE" column += " " + "UNIQUE"
...@@ -246,42 +239,3 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex ...@@ -246,42 +239,3 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
return 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
}
...@@ -116,7 +116,6 @@ type fieldInfo struct { ...@@ -116,7 +116,6 @@ type fieldInfo struct {
null bool null bool
index bool index bool
unique bool unique bool
colDefault bool
initial StrTo initial StrTo
size int size int
auto_now bool auto_now bool
...@@ -281,11 +280,6 @@ checkType: ...@@ -281,11 +280,6 @@ checkType:
fi.pk = attrs["pk"] fi.pk = attrs["pk"]
fi.unique = attrs["unique"] 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 { switch fieldType {
case RelManyToMany, RelReverseMany, RelReverseOne: case RelManyToMany, RelReverseMany, RelReverseOne:
fi.null = false fi.null = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment