volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.69k stars 540 forks source link

Enum for a field in MYSQL with all CAPITALS before a slash messes up the code generation #1413

Open JC1738 opened 2 weeks ago

JC1738 commented 2 weeks ago

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.16.2

What is your database and version (eg. Postgresql 10)

MYSQL 8.0

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler mysql

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)

CREATE TABLE example_table ( id int NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, name_type enum('RANDOM','FOO/BAR') NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=71 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Further information. What did you do, what did you expect?

Because of the enum that has special character / when the code generates, it tries to make a variable name with FOO/BAR and that isn't a valid name for a variable.

I temporarily got around it by excluding that field in the sqlboiler.toml using blacklist = ["example_table.nametype"] but ideally I can get the field back by either having the code stop trying to use / in the name (replace with or just omit it)

MJacred commented 1 week ago

I can confirm using MariaDB (collation utf8mb4_uca1400_ai_ci).

But it works when using e.g. name_type enum('RANDOM','FOo/BAR') NOT NULL. It seems a capital letter before a slash messes up the code generation. I'll work out a fix in the upcoming days.

In the meantime, please update your issue title and description to clarify the actual issue

MJacred commented 1 week ago

Fixed the issue in volatiletech/strmangle#20. Though I have no idea when or if it will get merged and lands in official sqlboiler

Fyi: the issue was because ALL letters were uppercase. In that case, it cannot handle '/' or any other invalid character that's the same as its upper case version.