From dacc56841315d8668992b912bc30a57230a54bc1 Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Wed, 25 Sep 2019 13:49:50 -0700 Subject: [PATCH] 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 --- dialect/sql/schema/schema.go | 5 ----- entc/gen/internal/bindata.go | 4 ++-- entc/gen/template/migrate/schema.tmpl | 4 ++-- entc/gen/type.go | 4 +--- examples/edgeindex/ent/city.go | 2 +- examples/edgeindex/ent/street.go | 2 +- examples/m2m2types/ent/group.go | 2 +- examples/m2m2types/ent/user.go | 2 +- examples/m2m2types/ent/user_update.go | 14 ++++++++++++-- examples/m2mbidi/ent/user.go | 2 +- examples/m2mbidi/ent/user_update.go | 14 ++++++++++++-- examples/m2mrecur/ent/user.go | 2 +- examples/m2mrecur/ent/user_update.go | 14 ++++++++++++-- examples/o2m2types/ent/pet.go | 2 +- examples/o2m2types/ent/user.go | 2 +- examples/o2m2types/ent/user_update.go | 14 ++++++++++++-- examples/o2mrecur/ent/node.go | 2 +- examples/o2mrecur/ent/node_update.go | 14 ++++++++++++-- examples/o2o2types/ent/card.go | 2 +- examples/o2o2types/ent/user.go | 2 +- examples/o2o2types/ent/user_update.go | 14 ++++++++++++-- examples/o2obidi/ent/user.go | 2 +- examples/o2obidi/ent/user_update.go | 14 ++++++++++++-- examples/o2orecur/ent/node.go | 2 +- examples/o2orecur/ent/node_update.go | 14 ++++++++++++-- examples/traversal/ent/group.go | 2 +- examples/traversal/ent/pet.go | 2 +- examples/traversal/ent/user.go | 2 +- examples/traversal/ent/user_update.go | 14 ++++++++++++-- 29 files changed, 129 insertions(+), 46 deletions(-) diff --git a/dialect/sql/schema/schema.go b/dialect/sql/schema/schema.go index 3b99daa7a..8cb30e9f6 100644 --- a/dialect/sql/schema/schema.go +++ b/dialect/sql/schema/schema.go @@ -449,11 +449,6 @@ func (c *Column) ScanDefault(value string) (err error) { return nil } -// HasDefault reports if the column has a default value. -func (c *Column) HasDefault() bool { - return c.Default != nil -} - // defaultValue adds tge `DEFAULT` attribute the the column. // Note that, in SQLite if a NOT NULL constraint is specified, // then the column must have a default value which not NULL. diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index 4bddafc83..c19b39876 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -857,7 +857,7 @@ func templateMigrateMigrateTmpl() (*asset, error) { return a, nil } -var _templateMigrateSchemaTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x57\x4b\x6f\xdc\x36\x10\x3e\x4b\xbf\x62\x20\x6c\x8b\xc4\xd8\xa5\x12\xdf\xba\xc0\x1e\x02\x27\x41\x8d\x14\x6e\x50\x3b\xa7\x20\x28\x68\x6a\xb4\x22\x56\x22\x65\x8a\x72\xbd\x55\xf5\xdf\x0b\x3e\x24\x71\x5f\xf6\xa6\x8d\x2f\x2b\x92\xf3\xe0\x7c\xf3\xcd\x0c\xdd\x75\xe9\x45\x7c\x25\xeb\xad\xe2\xeb\x42\xc3\xe5\x9b\xb7\xbf\x2c\x6a\x85\x0d\x0a\x0d\x1f\x29\xc3\x7b\x29\x37\x70\x2d\x18\x81\x77\x65\x09\x56\xa8\x01\x73\xae\x1e\x31\x23\xf1\x5d\xc1\x1b\x68\x64\xab\x18\x02\x93\x19\x02\x6f\xa0\xe4\x0c\x45\x83\x19\xb4\x22\x43\x05\xba\x40\x78\x57\x53\x56\x20\x5c\x92\x37\xc3\x29\xe4\xb2\x15\x59\xcc\x85\x3d\xff\xed\xfa\xea\xc3\xcd\xed\x07\xc8\x79\x89\xe0\xf7\x94\x94\x1a\x32\xae\x90\x69\xa9\xb6\x20\x73\xd0\x81\x33\xad\x10\x49\x7c\x91\xf6\x7d\x1c\x77\x1d\x64\x98\x73\x81\x90\x34\xac\xc0\x8a\x26\xe0\xb6\x17\xf0\x17\xd7\x05\xe0\x93\x46\x91\xc1\x0c\x92\xcf\x94\x6d\xe8\x1a\x13\x48\x2a\xbe\x56\x54\x63\x02\x8b\xbe\x8f\xa3\xae\x03\x8d\x55\x5d\x52\x8d\x90\x14\x48\x33\x54\x09\x10\x63\xa5\xeb\xc0\xe8\x1a\x7b\xbc\xaa\xa5\xd2\xf0\xca\x8a\x2b\x2a\xd6\x08\xb3\x3f\xe7\x30\x13\xb0\x5c\xc1\x8c\xdc\xc8\x0c\x1b\x23\x18\x45\x49\xd7\xc1\x8c\x5c\x49\x91\xf3\x35\xf1\x3e\xa1\xef\x53\xb3\x2d\x82\x8d\xc4\x98\x5a\x8c\x0e\xa2\x64\xcd\x75\xd1\xde\x13\x26\xab\x34\xf7\xe0\x73\xc1\xda\x7b\xaa\xa5\x4a\x51\xe8\xd4\xc5\x97\xe6\x1c\xcb\x2c\x39\x47\x21\xe3\xb4\x44\xa6\xd3\xe6\xa1\xf4\xca\x49\xfc\x3a\x8e\x1f\xa9\x72\x81\x2c\xc2\x48\xb4\x8b\xe4\x8e\xde\x97\x43\x28\x46\x22\xbd\x80\x9c\x8b\x0c\xf4\xb6\x46\x10\x36\xcb\x2e\x45\x6b\x45\xeb\x62\xcc\x8c\x36\x6a\x73\xe0\x39\xe0\x13\x6f\x74\x03\x36\x3b\xce\xc4\xcc\xaa\x2d\x57\xc0\x45\x86\x4f\x23\x5a\x6f\x26\x27\xa7\x01\xed\x3a\x6b\xf3\x01\x66\x9a\xdc\xd0\x0a\x0d\x86\xf6\x8a\xee\xcc\x99\x5e\x19\x35\xbb\x76\x68\x4e\x79\xf3\x17\x60\xb2\x6c\x2b\xd1\x18\xd3\x35\x6d\x18\x2d\x47\x73\xff\x40\xad\xb8\xd0\x39\x24\x3f\x35\x57\x4e\x2a\x71\x8a\x69\x0a\xc6\xc1\xa0\xda\xf7\x50\xc8\x32\x6b\x6c\xec\xc3\x66\x2e\x1d\xc5\x6d\xce\xbd\xc5\xbe\x4f\x1c\x1a\xc4\x7a\xdf\xb1\xb0\x82\xaf\xdf\x2e\x5c\x26\x88\xf3\xd6\xc5\xd1\x01\x04\xcc\x42\xa0\xbd\x84\xcf\x45\x14\x75\x60\xec\x2f\x9d\x33\x36\x3a\x9b\xc3\xdd\xb6\xc6\x25\x58\x5a\x10\x77\x66\x76\x0c\x05\x1b\xed\xa5\xe6\xce\x42\xb7\x30\x68\xce\x18\xf9\x22\xf8\x43\x6b\x0e\xc0\x7d\x2d\x41\xab\x16\xe7\x21\x70\xa1\xf8\xb5\x60\x0a\x2b\xd3\x16\xfa\x1e\xc6\xc5\x0b\x4a\x37\x6d\x59\xfa\x4c\xc1\xf0\xbd\x04\x7f\xf9\xe9\xec\x88\xbe\x2d\xdc\x19\x23\xb7\xfc\x6f\xab\x6d\x7e\xad\x26\x79\x5e\xfe\x9d\xd6\xca\xc8\x9b\x5f\x87\x13\xb1\x08\x9d\xba\xe1\xaf\xb4\x79\x8f\x39\x6d\x4b\x1b\x97\xff\x74\x57\x34\xbc\x0a\x8a\x95\xf8\xc3\xae\x1b\x09\x34\x66\x60\x32\xef\x60\x0e\xaa\x3a\x8a\x46\x0a\x5a\x4a\xbc\x40\x40\x4b\xec\x5d\xfa\xe9\x01\xc1\x89\x7c\x8e\x3f\xc0\x45\x2e\x55\x45\x35\x97\xe2\x3c\x1e\x8e\xa6\x56\xf0\xb3\xe7\xa0\x75\x68\x29\x18\x50\x6b\xd2\xb7\xe1\x78\x16\x2e\xf7\xaa\xc1\x9e\x7d\x56\xbc\xa2\x6a\xfb\x09\xb7\xcb\xe3\xcc\xde\xa7\x76\xbd\xf1\xdc\x9e\x34\x87\xb4\x84\xa2\xfc\x74\x15\x8c\xf9\x33\x3d\xa1\xde\xf8\xa6\x30\x26\x63\xf7\x92\x5f\xcd\x92\x43\xdf\x7f\xdb\xe3\xc0\x6e\x92\xf6\x97\x2e\xb8\x8f\x52\x21\x5f\x8b\x4f\xb8\x6d\xc2\xe8\xa6\xed\xa3\x11\xe6\x43\x84\x81\xfa\xe4\xd5\x87\x70\xbb\xad\xee\x65\xe9\xf1\xce\x37\xc4\xad\x47\xc8\x43\xd4\x8f\xc3\x1a\x01\x1c\xb6\x8d\xb7\xd6\x73\xbe\x39\x84\xec\x10\xdc\xcb\x53\xe8\xee\x02\xcc\xde\x0e\x00\x5f\x7e\x2f\xc2\x87\x20\x1f\xdb\xe9\xe7\x63\x56\xd3\x0b\xa8\x65\xa3\x6b\x29\x10\x14\xe6\x0a\x05\xe3\x62\x0d\x5a\x02\x7d\x94\xdc\x4d\x20\x56\x20\xdb\x98\xdd\x52\xca\x7a\x1c\x32\xe6\xef\x0f\xcc\xff\x17\x66\x93\xfe\xcb\xb0\x39\x71\x5b\x3c\xff\x0d\xc0\xa1\x07\x84\x86\x9e\x1b\x47\x3f\x10\xe5\xa1\x5b\xe6\x1b\xf2\xbb\xf8\x52\x67\x54\xef\x4e\x8a\xc1\xc6\x70\xb8\xf4\xfd\x86\x0c\xed\x37\x3e\xe1\x63\xcf\xf4\x7b\x2c\xf1\xa4\x69\x77\x78\xae\xe9\x60\x7a\xed\xd7\xe8\xd0\xcb\x35\xb9\x36\x6f\x0b\x1c\xf3\xe0\x97\x21\x17\xec\x56\x77\xd0\x6b\x0c\x0d\x78\xf6\xe4\xeb\x61\xcf\xcc\x54\xb2\x61\x87\xe4\xd9\xd3\x6e\x8f\x34\x7f\xc3\x20\x1d\x04\xc6\x11\x3b\x4a\xbc\xc4\xcf\x23\x2f\x01\x47\x4f\x63\xee\x14\xcf\xce\x2d\xea\x1f\x57\xd5\x47\x08\x77\x64\x6b\x0c\x7b\xf8\xd8\x13\x39\x3e\x2b\xc3\x75\x9a\x82\x7f\x8c\xba\xd9\x47\xcb\xd2\x0e\x39\xed\x36\xfd\x33\xd4\x03\x19\x47\x5e\x36\x7c\x62\x8d\xe3\xed\xe5\xa7\x6e\x14\x54\xe5\x73\x93\x79\x1e\xef\x5e\xba\x37\x0f\xea\xbc\x15\x0c\xb8\xe0\xfa\xd5\x6b\xe8\xce\x7d\x58\x7f\xf7\x8b\x60\x2f\xdb\xcf\x0c\x9a\x70\xda\x87\xc7\x53\x5a\xc7\xb6\x03\x2b\x38\xb7\x1f\xed\xdf\x65\x80\x20\xf8\x76\xff\x8f\xb9\xc5\xbf\x01\x00\x00\xff\xff\x77\x03\x11\xd5\x5d\x0e\x00\x00") +var _templateMigrateSchemaTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x57\x4d\x6f\xdc\x36\x13\x3e\x4b\xbf\x62\x20\xec\xfb\x22\x31\x76\xa9\xc4\xb7\x2e\xb0\x07\xc3\x49\x00\x23\x85\x1b\xd4\xce\x29\x08\x0a\x9a\x1a\xad\x88\x95\x48\x99\xa2\x5c\x6f\x55\xfd\xf7\x82\x1f\x92\xb8\x5f\xf6\xa6\x8d\x2f\x2b\x0e\xe7\x83\xf3\xcc\x33\x1c\xba\xeb\xd2\x8b\xf8\x5a\xd6\x5b\xc5\xd7\x85\x86\xcb\x77\xef\x7f\x59\xd4\x0a\x1b\x14\x1a\x3e\x51\x86\x0f\x52\x6e\xe0\x46\x30\x02\x57\x65\x09\x56\xa9\x01\xb3\xaf\x9e\x30\x23\xf1\x7d\xc1\x1b\x68\x64\xab\x18\x02\x93\x19\x02\x6f\xa0\xe4\x0c\x45\x83\x19\xb4\x22\x43\x05\xba\x40\xb8\xaa\x29\x2b\x10\x2e\xc9\xbb\x61\x17\x72\xd9\x8a\x2c\xe6\xc2\xee\xff\x7a\x73\xfd\xf1\xf6\xee\x23\xe4\xbc\x44\xf0\x32\x25\xa5\x86\x8c\x2b\x64\x5a\xaa\x2d\xc8\x1c\x74\x10\x4c\x2b\x44\x12\x5f\xa4\x7d\x1f\xc7\x5d\x07\x19\xe6\x5c\x20\x24\x0d\x2b\xb0\xa2\x09\x38\xf1\x02\xfe\xe4\xba\x00\x7c\xd6\x28\x32\x98\x41\xf2\x85\xb2\x0d\x5d\x63\x02\x49\xc5\xd7\x8a\x6a\x4c\x60\xd1\xf7\x71\xd4\x75\xa0\xb1\xaa\x4b\xaa\x11\x92\x02\x69\x86\x2a\x01\x62\xbc\x74\x1d\x18\x5b\xe3\x8f\x57\xb5\x54\x1a\xde\x58\x75\x45\xc5\x1a\x61\xf6\xc7\x1c\x66\x02\x96\x2b\x98\x91\x5b\x99\x61\x63\x14\xa3\x28\xe9\x3a\x98\x91\x6b\x29\x72\xbe\x26\x3e\x26\xf4\x7d\x6a\xc4\x22\x10\x24\xc6\xd5\x62\x0c\x10\x25\x6b\xae\x8b\xf6\x81\x30\x59\xa5\xb9\x07\x9f\x0b\xd6\x3e\x50\x2d\x55\x8a\x42\xa7\x2e\xbf\x34\xe7\x58\x66\xc9\x39\x06\x19\xa7\x25\x32\x9d\x36\x8f\xa5\x37\x4e\xe2\xb7\x71\xfc\x44\x95\x4b\x64\x11\x66\xa2\x5d\x26\xf7\xf4\xa1\x1c\x52\x31\x1a\xe9\x05\xe4\x5c\x64\xa0\xb7\x35\x82\xb0\x55\x76\x25\x5a\x2b\x5a\x17\x63\x65\xb4\x31\x9b\x03\xcf\x01\x9f\x79\xa3\x1b\xb0\xd5\x71\x2e\x66\xd6\x6c\xb9\x02\x2e\x32\x7c\x1e\xd1\x7a\x37\x05\x39\x0d\x68\xd7\x59\x9f\x8f\x30\xd3\xe4\x96\x56\x68\x30\xb4\x47\x74\x7b\xce\xf5\xca\x98\xd9\xb5\x43\x73\xaa\x9b\x3f\x00\x93\x65\x5b\x89\xc6\xb8\xae\x69\xc3\x68\x39\xba\xfb\x1b\x6a\xc5\x85\xce\x21\xf9\x5f\x73\xed\xb4\x12\x67\x98\xa6\x60\x02\x0c\xa6\x7d\x0f\x85\x2c\xb3\xc6\xe6\x3e\x08\x73\xe9\x28\x6e\x6b\xee\x3d\xf6\x7d\xe2\xd0\x20\x36\xfa\x8e\x87\x15\x7c\xfb\x7e\xe1\x2a\x41\x5c\xb4\x2e\x8e\x0e\x20\x60\x16\x02\xed\x35\x7c\x2d\xa2\xa8\x03\xe3\x7f\xe9\x82\xb1\x31\xd8\x1c\xee\xb7\x35\x2e\xc1\xd2\x82\xb8\x3d\x23\x31\x14\x6c\xb4\xd7\x9a\x3b\x0f\xdd\xc2\xa0\x39\x63\xe4\xab\xe0\x8f\xad\xd9\x00\xf7\xb5\x04\xad\x5a\x9c\x87\xc0\x85\xea\x37\x82\x29\xac\xcc\xb5\xd0\xf7\x30\x2e\x5e\x31\xba\x6d\xcb\xd2\x57\x0a\x86\xef\x25\xf8\xc3\x4f\x7b\x47\xec\x6d\xe3\xce\x18\xb9\xe3\x7f\x59\x6b\xf3\x6b\x2d\xc9\xcb\xfa\x57\x5a\x2b\xa3\x6f\x7e\x1d\x4e\xc4\x22\x74\xda\xe2\x03\xe6\xb4\x2d\x6d\x5a\xfe\xd3\x9d\xd0\xd0\x2a\xe8\x55\x72\x10\xdb\x21\x1a\x34\x70\x14\x8d\x6c\xb3\xd5\x7f\x85\x6b\x96\xc3\xbb\x4c\xd3\x03\x58\x13\xcf\x1c\x55\x80\x8b\x5c\xaa\x8a\x6a\x2e\xc5\x79\x94\x1b\x5d\xad\xe0\xff\x9e\x6e\x36\xa0\x65\x5b\xc0\xa2\xc9\xde\xa6\xe3\x09\xb7\xdc\x23\xbe\xdd\xfb\xa2\x78\x45\xd5\xf6\x33\x6e\x97\xc7\x49\xbc\xcf\xe2\x7a\xe3\x69\x3c\x59\x0e\x15\x08\x55\xf9\x69\xc2\x8f\x64\x32\xed\x5f\x6f\x7c\xff\x8f\xcc\xdf\x3d\xe4\x37\xb3\xe4\xd0\xf7\xdf\xf7\xca\xbd\x5b\xa4\xfd\xa5\x4b\xee\x93\x54\xc8\xd7\xe2\x33\x6e\x9b\x30\xbb\x49\x7c\x34\xc3\x7c\xc8\x30\x30\x9f\xa2\xfa\x14\xee\xb6\xd5\x83\x2c\x3d\xde\xf9\x86\xb8\xf5\x08\x79\x88\xfa\x71\x58\x23\x80\xc3\x1b\xe2\xbd\x8d\x9c\x6f\x0e\x21\x3b\x04\xf7\xf2\x14\xba\xbb\x00\xb3\xf7\x03\xc0\x97\x3f\x8a\xf0\x21\xc8\xc7\x24\xfd\x7c\xac\x6a\x7a\x01\xb5\x6c\x74\x2d\x05\x82\xc2\x5c\xa1\x60\x5c\xac\x41\x4b\xa0\x4f\x92\xbb\x61\xc3\x0a\x64\x1b\x23\x2d\xa5\xac\xc7\x79\x62\xfe\x7e\xc7\xfc\x3f\x61\x36\xd9\xbf\x0e\x9b\x53\xb7\xcd\xf3\xef\x00\x1c\xee\x80\xd0\xd1\x4b\x93\xe7\x27\xa2\x3c\x5c\x73\xf9\x86\xfc\x26\xbe\xd6\x19\xd5\xbb\x43\x61\xf0\x31\x6c\x2e\xfd\x7d\x33\xde\x76\xf1\x89\x18\x7b\xae\x3f\x60\x89\x27\x5d\xbb\xcd\x73\x5d\x07\x83\x6a\xbf\x47\x87\xc1\xa2\xc9\x8d\x79\x46\xe0\x58\x07\xbf\x0c\xb9\x60\x45\xdd\xc1\x5d\x63\x68\xc0\xb3\x67\xdf\x0f\x7b\x6e\xa6\x96\x0d\x6f\x48\x9e\x3d\xef\xde\x91\xe6\x6f\x98\x99\x83\xc2\x38\x4d\x47\x8d\xd7\xf8\x79\x64\xe8\x3b\x7a\x1a\x77\xa7\x78\x76\x6e\x53\xff\xbc\xae\x3e\x42\xb8\x23\xa2\x31\xed\xe1\x63\x4f\xe5\xf8\xac\x0c\xd7\x69\x0a\xfe\xdd\xe9\x66\x1f\x2d\x4b\x3b\xe4\xb4\x13\xfa\x17\xa7\x07\x32\x8e\xbc\x6e\xf8\x9a\x1a\xc7\xdb\xeb\xaf\xda\x28\xe8\xca\x97\x26\xf3\x3c\xde\x3d\x74\x6f\xde\xce\x79\x2b\x18\x70\xc1\xf5\x9b\xb7\xd0\x9d\xfb\x86\xfe\xe1\x17\xc1\x5e\xb5\x5f\x18\x34\xe1\xb4\x0f\xb7\xa7\xb2\x8e\xd7\x0e\xac\xe0\xdc\xfb\x68\xff\x2c\x03\x04\xc1\xb7\xfb\xd7\xcb\x2f\xfe\x09\x00\x00\xff\xff\x89\x5f\xe9\xde\x49\x0e\x00\x00") func templateMigrateSchemaTmplBytes() ([]byte, error) { return bindataRead( @@ -872,7 +872,7 @@ func templateMigrateSchemaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/migrate/schema.tmpl", size: 3677, mode: os.FileMode(420), modTime: time.Unix(1568643141, 0)} + info := bindataFileInfo{name: "template/migrate/schema.tmpl", size: 3657, mode: os.FileMode(420), modTime: time.Unix(1569441129, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/migrate/schema.tmpl b/entc/gen/template/migrate/schema.tmpl index 6838013fc..d796713f4 100644 --- a/entc/gen/template/migrate/schema.tmpl +++ b/entc/gen/template/migrate/schema.tmpl @@ -34,7 +34,7 @@ var ( {{- if $c.Nullable }} Nullable: {{ $c.Nullable }},{{ end }} {{- with $c.Size }} Size: {{ . }},{{ end }} {{- with $c.Attr }} Attr: "{{ . }}",{{ end }} - {{- if $c.HasDefault }} Default: {{ $node.Package }}.Default{{ pascal $c.Name }},{{ end }}}, + {{- with $c.Default }} Default: {{ $node.Package }}.{{ . }},{{ end }}}, {{- end }} } {{- $table := pascal $t.Name | printf "%sTable" }} @@ -113,4 +113,4 @@ func init() { {{- end }} } -{{ end }} \ No newline at end of file +{{ end }} diff --git a/entc/gen/type.go b/entc/gen/type.go index 1af7f458a..f05164a8a 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -474,9 +474,7 @@ func (f Field) Column() *schema.Column { } } if f.Default && !f.IsTime() { - // since this column is used only for codegen, the actual default - // value is imported by the migrate package and used directly. - c.Default = true + c.Default = "Default" + pascal(f.Name) } return c } diff --git a/examples/edgeindex/ent/city.go b/examples/edgeindex/ent/city.go index 175482f30..fca629cc9 100644 --- a/examples/edgeindex/ent/city.go +++ b/examples/edgeindex/ent/city.go @@ -15,7 +15,7 @@ import ( // City is the model entity for the City schema. type City struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. diff --git a/examples/edgeindex/ent/street.go b/examples/edgeindex/ent/street.go index 990ac6810..326ebc589 100644 --- a/examples/edgeindex/ent/street.go +++ b/examples/edgeindex/ent/street.go @@ -15,7 +15,7 @@ import ( // Street is the model entity for the Street schema. type Street struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. diff --git a/examples/m2m2types/ent/group.go b/examples/m2m2types/ent/group.go index cac3d0224..94da730d4 100644 --- a/examples/m2m2types/ent/group.go +++ b/examples/m2m2types/ent/group.go @@ -15,7 +15,7 @@ import ( // Group is the model entity for the Group schema. type Group struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. diff --git a/examples/m2m2types/ent/user.go b/examples/m2m2types/ent/user.go index 22ae6c9cb..62303dde7 100644 --- a/examples/m2m2types/ent/user.go +++ b/examples/m2m2types/ent/user.go @@ -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. diff --git a/examples/m2m2types/ent/user_update.go b/examples/m2m2types/ent/user_update.go index 83fd86394..a626fd411 100644 --- a/examples/m2m2types/ent/user_update.go +++ b/examples/m2m2types/ent/user_update.go @@ -35,12 +35,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 } @@ -213,12 +218,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 } diff --git a/examples/m2mbidi/ent/user.go b/examples/m2mbidi/ent/user.go index 769ce2399..7dad700be 100644 --- a/examples/m2mbidi/ent/user.go +++ b/examples/m2mbidi/ent/user.go @@ -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. diff --git a/examples/m2mbidi/ent/user_update.go b/examples/m2mbidi/ent/user_update.go index b00c0e21d..4564bc72c 100644 --- a/examples/m2mbidi/ent/user_update.go +++ b/examples/m2mbidi/ent/user_update.go @@ -35,12 +35,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 } @@ -220,12 +225,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 } diff --git a/examples/m2mrecur/ent/user.go b/examples/m2mrecur/ent/user.go index 8e6964476..cdc0a95f8 100644 --- a/examples/m2mrecur/ent/user.go +++ b/examples/m2mrecur/ent/user.go @@ -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. diff --git a/examples/m2mrecur/ent/user_update.go b/examples/m2mrecur/ent/user_update.go index 7648aef7a..0618e46b5 100644 --- a/examples/m2mrecur/ent/user_update.go +++ b/examples/m2mrecur/ent/user_update.go @@ -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 } @@ -287,12 +292,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 } diff --git a/examples/o2m2types/ent/pet.go b/examples/o2m2types/ent/pet.go index d74663ab9..2f19ec867 100644 --- a/examples/o2m2types/ent/pet.go +++ b/examples/o2m2types/ent/pet.go @@ -15,7 +15,7 @@ import ( // Pet is the model entity for the Pet schema. type Pet struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. diff --git a/examples/o2m2types/ent/user.go b/examples/o2m2types/ent/user.go index 77fee1b9e..c8a696615 100644 --- a/examples/o2m2types/ent/user.go +++ b/examples/o2m2types/ent/user.go @@ -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. diff --git a/examples/o2m2types/ent/user_update.go b/examples/o2m2types/ent/user_update.go index 38abdab13..431dda79e 100644 --- a/examples/o2m2types/ent/user_update.go +++ b/examples/o2m2types/ent/user_update.go @@ -36,12 +36,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 } @@ -220,12 +225,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 } diff --git a/examples/o2mrecur/ent/node.go b/examples/o2mrecur/ent/node.go index 1b8ff2c5e..58d38ea72 100644 --- a/examples/o2mrecur/ent/node.go +++ b/examples/o2mrecur/ent/node.go @@ -15,7 +15,7 @@ import ( // Node is the model entity for the Node schema. type Node struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Value holds the value of the "value" field. diff --git a/examples/o2mrecur/ent/node_update.go b/examples/o2mrecur/ent/node_update.go index a46b1cc2c..6d7738fb0 100644 --- a/examples/o2mrecur/ent/node_update.go +++ b/examples/o2mrecur/ent/node_update.go @@ -37,12 +37,17 @@ func (nu *NodeUpdate) Where(ps ...predicate.Node) *NodeUpdate { // SetValue sets the value field. func (nu *NodeUpdate) SetValue(i int) *NodeUpdate { nu.value = &i + nu.addvalue = nil return nu } // AddValue adds i to value. func (nu *NodeUpdate) AddValue(i int) *NodeUpdate { - nu.addvalue = &i + if nu.addvalue == nil { + nu.addvalue = &i + } else { + *nu.addvalue += i + } return nu } @@ -264,12 +269,17 @@ type NodeUpdateOne struct { // SetValue sets the value field. func (nuo *NodeUpdateOne) SetValue(i int) *NodeUpdateOne { nuo.value = &i + nuo.addvalue = nil return nuo } // AddValue adds i to value. func (nuo *NodeUpdateOne) AddValue(i int) *NodeUpdateOne { - nuo.addvalue = &i + if nuo.addvalue == nil { + nuo.addvalue = &i + } else { + *nuo.addvalue += i + } return nuo } diff --git a/examples/o2o2types/ent/card.go b/examples/o2o2types/ent/card.go index 591f9e664..dd0aa4f6d 100644 --- a/examples/o2o2types/ent/card.go +++ b/examples/o2o2types/ent/card.go @@ -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. diff --git a/examples/o2o2types/ent/user.go b/examples/o2o2types/ent/user.go index 329879983..1f129453c 100644 --- a/examples/o2o2types/ent/user.go +++ b/examples/o2o2types/ent/user.go @@ -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. diff --git a/examples/o2o2types/ent/user_update.go b/examples/o2o2types/ent/user_update.go index 4270cf3db..305382b31 100644 --- a/examples/o2o2types/ent/user_update.go +++ b/examples/o2o2types/ent/user_update.go @@ -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 } diff --git a/examples/o2obidi/ent/user.go b/examples/o2obidi/ent/user.go index 2d95ffa4f..3a09cc286 100644 --- a/examples/o2obidi/ent/user.go +++ b/examples/o2obidi/ent/user.go @@ -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. diff --git a/examples/o2obidi/ent/user_update.go b/examples/o2obidi/ent/user_update.go index b8779939c..9c2e5024b 100644 --- a/examples/o2obidi/ent/user_update.go +++ b/examples/o2obidi/ent/user_update.go @@ -36,12 +36,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 } @@ -217,12 +222,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 } diff --git a/examples/o2orecur/ent/node.go b/examples/o2orecur/ent/node.go index e5b60cab9..d4ed77ce3 100644 --- a/examples/o2orecur/ent/node.go +++ b/examples/o2orecur/ent/node.go @@ -15,7 +15,7 @@ import ( // Node is the model entity for the Node schema. type Node struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Value holds the value of the "value" field. diff --git a/examples/o2orecur/ent/node_update.go b/examples/o2orecur/ent/node_update.go index fc2f6fd22..c16745343 100644 --- a/examples/o2orecur/ent/node_update.go +++ b/examples/o2orecur/ent/node_update.go @@ -37,12 +37,17 @@ func (nu *NodeUpdate) Where(ps ...predicate.Node) *NodeUpdate { // SetValue sets the value field. func (nu *NodeUpdate) SetValue(i int) *NodeUpdate { nu.value = &i + nu.addvalue = nil return nu } // AddValue adds i to value. func (nu *NodeUpdate) AddValue(i int) *NodeUpdate { - nu.addvalue = &i + if nu.addvalue == nil { + nu.addvalue = &i + } else { + *nu.addvalue += i + } return nu } @@ -255,12 +260,17 @@ type NodeUpdateOne struct { // SetValue sets the value field. func (nuo *NodeUpdateOne) SetValue(i int) *NodeUpdateOne { nuo.value = &i + nuo.addvalue = nil return nuo } // AddValue adds i to value. func (nuo *NodeUpdateOne) AddValue(i int) *NodeUpdateOne { - nuo.addvalue = &i + if nuo.addvalue == nil { + nuo.addvalue = &i + } else { + *nuo.addvalue += i + } return nuo } diff --git a/examples/traversal/ent/group.go b/examples/traversal/ent/group.go index f6394ba02..79f988c81 100644 --- a/examples/traversal/ent/group.go +++ b/examples/traversal/ent/group.go @@ -15,7 +15,7 @@ import ( // Group is the model entity for the Group schema. type Group struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. diff --git a/examples/traversal/ent/pet.go b/examples/traversal/ent/pet.go index a5527696d..0adaadf65 100644 --- a/examples/traversal/ent/pet.go +++ b/examples/traversal/ent/pet.go @@ -15,7 +15,7 @@ import ( // Pet is the model entity for the Pet schema. type Pet struct { - config + config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. diff --git a/examples/traversal/ent/user.go b/examples/traversal/ent/user.go index 3c9868b98..c4f9338d7 100644 --- a/examples/traversal/ent/user.go +++ b/examples/traversal/ent/user.go @@ -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. diff --git a/examples/traversal/ent/user_update.go b/examples/traversal/ent/user_update.go index 8bbe8ce1f..c98b54a75 100644 --- a/examples/traversal/ent/user_update.go +++ b/examples/traversal/ent/user_update.go @@ -43,12 +43,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 } @@ -456,12 +461,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 }