-
|
I have a MySQL table that has some columns with names like: `2g` tinyint(1) DEFAULT '0',
`3g` tinyint(1) DEFAULT '0',
`4g` tinyint(1) DEFAULT '0',And Lucid generates the schema like: @column()
declare 2G: boolean | null
@column()
declare 3G: boolean | null
@column()
declare 4G: boolean | nullWhich is invalid property name in javascript. Bad naming practices and table structure aside, is there any way I can configure a custom rule to rename this column so Lucid generates a valid schema? Even skipping auto generating this table would be fine. I do not "own" this table, so changing the column name is out of question, but I do need to generate a schema for the database where it is from. For now I'm having to resort to disabling schema generation for this connection. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
This is a known limitation of the schema generator — it does not handle column names that start with digits or contain characters invalid for JS identifiers. A few workarounds: 1. Use the After the schema is generated, manually fix the problematic columns: @column({ columnName: "2g" })
declare twoG: boolean | null
@column({ columnName: "3g" })
declare threeG: boolean | null
@column({ columnName: "4g" })
declare fourG: boolean | nullThe 2. Exclude the table from auto-generation and write the model manually: If you have many problematic columns, it might be easier to skip auto-generation for that table and write the model by hand. You can create the model file manually in 3. Post-process the generated schema: If you want to keep auto-generation for the other tables, you could write a small script that runs after generation and fixes the output — replacing This is definitely worth reporting as a bug/enhancement though — the generator should either escape these names automatically (e.g. prefix with underscore or use a naming convention like |
Beta Was this translation helpful? Give feedback.
-
|
I've opened an issue for this on Lucid's repo as it do seem like an unexpected behavior from the schema generator. The solution of prefixing the attributes with an underscore seems pretty simple and unoffensive, I might even try implementing that later this week. |
Beta Was this translation helpful? Give feedback.
A fix to this was merged into Lucid: e150d15
Property names will be prefixed with an underscore and we'll also be able to exclude tables from schema generation with custom rules.