Skip to content

Commit 266fab8

Browse files
committed
fix generating enum for db enums
1 parent 1b98158 commit 266fab8

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

internal/postgresql_type.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func postgresType(req *plugin.GenerateRequest, col *plugin.Column) string {
11-
columnType := sdk.DataType(col.Type)
11+
columnType := sdk.DataType(col.Type)
1212

1313
switch columnType {
1414
case "serial", "serial4", "pg_catalog.serial4", "bigserial", "serial8", "pg_catalog.serial8", "smallserial", "serial2", "pg_catalog.serial2", "integer", "int", "int4", "pg_catalog.int4", "bigint", "int8", "pg_catalog.int8", "smallint", "int2", "pg_catalog.int2":
@@ -42,21 +42,22 @@ func postgresType(req *plugin.GenerateRequest, col *plugin.Column) string {
4242
return "str"
4343
case "ltree", "lquery", "ltxtquery":
4444
return "str"
45-
default:
46-
for _, schema := range req.Catalog.Schemas {
47-
if schema.Name == "pg_catalog" || schema.Name == "information_schema" {
48-
continue
49-
}
50-
for _, enum := range schema.Enums {
51-
if columnType == enum.Name {
52-
if schema.Name == req.Catalog.DefaultSchema {
53-
return "models." + modelName(enum.Name, req.Settings)
54-
}
55-
return "models." + modelName(schema.Name+"_"+enum.Name, req.Settings)
56-
}
57-
}
58-
}
59-
log.Printf("unknown PostgreSQL type: %s\n", columnType)
60-
return "Any"
61-
}
45+
default:
46+
for _, schema := range req.Catalog.Schemas {
47+
if schema.Name == "pg_catalog" || schema.Name == "information_schema" {
48+
continue
49+
}
50+
for _, enum := range schema.Enums {
51+
// Match both unqualified and schema-qualified enum type names
52+
if columnType == enum.Name || columnType == schema.Name+"."+enum.Name {
53+
if schema.Name == req.Catalog.DefaultSchema {
54+
return "models." + modelName(enum.Name, req.Settings)
55+
}
56+
return "models." + modelName(schema.Name+"_"+enum.Name, req.Settings)
57+
}
58+
}
59+
}
60+
log.Printf("unknown PostgreSQL type: %s\n", columnType)
61+
return "Any"
62+
}
6263
}

0 commit comments

Comments
 (0)