-
Couldn't load subscription status.
- Fork 39
Description
As the title says, when ranging .Schema.Enums in a [SchemaPaths] template, each enum is repeated once for each associated value, when it should just range once for each enum type. You can see this also in the verbose output when running gnorm:
found 3 values for enum public.project_type
found 3 values for enum public.project_type
found 3 values for enum public.project_type
found 2 values for enum public.stage_type
found 2 values for enum public.stage_type
This may be PostgreSQL only, as I think the culprit is the following query:
gnorm/database/drivers/postgres/parse.go
Lines 599 to 605 in d696814
| SELECT n.nspname, t.typname as type | |
| FROM pg_type t | |
| LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace | |
| JOIN pg_enum e ON t.oid = e.enumtypid | |
| WHERE (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) | |
| AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid) | |
| AND n.nspname IN (%s)` |
I would have submitted a PR, but I'm not great at SQL and can't figure out how to adjust the query. The results could obviously be de-duplicated in code, but that seems like a second choice solution.
My hunch as to why this went unnoticed is that when the values generated are passed to [EnumPaths] templates, generally one file is created per enum and you wouldn't know if they were written multiple times.