ent/entc: corrently reference default value on migrate generation

Summary:
Migration incorrectly generated field default value on storage key inclusion.

Example Field:
```
field.String("tenant").
  StorageKey("organization").
  Default("fb-test"),
```
Generated default of:
```
// DefaultTenant holds the default value on creation for the tenant field.
DefaultTenant = descTenant.Default.(string)
```
But migration references non existent default (storage key is used):
```
{Name: "organization", Type: field.TypeString, Default: user.DefaultOrganization},
```

Reviewed By: a8m

Differential Revision: D17578898

fbshipit-source-id: afca92ac3f34c16100c868a10d0a480139bf4262
This commit is contained in:
Alex Snast
2019-09-25 13:49:50 -07:00
committed by Facebook Github Bot
parent 6cf5b918c3
commit dacc568413
29 changed files with 129 additions and 46 deletions

View File

@@ -16,7 +16,7 @@ import (
// Card is the model entity for the Card schema.
type Card struct {
config
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Expired holds the value of the "expired" field.

View File

@@ -15,7 +15,7 @@ import (
// User is the model entity for the User schema.
type User struct {
config
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Age holds the value of the "age" field.

View File

@@ -37,12 +37,17 @@ func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
// SetAge sets the age field.
func (uu *UserUpdate) SetAge(i int) *UserUpdate {
uu.age = &i
uu.addage = nil
return uu
}
// AddAge adds i to age.
func (uu *UserUpdate) AddAge(i int) *UserUpdate {
uu.addage = &i
if uu.addage == nil {
uu.addage = &i
} else {
*uu.addage += i
}
return uu
}
@@ -204,12 +209,17 @@ type UserUpdateOne struct {
// SetAge sets the age field.
func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne {
uuo.age = &i
uuo.addage = nil
return uuo
}
// AddAge adds i to age.
func (uuo *UserUpdateOne) AddAge(i int) *UserUpdateOne {
uuo.addage = &i
if uuo.addage == nil {
uuo.addage = &i
} else {
*uuo.addage += i
}
return uuo
}