Skip to content
Advertisement

How can I specify column name casing in TypeORM migrations

I’m using typeORM and I want to use migrations instead of syncing because I’m working in a team and it’s actually a lot of tedious work to get the db to a state in which the app actually functions.

The problem is that every column name I specify in the migration gets converted to lowercase which I’ve worked around by making all entity props snake_case (which is horrible btw). But foreign keys get converted to camelCase by (I think) postgres by default so I can’t relate anything to each other by foreign key in my migration. (because it needs to be camelCase but the query gets converted to lowercase)

Have i made clear what my problem is?

Is there a way to solve this, or is there a workaround?

Advertisement

Answer

In postgresql, column and table names are automatically converted to lowercase unless you include them in double quotes:

See https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html — “Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case.”

So you should write migrations as, for example,

and queries similarly.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement