ent/field: add update_default option time field

Reviewed By: alexsn

Differential Revision: D17070907

fbshipit-source-id: 63c9ce75c58e524044c38f9461cb04e8e45c8017
This commit is contained in:
Ariel Mashraki
2019-08-27 06:53:44 -07:00
committed by Facebook Github Bot
parent bd07c86b60
commit 772b8a33f8
30 changed files with 376 additions and 100 deletions

View File

@@ -25,17 +25,18 @@ type Schema struct {
// Field represents an ent.Field that was loaded from a complied user package.
type Field struct {
Name string `json:"name,omitempty"`
Type field.Type `json:"type,omitempty"`
Tag string `json:"tag,omitempty"`
Size *int `json:"size,omitempty"`
Charset *string `json:"charset,omitempty"`
Unique bool `json:"unique,omitempty"`
Nillable bool `json:"nillable,omitempty"`
Optional bool `json:"optional,omitempty"`
Default bool `json:"default,omitempty"`
Immutable bool `json:"immutable,omitempty"`
Validators int `json:"validators,omitempty"`
Name string `json:"name,omitempty"`
Type field.Type `json:"type,omitempty"`
Tag string `json:"tag,omitempty"`
Size *int `json:"size,omitempty"`
Charset *string `json:"charset,omitempty"`
Unique bool `json:"unique,omitempty"`
Nillable bool `json:"nillable,omitempty"`
Optional bool `json:"optional,omitempty"`
Default bool `json:"default,omitempty"`
UpdateDefault bool `json:"update_default,omitempty"`
Immutable bool `json:"immutable,omitempty"`
Validators int `json:"validators,omitempty"`
}
// Edge represents an ent.Edge that was loaded from a complied user package.
@@ -85,15 +86,16 @@ func MarshalSchema(schema ent.Interface) (b []byte, err error) {
for _, f := range fields {
fd := f.Descriptor()
sf := &Field{
Name: fd.Name,
Type: fd.Type,
Tag: fd.Tag,
Unique: fd.Unique,
Default: fd.Default != nil,
Nillable: fd.Nillable,
Optional: fd.Optional,
Immutable: fd.Immutable,
Validators: len(fd.Validators),
Name: fd.Name,
Type: fd.Type,
Tag: fd.Tag,
Unique: fd.Unique,
Nillable: fd.Nillable,
Optional: fd.Optional,
Immutable: fd.Immutable,
Validators: len(fd.Validators),
Default: fd.Default != nil,
UpdateDefault: fd.UpdateDefault != nil,
}
if fd.Size != 0 {
sf.Size = &fd.Size