-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
I'm currently migrating a database from an existing structure where we have used a variation of Snowflake to generate the IDs for our resources. The natural way to store such a value in the database would be an uint64/BIGINT UNSIGNED NOT NULL, thus a numeric type for ent.
In spite of there not being a straight DefaultFunc method on the uint64Builder, by getting the Descriptor I managed to set a custom function which is ran when the resource is created:
fd := field.Uint64("id").Immutable().Positive()
fd.Descriptor().Default = func() uint64 {
// generate...
}However, once we try to run entc, the following error shows up:
2021/01/07 10:08:32 running ent codegen:unmarshal schema [... json data ...]: unexpected default value type for field: "id"
Tracing back the error, it is from this method:
Being a numeric type and having a default, the type conversion is attempted, but f.DefaultValue will actually be of type nil because only DefaultFunc is set.
Proposals to solve this:
- add a
DefaultFunccheck on thedefaults()method, thus skipping it when we have such a function - or, the former + add full support by also adding
DefaultFuncon all numeric type builders - although this entails expanding the API
I'd be happy to work on a PR for this - but wanted to check first what's the best path to follow here.