mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/entsql: add support for column default using annotation
Fixed #1033
This commit is contained in:
committed by
Ariel Mashraki
parent
3db3f5fd1a
commit
745afde770
@@ -980,9 +980,6 @@ func (f Field) IsInt() bool { return f.Type != nil && f.Type.Type == field.TypeI
|
||||
// IsEnum returns true if the field is an enum field.
|
||||
func (f Field) IsEnum() bool { return f.Type != nil && f.Type.Type == field.TypeEnum }
|
||||
|
||||
// IsAddable returns true if the field is an enum field.
|
||||
func (f Field) IsAddable() bool { return f.Type != nil && f.Type.Type == field.TypeEnum }
|
||||
|
||||
// IsEdgeField reports if the given field is an edge-field (i.e. a foreign-key)
|
||||
// that was referenced by one of the edges).
|
||||
func (f Field) IsEdgeField() bool { return f.fk != nil }
|
||||
@@ -1052,8 +1049,8 @@ func (f Field) NullTypeField(rec string) string {
|
||||
return expr
|
||||
}
|
||||
|
||||
// Column returns the table column. It sets it as a primary key (auto_increment) in case of ID field, unless stated
|
||||
// otherwise.
|
||||
// Column returns the table column. It sets it as a primary key (auto_increment)
|
||||
// in case of ID field, unless stated otherwise.
|
||||
func (f Field) Column() *schema.Column {
|
||||
c := &schema.Column{
|
||||
Name: f.StorageKey(),
|
||||
@@ -1071,6 +1068,11 @@ func (f Field) Column() *schema.Column {
|
||||
c.Default = strconv.Quote(s)
|
||||
}
|
||||
}
|
||||
// Override the default-value defined in the
|
||||
// schema if it was provided by an annotation.
|
||||
if ant := f.EntSQL(); ant != nil && ant.Default != "" {
|
||||
c.Default = strconv.Quote(ant.Default)
|
||||
}
|
||||
if f.def != nil {
|
||||
c.SchemaType = f.def.SchemaType
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user