feat: Postgres Native Enums
Resolves https://github.com/facebook/ent/issues/872
func (Person) Fields() []ent.Field {
return []ent.Field{
field.Int("id"),
field.Enum("mood").GoType(mood.Mood("mood")).SchemaType(map[string]string{dialect.Postgres: "mood"}),
}
}
Notes
- alter type is not used because it cannot run in a transaction and cannot remove types
- the current implementation will drop enum types that ent does not know about
- migration to and from enums are supported but this assumes that in the varchar -> enum case all the values are valid enum values
Not sure why generate is failing
Hey @cliedeman and thanks for adding this! It's really amazing.
I'll start giving it a look tomorrow, but I can say now, that I prefer to merge it in small chunks (split it into multiple PRs) - I can help you with that tomorrow.
BTW, it is ready for review, or you still work on it?
Hi @a8m It is ready for review. I only expect to add code. More unit tests and some validation of the enums (E.g. a user should not be allowed to specify the same enum on 2 different tables with differing values).
Happy to split it into chunks as you see fit
@a8m I have converted this pr to draft while I split this out into smaller pr's.
I should get to it in the next few days
Hi @cliedeman was there any update in the meantime on this topic?
Really need this feature, worked around it by writing custom migrations just for enums, but now Atlas complains with the below error ariga.io/atlas/sql/postgres.(*state).mayDropEnum because I guess it does not know how to drop the enum
Really need this feature, worked around it by writing custom migrations just for enums, but now Atlas complains with the below error
ariga.io/atlas/sql/postgres.(*state).mayDropEnumbecause I guess it does not know how to drop the enum
Try out https://github.com/mvrahden/go-enumer to generate enums. It has a compatibility option with ent