Open MorpheusXAUT opened 4 years ago
{
"name": "scopes",
"type": "types.StringArray",
"db_type": "ARRAYUSER-DEFINED",
"default": "'{app}'::user_scope[]",
"nullable": false,
"unique": false,
"validated": false,
"arr_type": "USER-DEFINED",
"udt_name": "_user_scope",
"domain_name": null,
"full_db_type": "_user_scope",
"auto_generated": false
},
{
"name": "scope",
"type": "string",
"db_type": "enum.user_scope('app','cms')",
"default": "'app'::user_scope",
"nullable": false,
"unique": false,
"validated": false,
"arr_type": null,
"udt_name": "user_scope",
"domain_name": null,
"full_db_type": "user_scope",
"auto_generated": false
},
This is the relevant section of the debug output.
The code that does this is here: https://github.com/volatiletech/sqlboiler/blob/master/templates/singleton/boil_types.go.tpl#L63 which refers to these functions: https://github.com/volatiletech/strmangle/blob/master/strmangle.go#L657-L702
You can see that the mysql/postgres driver is doing some crazy things to db_type
to make them work correctly. So it would seem to me we'd need to get the psql driver to be able to do something like: []enum.user_scope('app','cms')
if it were an array and have those corresponding functions be able to deal with that in some way or something.
I'd accept a PR for this type of thing. Won't put any time into it myself though. Thanks for bringing up the issue!
What version of SQLBoiler are you using (
sqlboiler --version
)?SQLBoiler v4.1.1
What is your database and version (eg. Postgresql 10)
PostgreSQL 12.2 (postgres:12.2-alpine Docker Image)
If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)
sqlboiler psql
If this happened at runtime what code produced the issue? (if not applicable leave blank)
What is the output of the command above with the
-d
flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)
Further information. What did you do, what did you expect?
Adding a column with an enum array type currently does not generate the respective constants for enum values in Go. Using the above schema, no values are added to
boil_types.go
- the enum is completely skipped and treated as string only.Using above enum directly as a column type (instead of an array) results in the proper constants being generated.
Example adapted
users
schema:After generation,
boil_types.go
contains:Updated output of
sqlboiler psql -d
:I would expect using an enum array also generates string constants for the referenced enum. Taking a quick peak at how Postgres handles and describes the type of an enum array, I'm not sure this is 100% feasible, but it would be nice to have to ensure proper values are added before DB interaction.